Reputation: 727
I am learning OpenGL ES2.0. I need a stencil buffer in my project.
What I am going to do:
1) Create a stencil buffer.
2) Load a 8-bit gray color image into this stencil buffer (which is also 8-bit per pixel).
3) The gray color image has different area (by setting different part a different value), so I can render for each area by changing the stencil test value.
I've searched for a lot time, still have no idea on how to load the image into stencil buffer.
So for the image above, I set stencil value as 1 for the blue area, and set 2 for the greeen area. How to implement this?
Upvotes: 2
Views: 335
Reputation: 100632
If your bitmap were 1 bit, just write a shader that either discard
s or allows pixels to proceed based on an alpha test, or use glAlphaFunc
to do the same thing if under the fixed pipeline, and draw a suitable quad with the appropriate glStencilFunc
.
If it's 8-bit and you genuinely want all 8 transferring to the stencil, the best cross-platform solutions I can think of either involve 8 draws — start from 0, use glStencilMask
to isolate individual bits, set glStencilOp
to invert, test for non-zero in the relevant bit in your shader — or just using the regular texture and implementing the equivalent of a stencil test directly in your shader.
Upvotes: 1