Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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

2 Answers 2

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. http://www.opengl.org/sdk/docs/man/xhtml/glClearDepth.xml 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

 
discard

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.