Skip to main content
gamedev.net
🔒 Locked

Stencil buffer

Started by pie Mar 23, 2003 at 7:04 AM 1 replies 300+ views
Original Post
pie
pie
Hey. I just read the stencil buffer tutorial, but I can''t quite understand why the depth buffer must be disabled before drawing the floor into the stencil buffer. Why ?
janharal
janharal
The depthbuffer is disabled because otherwise the "real" floor won''t be drawn.

The floor is drawn twice: The first time only the stencil buffer should be updated, so the depthbuffer and the colorbuffer are disabled.
If depthtest had been enabled the first time, nothing would be drawn the second time because the z-buffer test would fail.

It is perhaps clearer if you replace the calls to glDisable/Enable(GL_DEPTH_TEST) with:
glDepthMask(false); // do not update zbuffer
DrawFloor();
glDepthMask(true);

I guess glDisable(GL_DEPTH_TEST) is used in the tutorial because the floor is the first thing to be drawn so there is no need to do any zbuffer tests at all.
pie
pie
Yeah, thanks. I get it now :=)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.