Libgdx 使用 glClearColor 调暗屏幕

Libgdx dim screen with glClearColor

我只是想绘制背景,用 0.5f 透明黑色覆盖它使其变暗并在其上渲染一个暂停菜单。

我试过:

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

没有任何效果。我也无法在线找到任何解决方案。我的另一个选择是覆盖一个黑色精灵,但我不想这样做。有没有办法用GL把它涂上去?

嗯,我会画一个透明的矩形

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

希望对您有所帮助

你唯一的解决办法是覆盖一个黑色精灵。是最有效率的,多实践。

根据文档:

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

之后不能有更多的颜色 "under"