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

For the background render in my code I need to perform an operation that essentially acts like calling glClear(GL_DEPTH_BUFFER_BIT) except that it needs to use the current stencil buffer to mask out parts of the screen. The other requirement is that it has to work on fixed function pipeline systems, preferably back to OpenGL 1.3. Any suggestions on how to best do this?

share|improve this question
up vote 6 down vote accepted

You have to do this manually:

  • Disable depth testing.
  • Enable depth writing.
  • Set up an orthographic projection.
  • Enable stencil testing.
  • Draw a quad that covers the entire screen and whose Z is near your far plane.
share|improve this answer
More complex than I'd hoped, but it makes sense. I'm assuming there should be a glColorMask(GL_FALSE, GL_FALSE, GL_FALSE) in the setup to make it actually only clear the depth buffer. – jdougan Apr 2 '11 at 7:15

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.