Hi!
I've decided to render my shadow map with the help of a FBO instead of using the window. I think I have set up my framebuffer and depthbuffer right, but it doesn't want to work. My code looks like this:
Setup:____________________________________________________________________
// Create depth texture
glGenTextures(1, &textureArray[0]);
glBindTexture(GL_TEXTURE_2D, textureArray[0]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, 512, 512, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, 0);
// Filter and clamp
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
// Create frame buffer object and depth buffer
glGenFramebuffersEXT(1, &frameBuffer);
glGenRenderbuffersEXT(1, &depthRenderBuffer);
// initialize depth renderbuffer
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depthRenderBuffer);
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT,GL_DEPTH_COMPONENT24, depthWidth, depthHeight);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT,GL_DEPTH_ATTACHMENT_EXT,GL_RENDERBUFFER_EXT, depthRenderBuffer);
checkFBOStatus();
Rendering:________________________________________________________________
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, frameBuffer);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depthRenderBuffer);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, texture[0], 0);
/* Render stuff to texture */
...
/* Go back to window rendering */
glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, 0 );
glBindRenderbufferEXT( GL_RENDERBUFFER_EXT, 0 );
I can't figure out what's wrong, I've used the examples #3 & #7 at
oss.sgi.com. If I understand this the right way.. I shouldn't need to copy my frame to texture[0] with glCopyTexSubImage2D since im rendering directly to the fbo?
I think my depth buffer becomes empty because my scene gets shadowed all over.
Thanks in advance!
[Edited by - Herr_O on October 5, 2006 8:16:54 AM]