I guess the problem is because I’m using the fbo2 with depth and stencil buffer, and as said, the texture attached to fbo2
is well generated, I get their data using glReadBuffer(…) and the data becomes valid, but when I try to use this texture to update the texture fbo1_tex[next](attached into fbo1) this seems to have zero values.
See the code below
I’m using this code to update the next fbo1 textures
// bind the fbo1
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo1);
// Save the view port and set it to the size of the texture
glPushAttrib(GL_CURRENT_BIT | GL_VIEWPORT_BIT | GL_TRANSFORM_BIT );
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluOrtho2D(0, fbo1_tex_w, 0, fbo1_tex_w);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glViewport(0, 0, fbo1_tex_w, 0, fbo1_tex_w);
glDrawBuffer(GL_COLOR_ATTACHMENT1_EXT);
glEnable(GL_TEXTURE_2D);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, fbo1_tex[curr_id]);
glActiveTexture(GL_TEXTURE1);
glBindTexture(TEX_TARGET, grid_tex);
fbo1_shader.use(true);
// activate the textures to be used
drawQuad(0.0, 0.0, fbo1_tex_w, 0, fbo1_tex_w);
and this code to generate the fbo2_tex (which uses depth buffer and stencil buffer)
// bind the fbo2
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo2);
// Save the view port and set it to the size of the texture
glPushAttrib( GL_CURRENT_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_TRANSFORM_BIT | GL_VIEWPORT_BIT);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0, fbo2_tex_w, 0, fbo2_tex_w, 200, -200);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glViewport(0, 0, fbo2_tex_w, fbo2_tex_w);
// draw into the associated texture
glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
/*glEnable(TEX_TARGET);
glActiveTexture(GL_TEXTURE0);*/
glBindTexture(TEX_TARGET, fbo1_tex[curr_id]);
fbo2_shader.use(true);
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
glColorMask(true, false, false, false);
glDepthFunc(GL_LESS);
drawVertices();
glEnable(GL_STENCIL_TEST);
glColorMask(false, true, false, false);
glClear(GL_STENCIL_BUFFER_BIT);
drawVertices();
glColorMask(false, false, true, false);
glClear(GL_STENCIL_BUFFER_BIT);
drawVertices();
glColorMask(true, true, true, true);
glDisable(GL_STENCIL_TEST);
glDisable(GL_DEPTH_TEST);
// Restore old view port
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glPopAttrib();
fbo_shader2.use(false);