Problem with rendering the depth buffer to a texture. . .

I got this working by hacking the GameTutorials.com “Render to Texture” tutorial to render the depth buffer to the texture rather than the colour buffer. However, when I tried doing the same thing basing the program off of NeHe’s basic framework, it doesn’t work at all. Nothing appears to get rendered to the texture. . . Rather than just post a massive code sample, I’ve provided a link to the program, with source code.
http://members.shaw.ca/dwkjo/Files/ShadowTest.zip

I’m using the ARB_depth_texture extension for depth texture formats.

Instead of:

glTexImage2D (GL_TEXTURE_2D, 0, 1, size, size, 0, GL_DEPTH_COMPONENT24_ARB, GL_UNSIGNED_INT, pTexture);

try:

glTexImage2D (GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24_ARB, size, size, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, pTexture);

BTW, you don’t have to allocate memory just to have a pointer to pass to glTexImage, you can just use NULL and it will still set the texture object and allocate the texture memory for that texture object.

Hi

I use following to copy the z buffer into a texture:

glCopyTexImage2D(GL_TEXTURE_RECTANGLE_NV,0,GL_DEPTH_COMPONENT24_ARB,x,y,w,h,0);

Bye
ScottManDeath

Still not working. . . Rendering the colour buffer to the RGB texture doesn’t seem to work either. . . All I get is white.

Originally posted by Ostsol:
Still not working. . . Rendering the colour buffer to the RGB texture doesn’t seem to work either. . . All I get is white.

Not sure why rendering RGB doesn’t work, but I’ve emailed you a “fixed” version of your “ShadowTest” program.

Ah. . . thanks! I didn’t know that I had to worry about the near clipping plane for this. Time to read more about the depth buffer.