Reputation: 73
Similar Questions: No uniform with name in shader , Fragment shader: No uniform with name in shader
LibGDX: libgdx.badlogicgames.com
LibOnPi: www.habitualcoder.com/?page_id=257
I am attempting to run LibGDX on a Raspberry Pi with little luck. After some trial and error I eventually got it to start throwing the error "no uniform with name 'mvp' in shader". The problem is much like the similar questions, however in my situation it seems to me that 'mvp' is actually being used by the shader to set the positions.
The really strange part is that it runs on the PC (Windows 7 x64 in Eclipse ADT) just fine, but not on the Pi. Does the pi handle shaders differently, if not, what is causing this error to be thrown exclusively on the pi?
Vertex_Shader =
"attribute vec3 a_position; \n"
+ "attribute vec4 a_color; \n"
+ "attribute vec2 a_texCoords; \n"
+ "uniform mat4 mvp; \n"
+ "varying vec4 v_color; \n" + "varying vec2 tCoord; \n"
+ "void main() { \n"
+ " v_color = a_color; \n"
+ " tCoord = a_texCoords; \n"
+ " gl_Position = mvp * vec4(a_position, 1f); \n"
+ "}";
Fragment_Shader =
"precision mediump float; \n"
+ "uniform sampler2D u_texture; \n"
+ "uniform int texture_Enabled; \n"
+ "varying vec4 v_color; \n"
+ "varying vec2 tCoord; \n"
+ "void main() { \n"
+ " vec4 texColor = texture2D(u_texture, tCoord); \n"
+ " gl_FragColor = ((texture_Enabled == 1)?texColor:v_color); \n"
+ "}";
...
shader = new ShaderProgram(Vertex_Shader, Fragment_Shader);
...
shader.setUniformMatrix("mvp", camera.combined);
I also noticed this question: c++ OpenGL glGetUniformLocation for Sampler2D returns -1 on Raspberry PI but works on Windows which is quite similar, however implementing the proposed solution of putting the "#version 150" at the top of the shader just broke it on the PC too. (stated that there was no uniform with name 'mvp')
EDIT:
1 - Added Fragment Shader at request of keaukraine
2 - Fix found by Keaukraine and ArttuPeltonen. Raspberry Pi requires a version number in the shader. OpenGl-ES 2.0 uses version 100
Upvotes: 4
Views: 213
Reputation: 73
Answer provided by keaukraine and ArttuPeltonen
Raspberry Pi requires a version number in the shader. OpenGl-ES 2.0 uses version 100. It did not work when I initially tried it due to forgetting to add whitespace. "#version 100attribute..." is not the same as "#version 100\nattribute"
Example Final Shader:
Vertex_Shader =
"#version 100\n"
+ "attribute vec3 a_position; \n"
+ "attribute vec4 a_color; \n"
+ "attribute vec2 a_texCoords; \n"
+ "uniform mat4 mvp; \n"
+ "varying vec4 v_color; \n" + "varying vec2 tCoord; \n"
+ "void main() { \n"
+ " v_color = a_color; \n"
+ " tCoord = a_texCoords; \n"
+ " gl_Position = mvp * vec4(a_position, 1f); \n"
+ "}";
Thank you both.
Upvotes: 2