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_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL);

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

  

but gives me the FBO error: unsupported format

ie. similar problem as this fellow:
http://www.flipcode.com/cgi-bin/fcmsg.cgi?thread_show=25864&msg=205080

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 4.4.4.2 of the spec. See also example code (7), “Render to depth texture with no color attachments.”