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 6 of 6

Thread: can't bind a texture depth buffer to a frame buffer

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2014
    Posts
    9

    Unhappy can't bind a texture depth buffer to a frame buffer

    i want to use frame buffer object, so i download a demo from network.
    it works well, but i want to change the depth buffer from render buffer to a texture, so i change the code, and then, glCheckFramebufferStatus return GL_FRAMEBUFFER_COMPLETE, but glGetRenderbufferParameteriv can't get valid width and height for this frame buffer object, they are all return 0.

    this is the demo project with visual studio 2010.

    rt1.zip
    Last edited by sczybt; 02-23-2014 at 06:40 AM.

  2. #2
    Junior Member Newbie
    Join Date
    Feb 2014
    Posts
    9
    glGenRenderbuffers(1, &g_fboDepthBuffer);
    glBindRenderbuffer(GL_RENDERBUFFER, g_fboDepthBuffer);
    glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, g_fboWidth, g_fboHeight);
    glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, g_fboDepthBuffer);

  3. #3
    Junior Member Newbie
    Join Date
    Feb 2014
    Posts
    9
    glEnable(GL_TEXTURE_2D);
    glGenTextures(1, &g_fboDepthBuffer);
    glBindTexture(GL_TEXTURE_2D, g_fboDepthBuffer);
    // glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
    // glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
    // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    // 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_MIN_FILTER, GL_LINEAR);
    // #define GL_CLAMP_TO_EDGE 0x812F
    // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

    #define GL_TEXTURE_DEPTH_SIZE 0x884A
    #define GL_DEPTH_TEXTURE_MODE 0x884B
    #define GL_TEXTURE_COMPARE_MODE 0x884C
    #define GL_TEXTURE_COMPARE_FUNC 0x884D
    #define GL_COMPARE_R_TO_TEXTURE 0x884E


    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_INTENSITY);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);

    #define GL_DEPTH_COMPONENT24 0x81A6

    // glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, m_SizeX, m_SizeY, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, g_fboWidth, g_fboHeight, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, 0);

    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, g_fboDepthBuffer, 0);

    glBindTexture(GL_TEXTURE_2D, 0);
    glDisable(GL_TEXTURE_2D);

  4. #4
    Junior Member Newbie
    Join Date
    Feb 2014
    Posts
    9
    this is the old code, it works well.

  5. #5
    Junior Member Newbie
    Join Date
    Feb 2014
    Posts
    9
    Quote Originally Posted by sczybt View Post
    glGenRenderbuffers(1, &g_fboDepthBuffer);
    glBindRenderbuffer(GL_RENDERBUFFER, g_fboDepthBuffer);
    glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, g_fboWidth, g_fboHeight);
    glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, g_fboDepthBuffer);
    this is the old code, it works well.

  6. #6
    Junior Member Newbie
    Join Date
    Feb 2014
    Posts
    9
    Quote Originally Posted by sczybt View Post
    glEnable(GL_TEXTURE_2D);
    glGenTextures(1, &g_fboDepthBuffer);
    glBindTexture(GL_TEXTURE_2D, g_fboDepthBuffer);
    // glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
    // glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
    // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    // 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_MIN_FILTER, GL_LINEAR);
    // #define GL_CLAMP_TO_EDGE 0x812F
    // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

    #define GL_TEXTURE_DEPTH_SIZE 0x884A
    #define GL_DEPTH_TEXTURE_MODE 0x884B
    #define GL_TEXTURE_COMPARE_MODE 0x884C
    #define GL_TEXTURE_COMPARE_FUNC 0x884D
    #define GL_COMPARE_R_TO_TEXTURE 0x884E


    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_INTENSITY);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);

    #define GL_DEPTH_COMPONENT24 0x81A6

    // glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, m_SizeX, m_SizeY, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, g_fboWidth, g_fboHeight, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, 0);

    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, g_fboDepthBuffer, 0);

    glBindTexture(GL_TEXTURE_2D, 0);
    glDisable(GL_TEXTURE_2D);

    this is the new code, it doesn't works.

Posting Permissions

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