1

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

genpfault
  • 51,148
  • 11
  • 85
  • 139
ZZZ
  • 678
  • 2
  • 10
  • 26

3 Answers3

1

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.

shoosh
  • 76,898
  • 55
  • 205
  • 325
  • I dont think thats possible, or maybe i dont fully understand how stencil buffer works, i have one big vertex array with all rects inside, i cannot draw them one by one because there are lot of them and its very slow. I need to go deeper with scencil :) – ZZZ May 05 '11 at 11:56
0

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

shoosh
  • 76,898
  • 55
  • 205
  • 325
0
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

Yuriy Vikulov
  • 2,469
  • 5
  • 25
  • 32