Jump to content
  • Advertisement
Sign in to follow this  
supagu

stencil buffer

This topic is 4441 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

okay ive never used the stencil buffers really much before, and im wanting to use it to stop rending outside of my 2d UI windows. so, to start with i was trying to set up the stencil buffer to simply not allow anything to be drawn, but i cant get this working here is my code snippet: glEnable(GL_STENCIL_TEST); glStencilFunc(GL_EQUAL, 1, 0xFF); // if the stencil buffer has a value of 1, draw the pixel, else discard it glStencilOp(GL_ZERO, GL_ZERO, GL_ZERO); // if the pixel passes, fails or does anything, put zero in the stencil buffer // do render glDisable(GL_STENCIL_TEST); my comments are there and indicate what i think should be happening at that stage, any way, when i render stuff it always renders as not expected to happen :-/ ideas on what ive done wrong?

Share this post


Link to post
Share on other sites
Advertisement
If your UI windows are rectangular, it's probably much easier to just use scissoring instead.

(look up glScissor() and friends in your reference guide)

Share this post


Link to post
Share on other sites
you didn't tell how you initialize your stencil (the value it has when it's cleared...) that could be the problem...

example :

* set the clear value of the stencil to 0
* clear it
* set stencil to allways pass and write 1 when it does
* RENDER THE MASK GEOMETRY
* disable stencil write and set stencil to pass when its equal or not to 1
* RENDER THE "STENCIL CLIPPED" GEOMETRY

this should do it...

hope it clears some things,
JFD

Share this post


Link to post
Share on other sites
glClearStencil(0);
glClear(GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);

currently i have no mask geometry, just trying to get when i render something for it not to show up (which would indicate the stencil buffer is working)

Share this post


Link to post
Share on other sites
pfd.cStencilBits = 1;

did you put that option ? it's really important to specify it when calling :
pixel_format = ChoosePixelFormat( hdc, &pfd );

Share this post


Link to post
Share on other sites
You should probably be asking for an 8-bit stencil buffer. And also ask for a 24-bit depth buffer, depth and stencil are often packed together (this is also why it's recommended to always clear them at the same time).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!