OpenGl Blending
i want to blend two rects, but i want to draw only blended area (area where开发者_如何学运维 rects are intersecting), How to do it
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.
The intersection of two convex rects is always a rect. so why not just compute the intersection and draw only the that?
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
精彩评论