View Full Version : Blending question

05-25-2009, 07:00 AM
Hey everybody

Let's say I have a background, a polygon (A) on top of that and a smaller polygon (B) on top of polygon A. I want B to look like it's cut out of A so it looks like a hole. I've managed to do this by using
Gl.glBlendFunc(Gl.GL_ZERO, Gl.GL_ONE_MINUS_SRC_ALPHA);. However while there is now a hole in A, my "background" has also disappeared leaving me with a black hole. Even when I reset glBlendFunc to its original settings afterwards. Around polygon A, the background is fine, but underneath polygon B I have a black hole now. Can anybody help?


05-25-2009, 07:26 AM
1. Make hole in polygon A that looks like B and dont draw polygon B.
2. Using stencil bufer. Draw B in stencil buffer (disable color & depth writes) and then draw A but use stencil function to discard fragments that belongs to B.


05-26-2009, 02:47 AM
Why do I need to make a hole in polygon A? Won't using a stencil buffer already draw a hole in A?

05-26-2009, 02:50 AM
It wasb two different solutions.. sorry for confusion.

05-26-2009, 02:56 AM
ahh ok :)

well option 1 is not possible since I'm already using highly complex polygons which have to be triangulated/tesselated

05-26-2009, 05:10 AM
Like this?

Gl.glStencilFunc(Gl.GL_ALWAYS, 1, 1);
Gl.glStencilOp(Gl.GL_KEEP, Gl.GL_KEEP, Gl.GL_REPLACE);

(draw polygon B)

Gl.glStencilFunc(Gl.GL_EQUAL, 1, 1);
Gl.glStencilOp(Gl.GL_KEEP, Gl.GL_KEEP, Gl.GL_KEEP);

(draw polygon A)

05-26-2009, 07:35 AM
Fwiw, chapter 25 of GPU Gems 3 (available online) mentions a stencil based approach to triangulating vector art.

Can't find a freebie but it's based on this


05-27-2009, 02:11 AM
I managed to get it to work but on my test pc using a S3 Twister card, the CPU load jumps to 100%. Does that mean the video driver can't handle stencil buffers?

05-27-2009, 04:53 AM
ok it's working, I was doing it in the wrong order :)