0
votes

I want to apply a shader to the whole screen using GLSL in my libGDX game. To clear the background with a color, I'm using

Gdx.gl.glClearColor(color.r, color.g, color.b, 1f);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

However, when I apply my shader to the stage's spritebatch:

stage.getBatch().setShader(shader);

... the shader only applies to drawn sprites of the stage, not the whole screen. I'm using a shader which turns affected pixels red, just for clarity:

How do I apply my shader to the whole screen?

1
You could try gamedev.stackexchange.com they might be able to help you better.Riaan van Zyl
A clear operation in OpenGL does not use shaders. When you want to apply a shader to the background, you'll have to draw a screen-filling sprite and apply the shader to that.BDL

1 Answers

1
votes

I figured it out: shaders only apply to rendered textures rendering. My background drawing code is now the following:

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

batch.begin();
batch.draw(background, 0, 0, width, height);
batch.end();

The variable background is a 2x2 texture which will fill the whole background.