Jump to content

  • Log In with Google      Sign In   
  • Create Account

(Shadow Mapping) Rendering the Depth Buffer to a texture and Displaying it


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 BlueSpud   Members   -  Reputation: 422

Like
0Likes
Like

Posted 05 August 2013 - 08:47 AM

I have been trying to get shadow maps to work, but I can;t even get past the depth buffer part of it. I've been looking on the internet for hours now, yadayadayada. Here is my code so far -

 

Making the FBO and the texture for depth:

 GLuint framebuffer;
    GLuint depth;
    GLuint texture;

    glGenFramebuffers(1, &framebuffer);
    glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
    
    glGenTextures(1, &texture);
    glBindTexture(GL_TEXTURE_2D, texture);
    
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1280, 800, 0, GL_RGBA, GL_FLOAT, NULL);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    
    glBindTexture(GL_TEXTURE_2D, 0);

    
    glGenTextures(1, &depth);
    glBindTexture(GL_TEXTURE_2D, depth);
    
    glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 1280, 800, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
    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_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    
    glBindTexture(GL_TEXTURE_2D, 0);

    
    
    
    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depth, 0);
    //glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
    glDrawBuffer(GL_NONE);
    
    
    if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
        std::cout << "There was a problem with making the framebuffer\n";
    glBindFramebuffer(GL_FRAMEBUFFER, 0);
    
    return framebuffer;

Rendering the 'depth' to a quad for viewing:

glBindFramebuffer(GL_FRAMEBUFFER, FBO);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

 for (int i = 0; i < objects.size(); i++)
        {
            objects[i].renderObjectForDepth();
        }
glBindFrameBuffer(GL_TEXTURE_2D,0);
glBindTexture2D(GL_TEXTURE_2D, texture)
drawQuad();

And to me, everything looks fine, but It generates images like the picture attached. I've been ripping out my hair for days now, and any help would be appreciated.

 

 

 

Attached Thumbnails

  • Screen Shot 2013-08-05 at 10.34.25 AM.png


Sponsor:

#2 radioteeth   Prime Members   -  Reputation: 1052

Like
0Likes
Like

Posted 05 August 2013 - 09:37 AM

I think you're supposed to use renderbuffers along with framebuffers:

 

http://www.opengl.org/wiki/Framebuffer_Object_Examples



#3 BlueSpud   Members   -  Reputation: 422

Like
0Likes
Like

Posted 05 August 2013 - 09:50 AM

I think you're supposed to use renderbuffers along with framebuffers:

 

http://www.opengl.org/wiki/Framebuffer_Object_Examples

Using a texture is acceptable, I have it working now, I just needed to call

glDrawBuffer(GL_NONE);
    glReadBuffer(GL_NONE);

And bind my depth texture, not my blank, unused texture. A very simple fix.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS