PDA

View Full Version : an easy problem



thunder2001
04-23-2004, 12:38 AM
how can i open the depth buffers??thank you !!

Relic
04-23-2004, 04:30 AM
Open?
You need to request a pixelformat with depth buffer bits, that is in GLUT GLUT_DEPTH, or the depthBits field in the PIXELFORMATDESCRIPTOR structure.
To draw with depth buffering you need to glEnable(GL_DEPTH_TEST) (default off) and make sure glDepthMask(GL_TRUE) (default true).
You can read the contents of the depth buffer with glReadPixels(x, y, width, height, GL_DEPTH_COMPONENT, GL_UNSINGED_INT, pDepthBuffer);
It will put the depth values in the most significant bits if there are less than 32.
You can also use GL_FLOAT and get number between 0.0f and 1.0f, but the readback will be slower because of the conversion to floats.
If you want to look at the data as colors, you can do different things, like glDrawPixels or texture downloads and textured rendering.