Hello, I’m making a drawing board-like application and i need help in clearing something up… My current standing is that i have a frameBuffer with a rendertexture attached to it… I draw vertices to the render texture and i show that texture on a quad, this is how my drawing application is working. Now i want to implement a selection tool where i cut out a portion and move it and drop it where i want. I have done the cutting and storing pixels in a data structure… but i cant display it without ruining my current texture on the rendertexture.
So i think the solution is to get a secondary texture and overlap that on the first quad. I can move the stored pixels onto the second quad and move them as i like and when i’m done with it, i transfer the final pixels (at new locations) to the primary render texture. So the problem i’m getting is that i cant seem to get my second texture binded to the framebuffer. Here is the code for my primary texture
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &screenFrameBuffer);
glGenFramebuffers(1, &renderFrameBuffer);
glBindFramebuffer(GL_FRAMEBUFFER, renderFrameBuffer);
checkGLError("glBindFramebuffer");
// The texture we're going to render to
glGenTextures(1, &renderedTexture);
checkGLError("glGenTextures");
// Primary Texture
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, renderedTexture);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); //GL_LINEAR
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); //GL_NEAREST
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, _Width, _Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, primaryTextureDataStorage);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, renderedTexture, 0);
checkGLError("glFramebufferTexture2D");
Here is what i’m doing right after it for the secondary texture
// Secondary Texture
glActiveTexture(GL_TEXTURE1); // activating the 2nd texture
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); //GL_LINEAR
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); //GL_NEAREST
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, _Width, _Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, secondaryTextureDataStorage);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, renderedTexture, 0);
checkGLError("glFramebufferTexture2D Secondary");
From my understanding, we can bind multiple textures on the same framebuffer but at different color attachment slots. I even tried changing the texture buffer by generating, binding another texture buffer and attaching that to the color attachment 1… i dont know if i did that wrong or not, i changed back to using a single texture buffer because my current understanding says color attachments can work around that.
Here is the code i use to draw:
GLuint texPos = glGetAttribLocation(glProgram.textureProgram, "a_tex_texCoord");
GLuint vertPos = glGetAttribLocation(glProgram.textureProgram, "a_tex_position");
glVertexAttribPointer(vertPos, 2, GL_FLOAT, GL_FALSE, 2*sizeof(GLfloat), squareVertices);
glEnableVertexAttribArray(vertPos);
glVertexAttribPointer(texPos, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(GLfloat), textureVertices);
glEnableVertexAttribArray(texPos);
glDisable(GL_BLEND);
glActiveTexture(GL_TEXTURE0);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);;
checkGLError("glDrawArrays-PrimaryTexture");
// drawing secondary on top the primary
glEnable(GL_BLEND);
glActiveTexture(GL_TEXTURE1);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
checkGLError("glDrawArrays-SecondaryTexture");
glDisableVertexAttribArray(vertPos);
glDisableVertexAttribArray(texPos);
EDIT:I changed uniform location as well between the two glDrawArrays method… 0 when i need the primary and 1 when i need secondary