Jump to content
  • Advertisement
Sign in to follow this  
dpadam450

Save, then render depth buffer

This topic is 4233 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am currently working on shadow mapping and I pretty much typed in all of what's on paulsprojects tutorial (if you know of it), and it didn't work so I'm going to the beginning. All I want to do is draw some stuff, save the depth components and then draw them onto a quad that covers the screen. Here is some code off the top of my head. GLuint depth; glGenTextures(1, &depth); glBindTexture(GL_TEXTURE_2D, depth); glCopyTexImage2D(.......GL_DEPTH_COMPONENT); glEnable(GL_TEXTURE_2D); glBegin(GL_QUADS); //code to draw the quad

Share this post


Link to post
Share on other sites
Advertisement
In short these should be the essential steps:

glGenTextures(1, &l_ShadowMap);
glBindTexture(GL_TEXTURE_2D, l_ShadowMap);
// Specify the format of the texture!
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, l_Width, l_Height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL);

// Render your scene here

glBindTexture(GL_TEXTURE_2D, l_ShadowMap);
// Copy the depth values
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, l_Width, l_Height);

// Now render a screenspace quad or so with ShadowMap applied as texture


There are several details that I have omitted here such as setting the viewport to the ShadowMap size, reversing winding to reduce cracks or disabling writing to the framebuffer when rendering to the depth map and setting up the texture environment.

Note that you will need at least OpenGL 1.5 to use GL_DEPTH_COMPONENT.

Share this post


Link to post
Share on other sites
glGenTextures(1, &depth);
glBindTexture(GL_TEXTURE_2D, depth);

glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 256, 256, 0, GL_DEPTH_COMPONENT,GL_UNSIGNED_BYTE, NULL);

glEnable(GL_DEPTH_TEST);

main loop....

glClearDepth(1.0);
//Draw a triangle here.


glBindTexture(GL_TEXTURE_2D, depth);
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 256, 256);


glEnable(GL_TEXTURE_2D);
//Draw quad

Here is what the program looks like.



I know what you mean about the shadow map, but I can't do that without actually getting a proper depth buffer saved into memory.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!