I'm having a weird problem with alpha blending in libgdx. What I'm doing is drawing a background picture, drawing a mask (done using ShapeRenderer) and then drawing the foreground. The mask works fine on my Desktop but not on my Android devices (Galaxy S2, Lenovo ideaTab A2109). I really have no idea what's going on. Could someone help me out? Or at least give me a hint on what's going on. Thanks
Result on my Desktop:
Result on my phone:
My Render function:
Gdx.gl.glClearColor(0f, 0f, 0f, 0);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.setProjectionMatrix(camera.combined);
camera.zoom = 1f;
camera.update();
batch.begin();
drawBackground(batch);
batch.end();
frameBuffer.begin();
line.drawMask(false);
frameBuffer.end();
fboRegion.setTexture(frameBuffer.getColorBufferTexture());
batch.begin();
drawMask(batch);
drawForeground(batch)
batch.end();
draw functions:
private void drawBackground(SpriteBatch batch){
batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
page1.draw(batch);
page2.draw(batch);
batch.flush();
}
private void drawMask(SpriteBatch batch){
Gdx.gl.glColorMask(false, false, false, true);
batch.setBlendFunction(GL20.GL_ONE, GL20.GL_ZERO);
batch.draw(fboRegion, 0, 0);
batch.flush();
}
private void drawForeground(SpriteBatch batch){
Gdx.gl.glColorMask(true, true, true, true);
batch.setBlendFunction(GL20.GL_DST_ALPHA, GL20.GL_ONE_MINUS_DST_ALPHA);
page3.draw(batch);
batch.flush();
}
Edit: How about using shaders instead of an Alpha Mask? eg replace all white pixels from ShapeRenderer with foreground image pixels. Is it a good idea?
OpenGL ES 2.0 doesn't guarantee 8888 for a frame buffer's color buffer. it will only work on some devices. You have to use RGBA4444, RGB565, or RGB5_A1.
I do this so I can at least use 8888 on devices with OpenGL ES 3.0 and on the desktop:
Format format = (Gdx.graphics.getGL30()==null &&
Gdx.app.getType()!=ApplicationType.Desktop) ?
Format.RGB565 : Format.RGBA8888;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.