How to remove (cut) a transparent rectangle in a texture so that the hole is translucent.
On Android, I would use the Xfermodes approach:
How to use masks in android
But in libgdx I have to use opengl. So far, I almost got what I was looking for using glBlendFunc. From this nice and very useful page, I tell you that
glBlendFunc(GL_ZERO, GL_ONE_MINUS_SRC_ALPHA);
should solve my problem, but I tried this and it didn’t work as expected:
batch.end();
batch.begin();
//Draw the background
super.draw(batch, x, y, width, height);
batch.setBlendFunction(GL20.GL_ZERO,
GL20.GL_ONE_MINUS_SRC_ALPHA);
//draw the mask
mask.draw(batch, x + innerButtonTable.getX(), y
+ innerButtonTable.getY(), innerButtonTable.getWidth(),
innerButtonTable.getHeight());
batch.end();
batch.setBlendFunction(GL20.GL_SRC_ALPHA,
GL20.GL_ONE_MINUS_SRC_ALPHA);
batch.begin();
It just makes the mask area plain black, while I expected transparency, any ideas.
This is what I get:

This is what I expected:

source
share