FBO depth map almost completely washed out

I’m trying to render the depth buffer into a texture so that I can use it as a shadow map. I’ve got the FBO set up, but for some reason the depth map I get when rendering to a texture comes out almost entirely washed out. I’m using gDEBugger to see the depth buffer, and then the texture that the FBO writes to. Here’s the screen shots I took:

[img]http://i.imgur.com/RrsB1.png[/img]  

This is what the depth buffer looks like


This is what the texture the FBO writes to looks like

Believe it or not, the second image is not entirely white. I had to look at my display at a funky angle to check, but I can see the outlines that match the other image. The values of those pixels are something like 253, 253, 253 for the lighter sections and 251, 251, 251 for the “darker” ones.

Here’s how I’m creating the FBO:


GLuint fboId;
GLuint depthTextureId;

void generateShadowFBO()
{
	int shadowMapWidth = window.GetWidth();
	int shadowMapHeight = window.GetHeight();

	GLenum FBOstatus;

	glGenTextures(1, &depthTextureId);
	glBindTexture(GL_TEXTURE_2D, depthTextureId);

	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);

	glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, shadowMapWidth, shadowMapHeight, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, 0);
	glBindTexture(GL_TEXTURE_2D, 0);

	glGenFramebuffersEXT(1, &fboId);
	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fboId);

	glDrawBuffer(GL_NONE);
	glReadBuffer(GL_NONE);

	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, depthTextureId, 0);

	FBOstatus = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
	if(FBOstatus != GL_FRAMEBUFFER_COMPLETE_EXT)
		std::cout << "GL_FRAMEBUFFER_COMPLETE_EXT failed" << std::endl;

	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
}

Then I wrap the drawing calls with:


	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,fboId);
	glClear(GL_DEPTH_BUFFER_BIT);

        // draw calls
	
	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,0);

It’s basically the code from this tutorial. I made some modifications but changed it back to the original in case I made a mistake. I haven’t been able to figure this one out. Any ideas?

The depth buffer keeps values from 0.0 to 1.0 but not in linear manner but in exponential. This practically means that if you visualize it it will be black in pixels very very close to the camera.

To make it linear (just to see it) use this:
(2.0 * zNear) / (zFar + zNear - depth * (zFar - zNear))