View Full Version : problem with depth buffer while using the FBO

Ehsan Kamrani
12-29-2010, 01:53 PM
I don't know why depth test doesn't work correctly when I use a FBO to render to texture? Note that I have just attached a texture to the color buffer of FBO. I haven't attached anything to the depth buffer of FBO.

carsten neumann
12-29-2010, 02:12 PM
I haven't attached anything to the depth buffer of FBO.

and that is why the depth test does not work, it needs a depth buffer, i.e. you need to attach one to your FBO.

Ehsan Kamrani
12-30-2010, 12:28 AM
Thank you. I tried it, but I no longer see anything in my texture!
here's my code to initialize a texture, FBO and render buffer:

glGenerateMipmapEXT( GL_TEXTURE_2D );
glTexImage2D(GL_TEXTURE_2D, 0, channels, size, size, 0, type, GL_UNSIGNED_BYTE, NULL );
m_fboID[textureID] = g_render.GenerateFBO();
g_render.BindFBO( m_fboID[textureID] );
g_render.Attach2DTextureToFBOColor( m_waterTexture[textureID] );
CUInt renderBuffer = g_render.GenerateRenderBuffer();
g_render.BindRenderBuffer( renderBuffer );
g_render.RenderbufferStorage( 256, 256 );
g_render.AttachDepthToFBO( renderBuffer );

Without creating a render buffer and attaching it to the FBO, at least I get some images in my texture. but now the texture is black.
Note that the result of creating my FBO is GL_FRAMEBUFFER_COMPLETE_EXT.

Ehsan Kamrani
12-30-2010, 01:50 AM
I understood that the width and height of my render buffer are not equal with the with and height of my color texture. replacing this part of code:

g_render.RenderbufferStorage( 256, 256 );

with this one:

g_render.RenderbufferStorage( size, size );

solved my problem

Now the water texture looks nice:

http://upwqcw.blu.livefilestore.com/y1pN...er-1.jpg?psid=1 (http://upwqcw.blu.livefilestore.com/y1pNLVXckGSOWWvkOjWePHGKMc11XvJjG3pTKq4Wusdlu3Z1aq pGXzy6SnRIH0yAkqLPQoikkdKH2fwJ_3yVe7I-xtZlK8Ie8eb/water-1.jpg?psid=1)

Thank you carsten neumann :-)