Me and a friend of mine are doing some 3d-programming, and we're trying to get out a pointlight. We're are trying to access a uniform for our light's position in the vertex shader but it doesn't get found.
Here is some code:
GLuint program = LoadShaders(shaders);
glUseProgram(program);
rotationLoc = glGetUniformLocation(program,"vRotationMatrix");
if(rotationLoc != -1)
glUniformMatrix4fv(rotationLoc,1,GL_TRUE,&world.rotationMatrix[0][0]);
LightLoc = glGetUniformLocation(program, "vLightPos");
if (LightLoc != -1)
glUniform3fv(LightLoc, 1, LightPos);
As you can see we do the same thing for our rotation matrix first. It works for the rotation matrix, while it doesn't for LightLoc. The error line is: LightLoc = glGetUniformLocation(program, "vLightPos"); LightLoc returns -1, but it should return 2.
Our vertex shader looks (partially) like this:
uniform mat4 vRotationMatrix;
uniform vec3 vLightPos;
void main()
{
color = vColor;
oTexCoord = vTexCoord;
gl_Position = vRotationMatrix * vPosition;
lightPos = vLightPos;
}
Try to output the result of the shader compilation using the code under the comment check vertex shader:
Maybe there are any warnings or errors. The same you can use for the fragment shader compilation