Alpha混合不适用于Android libgdx但适用于桌面

时间:2014-06-21 13:00:36

标签: java android libgdx opengl-es-2.0 blending

我在libgdx中使用alpha混合有一个奇怪的问题。我正在做的是绘制背景图片,绘制一个蒙版(使用ShapeRenderer完成),然后绘制前景。该面具在我的桌面上工作正常,但在我的Android设备上没有(Galaxy S2,联想ideaTab A2109)。我真的不知道发生了什么。有人可以帮帮我吗?或者至少给我一个关于发生了什么的暗示。感谢

我桌面上的结果: Result on Desktop:

我手机上的结果:

Result on my Phone:

我的渲染功能:

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();

绘制函数:

 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();
}

修改:如何使用着色器而不是Alpha蒙版?例如将ShapeRenderer中的所有白色像素替换为前景图像像素。这是个好主意吗?

1 个答案:

答案 0 :(得分:0)

OpenGL ES 2.0并不保证帧缓冲区的颜色缓冲区为8888。它只适用于某些设备。您必须使用RGBA4444,RGB565或RGB5_A1。

我这样做,所以我至少可以在装有OpenGL ES 3.0的设备上和桌面上使用8888:

Format format = (Gdx.graphics.getGL30()==null && 
    Gdx.app.getType()!=ApplicationType.Desktop) ?
        Format.RGB565 : Format.RGBA8888;
相关问题