How to clear stencil buffer after stencil test?

Hi,

I use glut and in the display function, I clear the stencil buffer and draw some geometry with stencil test on. after that I want to clear the stencil buffer immediately. I use

glClearStencil(0X0);
glClear(Stencil_buffer_bit);

then I read the stencil buffer but it is same. I need to use stencil test multiple times during the display function.

How to clear it during display? so I can use it for next stencil test.

its glClear(GL_STENCIL_BUFFER_BIT); are you aware of that. It should have given you a compile error though

[This message has been edited by mdog1234 (edited 06-13-2003).]

thanks for your reply, I am aware of that. I just want to show the idea, sorry I did not use the correct word.

I run the program and after I clear the stencil buffer, I read it into the main memory and check the value, it is still the same as the one before I clear it. I also try to use stencil test to clear it, it is still not working.

Buffer clears are required to take scissoring and masking into account.

Before clearing the stencil, try inserting

glStencilMask(~0);
glDisable(GL_SCISSOR_TEST);

and see if this helps.

2 Likes

Thanks so much, zeckensack, I appreciate your help. It works.

some information I want to add after I tested the program.

It seems that glStencilMask(~0) works, because I used this function when I do stencil test in the program, now I need to set it to ~0 to make clearing works.

scissor test seems have not effect on clearing buffer in my program.

again, thanks very much

This helps, thank you for sharing this.

1 Like