PDA

View Full Version : Problem with rendering the depth buffer to a texture. . .



Ostsol
02-26-2003, 07:48 PM
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.

NitroGL
02-26-2003, 08:44 PM
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.

ScottManDeath
02-27-2003, 08:14 AM
Hi

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




glCopyTexImage2D(GL_TEXTURE_RECTANGLE_NV,0,GL_DEPT H_COMPONENT24_ARB,x,y,w,h,0);


Bye
ScottManDeath

Ostsol
02-27-2003, 11:34 AM
Still not working. . . Rendering the colour buffer to the RGB texture doesn't seem to work either. . . All I get is white.

NitroGL
02-27-2003, 12:23 PM
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.

Ostsol
02-27-2003, 01:11 PM
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.