   Problems with Depthbuffer
  Hi,I am trying to read out the depth-values of my scene with glReadPixels to use it as a parameter for the gluUnProject-method.It seems that the glReadPixels-function does not work properly - for example I tried the following lines of code, after rendering some objects: GLfloat depthValue[512*512]; glReadPixels(0, 0, 512, 512, GL_DEPTH_COMPONENT, GL_FLOAT, depthValue); glClear(GL_DEPTH_BUFFER); glReadPixels(0, 0, 512, 512, GL_DEPTH_COMPONENT, GL_FLOAT, depthValue);I would expect, that after the first readPixels there are a lot of values between 0.0 and 1.0 - the depthvalues of my scene, there really are, but all of them in a range between 0.995 and 1.00). But after the second readPixels I would expect the array is full of zeros (or ones? does not matter) - but the array still contains the same values. How is that possible?   
glClear(GL_DEPTH_BUFFER_BIT);;  Did you set any depth scale or bias? How where are your scene objects located with respect to the camera? If they are all quite far away, a depth between 0.995 and 1.0 might be plausible. Keep in mind that the depth buffer is non-linear.For the second read, did you check if there was an error before? If there was an error, the contents of depthValue would not be changed.Here's a good German reference for OpenGl, in case you don't know it already.Edit: roz666 you're right. Shame on me I didn't see that [embarrass].   ;  That was too obvious for me to see ;) Thanks!Well but I am still not sure with the high depth-values. Some objects are directly in front of me - so i would expect some very low values too. I did not change the depthscale oder bias..   ;  While those high depth values seem to be weird at first they are perfectly valid and ok. Note that your depth buffer does not store linear values. Most of the precision (for perspective projection) is used up for the objects immediately close to the near clipping plane. Everything else that is more distant gets banned to depth values > 0.9. Disturbingly "more distant" is quite a small value and heavily depends on where your near plane is located with respect to the far plane. If your near plane is eg. at 0.1 while the far plane is at 1000 then even those objects just a few units away from the camera are considered to be very distant with respect to the depth buffer.   ;  Great, that makes sense.. Thank you - so my code seems to be alright now, I just have to watch the clipping-planes values.   