Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Using glClear() you can set the buffer specified by the parameter to 0.0. This is useful say if you want pixels not covered by models to be black. Because vec3(0.0, 0.0, 0.0) results in black.

But for the depth buffer, clearing means to set it to the maximum value 1.0 since you don't want pixels not covered by models to have the depth 0.0 which is the camera's position but to have the depth 1.0 which means as far away as possible.

So how can I clear the depth buffer to 1.0 or come over this issue in another way?

share|improve this question
up vote 6 down vote accepted

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.

share|improve this answer
Since what I have isn't an actual depth buffer but a color buffer using glClearColor is what I was looking for. – danijar Mar 28 '13 at 17:30

You can use the function glClearDepth where you can specify what to clear the depth buffer to. however I think glClear() clears the depth buffer to 1.0 by default.

glClear sets the bitplane area of the window to values previously selected by glClearColor, glClearDepth, and glClearStencil

As glClearDepth states

Specifies the depth value used when the depth buffer is cleared. The initial value is 1.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.