0

I simply want to draw background, overlay it with 0.5f transparent black color to dim it and render on top of that a pause menu.

I have tried:

    Gdx.gl.glClearColor(0f, 0f, 0f, 0.5f);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

and nothing is working. I also couldn't find any solution online. My other option is to overlay a black sprite, but I don't want to do that. Is there anyway to paint it over with GL?

4

2 回答 2

2

好吧,我会画一个透明的矩形

    Gdx.gl.glEnable(GL20.GL_BLEND);
    Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
    shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
    shapeRenderer.setColor(new Color(0, 0, 0, 0.5f));
    shapeRenderer.rect(0, 0, screenWidth, screenHeight);
    shapeRenderer.end();
    Gdx.gl.glDisable(GL20.GL_BLEND);

希望这可以帮助

于 2015-10-03T11:48:31.723 回答
1

您唯一的解决方案是覆盖黑色精灵。是最有效率的,而且实践。

根据文档:

Alpha function, blend function, logical operation, stenciling, 
texture mapping, and depth-buffering are ignored by glClear.

glClear takes a single argument that is the bitwise OR of several
values indicating which buffer is to be cleared.

The values are as follows:

GL_COLOR_BUFFER_BIT
    Indicates the buffers currently enabled for color writing.

运行 glClear 后“下方”不能有更多颜色

于 2015-10-03T15:47:48.427 回答