Extracting z coordinate from z buffer

Is it possible to extract the z coordinate of a fragment from the information stored in the z buffer?

If yes, is this solution portable amongst desktop graphics accelerators and hi-end workstations?

Cheers,

camelo

1.) Yes, glReadPixels with GL_DEPTH_COMPONENT.
2.) Yes, this is a standard OpenGL method. The performance may vary among implementations.

Ok. So far so good. Now I need to convert the z information extracted from the z buffer back to camera space. How can I do that?

Thaks,

–camelo

Found it…

gluUnProject

Thanks anyway.

Does gluUnproject() do what you want?

Or have I missed the point…

Originally posted by camelo:
Now I need to convert the z information extracted from the z buffer back to camera space.

Haven’t tried that myself, but I’ve heard people say that even though the data in the z-buffer are depth values it might not be that easy to map them back to camera space.To my knowledge OpenGL doesn’t specify what format the depth values are stored in, it is implementation specific.