I set up my depth texture this way:
glGenTextures(1, &shadowMapTexture);
glBindTexture(GL_TEXTURE_2D, shadowMapTexture);
glTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT16, shadowMapSize, shadowMapSize, 0,
GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL);
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_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
Then when I've drawn the scene from the light's perspective I do this:
glBindTexture(GL_TEXTURE_2D, shadowMapTexture);
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, shadowMapSize, shadowMapSize);
Now this works but I want to use an FBO instead of glCopyTexSubImage2D. I set it up using this code(where shadowMapTexture is set up as before):
glGenFramebuffersEXT(1, &shadowBuffer);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, shadowBuffer);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, shadowMapTexture, 0);
glDrawBuffer(GL_FALSE);
glReadBuffer(GL_FALSE);
GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
if(status != GL_FRAMEBUFFER_COMPLETE_EXT) {
fprintf(stderr, "FBO setup failed\n");
exit(1);
}
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
I now draw the depth texture like this:
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, shadowBuffer);
// draw scene
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
But when I later try to use the shadowMapTexture it doesn't work. I guess I'm working under the assumption that at this point the contents of the shadowMapTexture will be the same as under the glCopyTexSubImage2D method. I use a simple technique where I draw the entire scene in shadow first and then draw normally everything that's not in shadow and now everything is drawn shadowed.
Edit: To clarify: There is nothing useful in the texture after doing the FBO method, while there is after the glCopyTexSubImage2D method.
[Edited by - robinei on October 13, 2007 1:31:11 PM]