tags:

views:

80

answers:

3

I would like to for example draw shapes A, B, C then set the blender, then draw shape D and everywhere where shape D is, the scene shows my background color of (1,1,1,0). Thanks

+4  A: 

I'm not aware of that being possible directly. There are a few possibilities to get the same effect though. The cleanest would probably be to start by filling the stencil buffer with 1's, then drawing shape D into the stencil buffer with 0's, then draw everything else (with the stencil buffer enabled, of course).

Jerry Coffin
+1 I was just about to suggest that!
Blindy
A: 

glBlendEquation can do it.

Matias Valdenegro
That doesn't even come close to what the op is asking.
Blindy
It's not? If I have a shape set to 1,1,1,0 the result of SUBTRACT operation should make the new pixel 1,1,1,0?
Milo
@Blindy The question title refers to substractive blending, but now that you mention it, the question body refers to another completely different matter.
Matias Valdenegro
A: 

Much simpler than other answers :

  • Display shapes A, B and C the normal way
  • glDisable(GL_DEPTH_TEST);
  • glDisable(GL_ALPHA_TEST);
  • glDisable(GL_BLEND);
  • Display shape D with color (1,1,1,0)

and you're done.

Calvin1602
Sometimes the simplest solution is the best ;) thanks
Milo
@Jex you may want to disable depth writes as well, depending on what you're trying to do
Calvin1602