Hello, I’m trying to setup a FBO with a texture2d color, depth and stencil attachments. This is the source code I use for FBO setup:
GLuint fb, rtt, depth_stencil_rb;
glGenFramebuffersEXT(1,&fb);
glGenTextures(1,&rtt);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,fb);
glBindTexture(GL_TEXTURE_2D,rtt);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA8,t->GetWidth(),t->GetHeight(),0,GL_RGBA,GL_UNSIGNED_BYTE,NULL);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,GL_COLOR_ATTACHMENT0_EXT,GL_TEXTURE_2D,rtt,0);
glGenRenderbuffersEXT(1,&depth_stencil_rb); glBindRenderbufferEXT(GL_RENDERBUFFER_EXT,depth_stencil_rb); glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT,0x84F9/*GL_DEPTH_STENCIL_EXT*/,t->GetWidth(),t->GetHeight());
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT,GL_DEPTH_ATTACHMENT_EXT,GL_RENDERBUFFER_EXT,depth_stencil_rb); glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT,GL_STENCIL_ATTACHMENT_EXT,GL_RENDERBUFFER_EXT,depth_stencil_rb);
glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT); glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);
This code seems to work because it passes the checkFBOStatus test. However, when I’m trying to use the stencil, it doesn’t seems to work properly.
I try to readback the contents in the depth_stencil buffer with:
glReadPixels(0,0,t->GetWidth(),t->GetHeight(),0x84F9/*GL_DEPTH_STENCIL_EXT*/,0x84FA/*GL_UNSIGNED_INT_24_8_EXT*/, pixels);
after setting the stencil value with:
glClearStencil(8);
glClear(GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT);
But it I allways get the same data in the pixels array: 0, don’t matter to what value I clean the depth_stencil buffer.
Is there any problem in my code? Any one of you have some source code of a depth_stencil FBO working? (or only a stencil FBO at least).
Thanks in advance.