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

  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.

Similar Threads

  1. What would I see if I bind the depth buffer texture on to a quad?
    By hashbrown in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 06-07-2017, 09:50 AM
  2. Replies: 0
    Last Post: 09-02-2016, 03:00 PM
  3. bind texture map to depth buffer with gles 2
    By imported_billconan in forum OpenGL: GLSL
    Replies: 1
    Last Post: 08-09-2010, 05:47 AM
  4. frame buffer objects and depth values
    By cyrfer in forum OpenGL: Basic Coding
    Replies: 11
    Last Post: 12-10-2006, 11:42 AM
  5. Depth-Buffer -> Frame Buffer
    By Falkenbach in forum OpenGL: Advanced Coding
    Replies: 4
    Last Post: 05-06-2004, 05:43 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean