Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what's the purpose of glClear(GL_DEPTH_BUFFER_BIT)

when using Opengl to draw scene graph, I saw there is always a glClear(GL_DEPTH_BUFFER_BIT), what's the purpose for this?

like image 788
Adam Lee Avatar asked Jul 01 '12 14:07

Adam Lee


People also ask

What is the function of glClear?

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.

What does glClear Gl_color_buffer_bit do?

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).

What is GL depth buffer bit?

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.

What is color buffer bit?

The COLOR_BUFFER_BIT constant indicates the buffers currently enabled for color writing.


1 Answers

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.

like image 176
datenwolf Avatar answered Sep 19 '22 06:09

datenwolf