FBO: depth buffer as texture

im wanting to do shadow mapping with some Cg.

now i’ve got an FBO set up with colour (just so i can see the thing) and a depth buffer, the depth buffer is 24bit, is there some way i can use the depth buffer as a texture? and will i be able to grab float values from it? ie. can i treat it as a float texture?

alternatively should i encode the depths in my colour texture? can you encode a float as RGBA somehow?

Just bind a depth texture instead of a depth renderbuffer to the FBO.

okay, i tried just this:

glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, width, height, 0,

				GL_TEXTURE_2D, texture, 0);


but gives me the FBO error: unsupported format

ie. similar problem as this fellow:

i have a geforce 6600gt

Have you disabled mipmapping? Try setting both filters to NEAREST, afaik mipmapping is not supported with depth textures…

hrmm okay im getting another error when i set filtering to nearest saying:

frame buffer incomplete, missing read buffer.

not sure what this means?

okay, i worked it out, i need to have a texture bound with GL_COLOR_ATTACHMENT0_EXT even though i dont want to render colour, which is a bit annoying, as i assume i would be loosing performance there.

Have you set the read and drawBuffer to gl_none?

Please re-read section of the spec. See also example code (7), “Render to depth texture with no color attachments.”