Skip to main content
gamedev.net
🔒 Locked

Save, then render depth buffer

Started by dpadam450 1 reply 800+ views
Original Post
dpadam450
dpadam450
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
NBA2K, Madden, Maneater, Killing Floor, Sims 
Treesong
Treesong
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.
dpadam450
dpadam450
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.
NBA2K, Madden, Maneater, Killing Floor, Sims 

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.