Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: fbo with depth attachment does not work

  1. #1
    Intern Newbie
    Join Date
    Jun 2004
    Posts
    34

    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:
    Code :
    // 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:
    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

    Do you have any ideas?

    Thanks in advance, Enrico

  2. #2
    Junior Member Newbie
    Join Date
    Oct 2005
    Location
    france
    Posts
    16

    Re: fbo with depth attachment does not work

    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.

  3. #3
    Intern Newbie
    Join Date
    Jun 2004
    Posts
    34

    Re: fbo with depth attachment does not work

    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.

  4. #4
    Junior Member Regular Contributor Zulfiqar Malik's Avatar
    Join Date
    Jun 2004
    Location
    London, UK
    Posts
    248

    Re: fbo with depth attachment does not work

    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.
    Zulfiqar Inayat Malik.
    Senior Developer, The Foundry.

  5. #5
    Junior Member Newbie
    Join Date
    Oct 2005
    Location
    france
    Posts
    16

    Re: fbo with depth attachment does not work

    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.

  6. #6
    Junior Member Regular Contributor
    Join Date
    Mar 2002
    Location
    NI, Germany
    Posts
    112

    Re: fbo with depth attachment does not work

    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.

  7. #7
    Intern Newbie
    Join Date
    Jun 2004
    Posts
    34

    Re: fbo with depth attachment does not work

    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?

  8. #8
    Junior Member Newbie
    Join Date
    Oct 2005
    Location
    france
    Posts
    16

    Re: fbo with depth attachment does not work

    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.

  9. #9
    Intern Newbie
    Join Date
    Jun 2004
    Posts
    34

    Re: fbo with depth attachment does not work

    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?

  10. #10
    Senior Member OpenGL Pro
    Join Date
    Jul 2001
    Location
    France
    Posts
    1,663

    Re: fbo with depth attachment does not work

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •