Blending question

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?

Thanks

  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.

http://glprogramming.com/red/chapter10.html
http://www.opengl.org/wiki/Stencil_Mask

Why do I need to make a hole in polygon A? Won’t using a stencil buffer already draw a hole in A?

It wasb two different solutions… sorry for confusion.

ahh ok :slight_smile:

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

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)

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

http://portal.acm.org/citation.cfm?id=1179997

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?

ok it’s working, I was doing it in the wrong order :slight_smile: