I want to make background of my game like lava via perlin noise.
I've read some tutorials but they were too old and some api calls aren't exist already.
If I understand right in libgdx I need to create a runtime-generated texture (FrameBuffer) on x=0 and y=0 with width=Screen width
and height=Screen height
and apply shader to it.
I tried to do:
class A extends ApplicationAdapter {
FrameBuffer background;
ShaderProgram shaderProgram;
public void create() {
background = new FrameBuffer(
Pixmap.Format.RGBA8888,
Gdx.graphics.getWidth(),
Gdx.graphics.getHeight(),
false
);
shaderProgram = /* stuff to pickup .vert and .frag */
}
@Override
public void render () {
Gdx.gl.glClearColor(0f, 0f, 0f, 0f);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
background.begin();
batch.setProjectionMatrix(
new Matrix4().setToOrtho2D(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight())
);
batch.begin();
batch.setShader(shaderProgram);
batch.end();
background.end();
}
}
My shaders are simple red fill programs:
//Vertex
attribute vec4 a_position;
uniform mat4 u_projTrans;
varying vec2 v_Pos;
void main() {
gl_Position = u_projTrans * a_position;
v_Pos = gl_Position;
}
//Fragment
#ifdef GL_ES
precision mediump float;
#endif
uniform mat4 u_projTrans;
varying vec2 v_Pos;
void main() {
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
}
Nothing has been drawn. I expect that all my viewport become red
Function that picks up shaders is working, i tested at sprites