Reputation: 1
I am using the code found here essentially unmodified. All the other tutorials on this site have worked for me. When I try to run this, however, I end up getting nothing but a cornflower screen.
After a little digging, I found (using trace debugging with println) that all the calls to glGetUniformLocation (starting at line 248) are returning negative one. Given that this is a reasonably professional tutorial hosted on the LWJGL site, and that I copied it unmodified (aside from some hard-coded filepaths which I changed) I get the feeling it might have something to do with my openGL version, my graphics card, or something similarly arcane.
After looking up specifics on glGetUniformLocation, I found it can return negative one if you ask for a Uniform that doesn't exist or that is of the wrong type. To show that this is not my problem, I will reproduce both the GLSL code and the invocations to glGetUniformLocation here:
#version 150 core
uniform mat4 projectionMatrix;
uniform mat4 viewMatrix;
uniform mat4 modelMatrix;
in vec4 in_Position;
in vec4 in_Color;
in vec2 in_TextureCoord;
out vec4 pass_Color;
out vec2 pass_TextureCoord;
void main(void) {
gl_Position = in_Position;
// Override gl_Position with our new calculated position
gl_Position = projectionMatrix * viewMatrix * modelMatrix * in_Position;
pass_Color = in_Color;
pass_TextureCoord = in_TextureCoord;
}
And the invocations:
projectionMatrixLocation = GL20.glGetUniformLocation(pId, "projectionMatrix");
viewMatrixLocation = GL20.glGetUniformLocation(pId, "viewMatrix");
modelMatrixLocation = GL20.glGetUniformLocation(pId, "modelMatrix");
System.out.println(pId+", "+projectionMatrixLocation+", "+
viewMatrixLocation+", "+modelMatrixLocation);
What am I missing?
Upvotes: 0
Views: 1450
Reputation: 4137
Consider querying your shader for all uniform data so you can easily see what uniforms are active. It's the only reliable way to know for sure. I do this for attributes and uniforms building an internal map in my shader class that is used to verify all interactions with the shader (can be disabled).
To get the number of active uniforms :
GLint uniforms;
glGetProgramiv(programRef, GL_ACTIVE_UNIFORMS, &uniforms);
For each uniform, get the name and datatype by calling glGetActiveUniform
.
This is also covered in : How can I find a list of all the uniforms in OpenGL es 2.0 vertex shader pro
Upvotes: 0