[ State ]
[ Concept ]
api.OpenGLThe Depth Buffer
The depth buffer holds distance values for each pixel. Each value represents the pixel’s distance from the viewer and is scaled to fill the current near/far clipping volume. The software implementation of OpenGL under Windows supports both 16- and 32-bit depth values.The depth buffer is normally used to perform hidden surface removal. Hidden surface removal is a process that occurs naturally in the real world; when one solid (opaque) object is placed in front of another, the nearer object will hide some or all of the one behind it.
In OpenGL, the depth buffer can also be used for some interesting effects, such as cutting away the front of objects to show the inner surfaces
Depth Comparisions
When you draw in a window using OpenGL, the Z position of each pixel is compared with the value in the depth buffer. If the result of the comparison is True, the pixel is stored in the color buffer along with its depth. OpenGL defines eight depth-comparison functions that can be used for depth bufferingThe default comparison function is GL_LESS. To change it, call glDepthFunc:
Table 15-6 Depth Comparison Functions
Name Function
GL_NEVER Always False. GL_LESS True if source Z < depth Z. GL_EQUAL True if source Z = depth Z. GL_LEQUAL True if source Z <= depth Z. GL_GREATER True if source Z > depth Z. GL_NOTEQUAL True if source Z != depth Z. GL_GEQUAL True if source Z >= depth Z. GL_ALWAYS Always True.
glDepthFunc(function);
Using the GL_LESS function, pixels in a polygon are drawn if the depth value of the pixel is less than the depth value in the depth buffer.
Depth Values
...
...
Applications of the Depth Buffer
...
...
[ URL ][ Content ]
Name
glClearDepth — specify the clear value for the depth buffer
....
C.Spec
void glClearDepth( GLclampd depth);
...
Param
depthSpecifies the depth value used when the depth buffer is cleared. The initial value is 1.
.....
[gamedev.stackexchange.com]
....
You use:
Alternatively, you can use glDepthFunc to change the way the depth buffer is tested.
- glClearColor(r, g, b, a) to set the color of glClear(GL_COLOR_BUFFER_BIT)
- glClearDepth(depth) for the depth buffer
- glClearStencil(stencil) for the stencil buffer
....
No comments:
Post a Comment