[英]Java: Why can't I properly render colours (RGBA) with LibGdx?
When I change the colours to blue Gdx.glClearColor(0,0,255,1)
then it works as it should. 当我将颜色更改为蓝色
Gdx.glClearColor(0,0,255,1)
时,它应能正常工作。 But when I use Gdx.glClearColor(51,204,255,1)
the colour remains white. 但是当我使用
Gdx.glClearColor(51,204,255,1)
,颜色仍然是白色。 What do I have to change to make it work? 我必须进行哪些更改才能使其正常工作?
@Override
public void render(float delta) {
Gdx.gl.glClearColor(51,204,255,1); // this makes the screen white
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
camera.update();
game.batch.setProjectionMatrix(camera.combined);
game.batch.begin();
game.batch.draw(game.hermine, 0, 0, (int)(game.hermine.getWidth() * 0.25), (int)(game.hermine.getHeight() * 0.25));
game.batch.end();
if (Gdx.input.isTouched()) {
game.setScreen(new GameScreen(game));
dispose();
}
}
The function glClearColor()
works with a range between 0 - 1. glClearColor()
函数的作用范围是glClearColor()
。
So glClearColor(1, 1, 1, 1);
所以
glClearColor(1, 1, 1, 1);
is white an glClearColor(0, 0, 0, 1);
是白色的
glClearColor(0, 0, 0, 1);
is black. 是黑色的。
glClearColor(0, 0, 255, 1);
works because it's the same like glClearColor(0, 0, 1, 1);
之所以可以工作是因为它与
glClearColor(0, 0, 1, 1);
glClearColor(51, 204, 255, 1);
does not work because it's the same as glClearColor(1, 1, 1, 1);
不起作用,因为它与
glClearColor(1, 1, 1, 1);
and this is white. 这是白色的。
You must work in a Range from 0 - 1 so to become your expected result you must write: Gdx.gl.glClearColor(0.2f, 0.8f, 1, 1);
您必须在0到1的范围内工作,因此要获得预期的结果,您必须编写:
Gdx.gl.glClearColor(0.2f, 0.8f, 1, 1);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.