Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 9 of 9

Thread: Rendering to depth buffer with FBO

  1. #1
    Junior Member Newbie
    Join Date
    Apr 2004
    Location
    Sweden
    Posts
    6

    Rendering to depth buffer with FBO

    Hi all.

    Does anyone know about an example, preferably using glut that uses the FBO to render depth to a texture which is then rendered onto the framebuffer? (attached to a quad for example, just to see the content of the depth buffer).

    I can get the COLOR buffer result, but when I also attach a depth buffer, all I get in the render target (texture) for the GL_DEPTH_ATTACHMENT_EXT is black texture.

    I have tried with setting up the depth target texture as: GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_2D etc..
    but nothing works...
    Im using a Geforce 6200 FX go so it should support all of the required functionality.

    So, does anyone know of working code for this?

  2. #2
    Junior Member Regular Contributor
    Join Date
    Sep 2005
    Posts
    105

    Re: Rendering to depth buffer with FBO

    there are examples of this in the spec

  3. #3
    Junior Member Regular Contributor
    Join Date
    Dec 2000
    Location
    Florence, Italy
    Posts
    219

    Re: Rendering to depth buffer with FBO

    Did anyone get this to work ? I followed spec's example #7 and i also get a black texture.

  4. #4
    Senior Member OpenGL Guru zed's Avatar
    Join Date
    Jul 2000
    Location
    S41.16.25 E173.16.21
    Posts
    2,609

    Re: Rendering to depth buffer with FBO

    are your depthbuffer 24bit i know at least on gffx 16bit depth doesnt work with color attachment

  5. #5
    Senior Member OpenGL Pro
    Join Date
    Sep 2004
    Location
    Prombaatu
    Posts
    1,401

    Re: Rendering to depth buffer with FBO

    Don't forget to release the RTT texture bind and disable texturing for the target, before you draw your depth texture. I get some deep space blackness--sometimes even a crash--if I don't.

  6. #6
    Junior Member Regular Contributor
    Join Date
    Feb 2003
    Location
    Waltham, MA
    Posts
    126

    Re: Rendering to depth buffer with FBO

    Make sure that you have your depth texture color mode and your depth texture compare mode set correctly. I've been using 'render to depth texture' on NVidia for several months and it works great. Make sure you have your render states correct for your quad as well... perhaps try with a color texture filled to a specific to verify this?

    Kevin

  7. #7
    Junior Member Regular Contributor
    Join Date
    Mar 2006
    Posts
    161

    Re: Rendering to depth buffer with FBO

    hi all!

    im having exacly the same problem!

    here is a starter:

    // Init()

    GLuint m_DepthBufferId;
    GLuint m_FrameBufferId;

    glGenTextures((GLsizei) 1, &m_FrameBuffer->GetId());
    glBindTexture(GL_TEXTURE_2D, m_FrameBuffer->GetId());
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, m_Width, m_Height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);

    glGenTextures((GLsizei) 1, &m_DepthBuffer->GetId());
    glBindTexture(GL_TEXTURE_2D, m_DepthBuffer->GetId());
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
    glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_LUMINANCE);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, m_Width, m_Height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL);

    // Initialize Frame Buffer
    glGenFramebuffersEXT(1, &m_FrameBufferId);
    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_FrameBufferId);
    glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, m_FrameBuffer->GetId(), 0);
    CheckStatus();

    // Initialize Depth Buffer
    glGenRenderbuffersEXT(1, &m_DepthBufferId);
    glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, m_DepthBufferId);
    glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24, m_Width, m_Height);
    glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, m_DepthBuffer->GetId());
    CheckStatus();

    // Render()

    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_FrameBufferId);
    glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, m_DepthBufferId);
    //Bind textures and Render...
    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
    glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);


    can anyone help clear this?

  8. #8
    Junior Member Regular Contributor
    Join Date
    Mar 2006
    Posts
    161

    Re: Rendering to depth buffer with FBO

    Make sure that you have your depth texture color mode and your depth texture compare mode set correctly
    is this correct?

    glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, m_Width, m_Height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL);

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
    glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_INTENSITY);

  9. #9
    Junior Member Regular Contributor
    Join Date
    Feb 2003
    Location
    Waltham, MA
    Posts
    126

    Re: Rendering to depth buffer with FBO

    I'd suggest changing GL_COMPARE_R_TO_TEXTURE to GL_NONE. This will allow you to visualize the contents of your depth buffer. This should let you determine whether or not the contents of your depth texture make sense. If you actually get what looks like valid depths, then perhaps your texture coordinates are incorrect.

    Kevin B

Posting Permissions

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