What is the purpose of glClear (GL_DEPTH_BUFFER_BIT)

when using Opengl to draw a scene graph, I saw that there is always glClear (GL_DEPTH_BUFFER_BIT), what is it for?

+7
source share
2 answers

Clears the depth buffer. The depth buffer is part of the frame buffer, which makes the primitives closed by other primitives in front of them. Without clearing the depth buffer, you must draw the depth structure of the previous drawing.

+9
source

When an object accesses the screen, first consider the distance between the screen (plane) and the object. This distance value is stored as the Z value (Z-buffer). If another object B exists between the plane and the object, the Z value is used to determine which object should be drawn on this pixel. Therefore, you must understand why the Z-buffer needs to be cleaned every time we initialize the program. Thus, we can make sure that in the value of the Z-buffer there is no wrong value that can be accidentally drawn on the screen.

0
source

All Articles