FBO and stencil

Hi all

I’ve rendered to texture the values of the stencil buffer. That’s my code:

glEnable(GL_TEXTURE_RECTANGLE_ARB);
glGenTextures(1, &depthStencilTexID);
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, depthStencilTexID);

glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_DEPTH24_STENCIL8_EXT, SCREEN_RES_X, SCREEN_RES_Y, 0, GL_RGBA, GL_INT, NULL);
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0);

glGenFramebuffersEXT(1, &fboID);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fboID);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_RECTANGLE_ARB, depthStencilTexID, 0);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL_TEXTURE_RECTANGLE_ARB, depthStencilTexID, 0);

Now I want to get the stencil value of the texture in a fragment shader. I think the stencil value should be the alpha channel but seems it doesn’t work.

What I’m doing wrong?

Thanks

You can’t both read and write to the same texture in the FBO.
Usually, when a texture is bound to the FBO it’s going to be written to - so there is no way to read its contents until you unbind the FBO.

Maybe I’ve explained in wrong way.

What I mean is,

glEnable(GL_TEXTURE_RECTANGLE_ARB);
glGenTextures(1, &depthStencilTexID);
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, depthStencilTexID);

glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_DEPTH24_STENCIL8_EXT, SCREEN_RES_X, SCREEN_RES_Y, 0, GL_RGBA, GL_INT, NULL);
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0);

glGenFramebuffersEXT(1, &fboID);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fboID);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_RECTANGLE_ARB, depthStencilTexID, 0);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL_TEXTURE_RECTANGLE_ARB, depthStencilTexID, 0);

--------- Render my scene -------------

unattachment of textures anf FBO.

Now I’ve the values of the stencil in depthStencilTexID I render a GL_QUADS of all my screen to activate all fragments. In my fragment I use the texture depthStencilTexID to get the values.

Tnaks anyway.