Saturday, May 14, 2016

The.Depth.Buffer. .glClearDepth.


[ State ]


[ Concept ]

       api.OpenGL

       The 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 buffering
Table 15-6 Depth Comparison Functions

NameFunction

GL_NEVERAlways False.
GL_LESSTrue if source Z < depth Z.
GL_EQUALTrue if source Z = depth Z.
GL_LEQUALTrue if source Z <= depth Z.
GL_GREATERTrue if source Z > depth Z.
GL_NOTEQUALTrue if source Z != depth Z.
GL_GEQUALTrue if source Z >= depth Z.
GL_ALWAYSAlways True.

The default comparison function is GL_LESS. To change it, call glDepthFunc:
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
depth
Specifies the depth value used when the depth buffer is cleared. The initial value is 1.


.....

[gamedev.stackexchange.com]

....

You use:
  • 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
Alternatively, you can use glDepthFunc to change the way the depth buffer is tested.
....



No comments:

Post a Comment