Apply mask to sprite

时间:2015-07-28 22:35:52

标签: java opengl libgdx

I have 3 sprites, a background, an object, and a mask that I want to apply to the object. I want the object sprite to be drawn on top of the transparent portion of the mask, but the portion around the object is displayed as white. How do I get rid of it?

This is the result I get: This is the result I get

This is the render function:

@Override
public void render() {
    Gdx.gl.glClearColor(1, 0, 0, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    batch.begin();

    mBackground.draw(batch);

    batch.setBlendFunction(GL20.GL_ZERO, GL20.GL_SRC_COLOR);
    mMask.draw(batch);

    batch.setBlendFunction(GL20.GL_DST_ALPHA, GL20.GL_ONE_MINUS_DST_ALPHA);
    mObject.draw(batch);

    batch.end();
}

0 个答案:

没有答案