How Can create a depth texture with FBO , please help me?

I want to create a depth texture ( copy the depth buffer to a texture).
I have already create a FBO and create four texture attach to GL_COLOR_ATTACHMENT0_EXT - GL_COLOR_ATTACHMENT3_EXT (use draw buffers). It works well.

Here comes the question.: Now I want to attach a texture to GL_DEPTH_ATTACHMENT_EXT . how should I call the glTexImage2D for the depth texture .
I do it like this :

glTexImage2D(GL_TEXTURE_2D, 0, 1, m_Width, m_Height, 0, GL_FLOAT, GL_LUMINANCE, NULL);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, m_depthTextureID, 0);

but it failed. when i check the FBO state returns error code GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT

internal format of depth texture is GL_DEPTH_COMPONENT_ARB, GL_DEPTH_COMPONENT16_ARB, GL_DEPTH_COMPONENT24_ARB or GL_DEPTH_COMPONENT32_ARB.

The best is 24 version because 8bit for stencil(still doesn’t working).
So call

glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, width, height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);

Another error you made, was that you call glTexImage2D with source format of GL_FLOAT and source type of GL_LUMINANCE :slight_smile:

Thank you Matt. I make it :slight_smile:
I think I should read the Red Book more carefully.
(I bought the Redbook 4th edition last day. and finish it 4 hours :frowning: )

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.