How I can use to stencil buffer for my easiest program? I have read many different themes about it, but I not found a detailed guide about it. I want to cut out for hole each side in a created tetrahedron.
Please explain to me step by step use stencil buffer?
To use the stencil buffer you have to first request it when you create the webgl context
Then you turn on the stencil test
Set up the test so it always passes and set the reference value to 1
And set the operation so we'll set the stencil to the reference value when both the stencil and depth tests pass
We then draw the first inner triangle
Then we change the test so it only passes if the stencil is zero
and now we can draw something else (the larger triangle) and it will only draw where there is 0 in the stencil buffer which is everywhere except where the first triangle was drawn.
Example: