OpenGl Blending

511 Views Asked by At

i want to blend two rects, but i want to draw only blended area (area where rects are intersecting), How to do it

3

There are 3 best solutions below

1
On BEST ANSWER

If you don't want to compute the intersection you can probably use the stencil buffer to achieve that. read about it here:
http://bluevoid.com/opengl/sig00/advanced00/notes/node118.html

You can draw the two rects and with increment on the stencil buffer and then mask only the pixels that have value > 2, i.e. the pixels where 2 or more rects were drawn.

2
On

The intersection of two convex rects is always a rect. so why not just compute the intersection and draw only the that?

0
On
GLES20.glEnable( GLES20.GL_BLEND );
GLES20.glBlendFunc( GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA );

But you should set behavior of your blend function yourown. And in the shader I set alpha channel. You can see the result:

blending post. the source of android project