How do I clip an image in OpenGL ES on Android?
Posted
by
Maxim Shoustin
on Game Development
See other posts from Game Development
or by Maxim Shoustin
Published on 2013-07-21T13:09:08Z
Indexed on
2013/10/28
22:15 UTC
Read the original article
Hit count: 251
My game involves "wiping off" an image by touch:
After moving a finger over it, it looks like this:
At the moment, I'm implementing it with Canvas
, like this:
9Paint pTouch;
9int X = 100;
9int Y = 100;
9Bitmap overlay;
9Canvas c2;
9Rect dest;
pTouch = new Paint(Paint.ANTI_ALIAS_FLAG);
pTouch.setXfermode(new PorterDuffXfermode(Mode.SRC_OUT));
pTouch.setColor(Color.TRANSPARENT);
pTouch.setMaskFilter(new BlurMaskFilter(15, Blur.NORMAL));
overlay = BitmapFactory.decodeResource(getResources(),R.drawable.wraith_spell).copy(Config.ARGB_8888, true);
c2 = new Canvas(overlay);
dest = new Rect(0, 0, getWidth(), getHeight());
Paint paint = new Paint();9
paint.setFilterBitmap(true);
...
@Override
protected void onDraw(Canvas canvas) {
...
c2.drawCircle(X, Y, 80, pTouch);
canvas.drawBitmap(overlay, 0, 0, null);
...
}
@Override
9public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_MOVE: {
X = (int) event.getX();
Y = (int) event.getY();9
invalidate();
c2.drawCircle(X, Y, 80, pTouch);9
break;
}
}
return true;
...
What I'm essentially doing is drawing transparency onto the canvas, over the red ball image.
Canvas
and Bitmap
feel old... Surely there is a way to do something similar with OpenGL ES. What is it called? How do I use it?
[EDIT]
I found that if I draw an image and above new image with alpha 0, it goes to be transparent, maybe that direction?
Something like:
gl.glColor4f(0.0f, 0.0f, 0.0f, 0.01f);
© Game Development or respective owner