Hi guys, I'm having trouble implementing a basic shadow mapping algorithm. At the moment I am trying to render the depth buffer to a texture and then render it to see if it is correct. I have been following the guide from here: http://www.fabiensanglard.net/shadowmapping/index.php
When I render the depth texture to a quad I'm getting nothing. I have had render to texture working by rendering the colour buffer to texture and using the a renderbuffer for the depth. Here is the code I use to set up the texture and the FBO:-
void Scene::generateShadowFBO()
{
int shadowMapWidth = 512;
int shadowMapHeight = 512;
GLenum FBOstatus;
glActiveTexture(GL_TEXTURE0);
glGenTextures(1, &m_depthTexture);
glBindTexture(GL_TEXTURE_2D, m_depthTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_INTENSITY);
glTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, shadowMapWidth, shadowMapHeight, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, 0);
// create a framebuffer object
glGenFramebuffers(1, &m_shadowFBO);
glBindFramebuffer(GL_FRAMEBUFFER, m_shadowFBO);
// Instruct openGL that we won't bind a color texture with the currently binded FBO
glDrawBuffer(GL_NONE);
glReadBuffer(GL_NONE);
// attach the texture to FBO depth attachment point
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,GL_TEXTURE_2D, m_depthTexture, 0);
// check FBO status
FBOstatus = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if(FBOstatus != GL_FRAMEBUFFER_COMPLETE)
printf("GL_FRAMEBUFFER_COMPLETE failed, CANNOT use FBO\n");
// switch back to window-system-provided framebuffer
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glBindTexture(GL_TEXTURE_2D, 0);
}
I then render the fbo pass using:-
glDisable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, 0);
glBindFramebuffer(GL_FRAMEBUFFER, m_shadowFBO);
glClear(GL_DEPTH_BUFFER_BIT);
glColorMask(false, false, false, false);
glCullFace(GL_BACK);
Then to render the texture to a quad I use:-
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, m_depthTexture);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glColorMask(true, true, true, true);
The texture and viewport sizes are all the same and the fbo status test is saying it is complete. Can anyone see anything glaringly obvious that I am missing?