fbo with depth attachment does not work

Hi,

I am trying to a fbo with only a depth buffer attachment to work. I read the spec and the document in the new ATI SDK, both have examples for it. This is what I have so far:

// generate fbo object
glGenFramebuffersEXT(1, &m_FBO);
CheckFrameBufferStatus(__LINE__);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_FBO);
CheckFrameBufferStatus(__LINE__);

// generate depth attachment
glGenTextures(1, &m_DepthAttachment);
glBindTexture(GL_TEXTURE_2D, m_DepthAttachment);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT16, width, height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL);

//glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP);
//glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP);

glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);

// attach depth texture
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, m_DepthAttachment, 0);
glDrawBuffer(GL_NONE);
glReadBuffer(GL_NONE);
CheckFrameBufferStatus(__LINE__);

glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);

This is the initalisation code. It gives me no errors. New the render code:

glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_FBO);
glClear(GL_DEPTH_BUFFER_BIT);
// Render some geometry here...
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);

Later on, I try to use m_DepthAttachment as GL_TEXTURE_2D object, but this doesnt work. The quad is always white :frowning:

Do you have any ideas?

Thanks in advance, Enrico

Hi,
if you want to use your depth texture to do depth comparison, you need to add:
glTexParameteri( GL_TEXTURE2D, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE_ARB );
glTexParameteri( GL_TEXTURE2D, GL_TEXTURE_COMPARE_FUNC_ARB, GL_LEQUAL );

It works form me, i’m doing shadow mapping with fbo btw.

Thanks for your reply.
I do not want to do shadow mapping (for now). I just want to display the texture and see the depth values. But the fbo texture is always white and my model is rendered.

Depth component textures are meaning less in terms of color. You can however write a fragment shader in which you lookup a value from a depth texture and use it as a color for fragments.

To see the depth values, i only apply the depth texture to a quad, but you need to have TEXTURE_COMPARE_MODE_ARB = NONE in this case.

Originally posted by lodder:
Thanks for your reply.
I do not want to do shadow mapping (for now). I just want to display the texture and see the depth values. But the fbo texture is always white and my model is rendered.

It may look like the texture is pure white, as the difference in color could be very small.

Originally posted by alkiem:
To see the depth values, i only apply the depth texture to a quad, but you need to have TEXTURE_COMPARE_MODE_ARB = NONE in this case.
Do you have something else activated? The shadow map test, for example? Or do you only have set this comparison after you created your depth texture?

Originally posted by Zulfiqar Malik:
Depth component textures are meaning less in terms of color. You can however write a fragment shader in which you lookup a value from a depth texture and use it as a color for fragments.
Ok, so I need shaders. I will try that…

@Jens: I render only a triangle, nothing else. There should be at least something visible, or?

Originally posted by lodder:
Do you have something else activated? The shadow map test, for example? Or do you only have set this comparison after you created your depth texture?

Nothing is activated, i just render the shadow map in the depth texture bound to the fbo. Everything about shadow map test is made in a fragment shader when rendering the scene from the camera point of view. When you want to see the depth texture, as i said before, if the depth texture was initialized with:
glTexParameteri( GL_TEXTURE2D, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE_ARB );
you just need to do:
glTexParameteri( GL_TEXTURE2D, GL_TEXTURE_COMPARE_MODE_ARB, GL_NONE );
But, GL_NONE is the default value of GL_TEXTURE_COMPARE_MODE_ARB, so in your case, it should work directly.

Do you try not to enable the fbo and rendering to frame buffer directly to see if there is sthg visible in the viewport? Your problem may not be with fbo, unless it is linked to driver/graphic card issue.

This comparison changes nothing for me. It is still the same. I render a quad two times:

  1. The usual frame buffer (works)
  2. Into the depth texture (does not work)
    I rendered into a color attachment and this works without any problems…

What to try now?

When I tried it, few months ago, I needed to have another buffer along with the depth buffer, like a logical color buffer.
Otherwise, I just had nothing just like you.
Make a research about your question, many keys were written.

Originally posted by jide:
When I tried it, few months ago, I needed to have another buffer along with the depth buffer, like a logical color buffer.
Otherwise, I just had nothing just like you.
Make a research about your question, many keys were written.

Did you render into a RenderBuffer or texture? Spec says explicit, I can render depth values into a texture… This is confusing…

I tried out both, but it was on nv cards.

Originally posted by lodder:
[QB@Jens: I render only a triangle, nothing else. There should be at least something visible, or?[/QB]
No. The difference between the color (or depth value) is probably too small to notice. I realized that, when filling a screenshot with a brush in a paint program with, for example, black.

Hi,

got it working now; even without shaders :slight_smile:
The problem: I used a NPOT color attachment and this works without problems on my X700Pro and Radeon9800Pro. I get a working NPOT depth attachment only, if I use GL_UNSIGNED_BYTE or GL_FLOAT as type parameter for glTexImage2D(). When I use GL_UNSIGNED_SHORT, the depth attachment does not work. But why wont I get a error message, when it doesnt work?? :mad:

Maybe I should report this to ATI…