I am new to all of these shader materials and don’t want to, just trying to replace the default SpriteBatch renderer in LibGDX.
I copied the default shader insert and tried to add the shape of the mice, but it gives me "Without uniform with the name" u_mouse "in the shader.
This is all related code:
String vertexShader = "attribute vec4 " + ShaderProgram.POSITION_ATTRIBUTE + ";\n"
+ "attribute vec4 " + ShaderProgram.COLOR_ATTRIBUTE + ";\n"
+ "attribute vec2 " + ShaderProgram.TEXCOORD_ATTRIBUTE + "0;\n"
+ "uniform mat4 u_projTrans;\n"
+ "uniform vec2 u_mouse;\n"
+ "varying vec4 v_color;\n"
+ "varying vec2 v_texCoords;\n"
+ "\n"
+ "void main()\n"
+ "{\n"
+ " v_color = u_mouse * " + ShaderProgram.COLOR_ATTRIBUTE + ";\n"
+ " v_texCoords = " + ShaderProgram.TEXCOORD_ATTRIBUTE + "0;\n"
+ " gl_Position = u_projTrans * " + ShaderProgram.POSITION_ATTRIBUTE + ";\n"
+ "}\n";
String fragmentShader =
"#ifdef GL_ES\n"
+ "#define LOWP lowp\n"
+ "precision mediump float;\n"
+ "#else\n"
+ "#define LOWP \n"
+ "#endif\n"
+ "varying LOWP vec4 v_color;\n"
+ "varying vec2 v_texCoords;\n"
+ "uniform sampler2D u_texture;\n"
+ "uniform vec2 u_mouse;\n"
+ "void main()\n"
+ "{\n"
+ " gl_FragColor = v_color * texture2D(u_texture, u_mouse);\n"
+ "}";
ShaderProgram shaderTest = new ShaderProgram(vertexShader, fragmentShader);
shaderTest.setUniformf("u_mouse", Gdx.input.getX(), Gdx.input.getY());
This is the stack trace:
Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: java.lang.IllegalArgumentException: no uniform with name 'u_mouse' in shader
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:113)
Caused by: java.lang.IllegalArgumentException: no uniform with name 'u_mouse' in shader
at com.badlogic.gdx.graphics.glutils.ShaderProgram.fetchUniformLocation(ShaderProgram.java:283)
at com.badlogic.gdx.graphics.glutils.ShaderProgram.setUniformf(ShaderProgram.java:394)
at com.nehatchick.games.wf.WhiteMountains.render(WhiteMountains.java:424)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:187)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:110)
source
share