when using Opengl to draw scene graph, I saw there is always a glClear(GL_DEPTH_BUFFER_BIT), what's the purpose for this?
The glClear function sets the bitplane area of the window to values previously selected by glClearColor, glClearIndex, glClearDepth, glClearStencil, and glClearAccum. You can clear multiple color buffers simultaneously by selecting more than one buffer at a time using glDrawBuffer.
A call to glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) clears the OpenGL color and depth buffers (or any other buffer or combination of buffers).
The depth buffer is automatically created by the windowing system and stores its depth values as 16 , 24 or 32 bit floats. In most systems you'll see a depth buffer with a precision of 24 bits. When depth testing is enabled, OpenGL tests the depth value of a fragment against the content of the depth buffer.
The COLOR_BUFFER_BIT constant indicates the buffers currently enabled for color writing.
It clears the depth buffer. The depth buffer is the part of the frame buffer, that makes primitives being occluded by other primitives in front of them. Without clearing the depth buffer, you'd draw into the depth structure of the previous drawing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With