Adam Lee
Adam Lee

Reputation: 25768

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?

Upvotes: 7

Views: 6757

Answers (2)

Y.C
Y.C

Reputation: 11

When an object is drawn to the screen, the distance between the screen(plane) and the object should be considered first. This value of distance is stored as Z value (Z-buffer). If there exists another object B between the plane and the object, the Z value is used to determine which object should be drawn on this pixel. So you should understand why the Z-buffer needs to be cleared every time when we initialize the program. This way, we can make sure that there is no incorrect value stored in Z-buffer value which may be drawn onto the screen by accident.

Upvotes: 0

datenwolf
datenwolf

Reputation: 162299

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.

Upvotes: 9

Related Questions