glGetUniformLocation returning -1(Solved)
I looked it up to see what the problem was.
GL_INVALID_VALUE is generated if program is not a value generated by OpenGL.
GL_INVALID_OPERATION is generated if program is not a program object.
GL_INVALID_OPERATION is generated if program has not been successfully linked.
GL_INVALID_OPERATION is generated if glGetUniformLocation is executed between the execution of glBegin and the corresponding execution of glEnd.
I call the function after all the steps so its not any of those errors, I don't have glBegin or glEnd in my program.
This function returns -1 if name does not correspond to an active uniform variable in program or if name starts with the reserved prefix "gl_".
This is how I called it
lightPosLoc = glGetUniformLocationARB(prog,"lightPos");
if(lightPosLoc != -1)
{
glUniform3fvARB(lightPosLoc,1,lightPos0);
}
else
{
MessageBox(NULL,"Did not find a location!?","WTF",MB_OK|MB_ICONINFORMATION);
}
This is the code for my shader
GLcharARB vShaderString[] =
"uniform vec3 lightPos;\n"
"void main()\n"
"{\n"
"gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
"vec3 N = normalize(gl_NormalMatrix * gl_Normal);\n"
"vec4 V = gl_ModelViewMatrix * gl_Vertex;\n"
"vec3 L = normalize(lightPos - V.xyz);\n"
"float NdotL = dot(N,L);\n"
"gl_FrontColor = gl_Color * vec4(max(0.0,NdotL));\n"
"}\n";
So lightPos is an active uniform variable but why is it still returning -1?
[Edited by - SirOnion on August 20, 2005 6:23:55 PM]
Are you 100% sure the GLSL program is compiled and linked without errors? If I remember correctly -1 is returned if the program isn't valid. I'd suggest checking the spec though, I may be misremembering.
Everything is compiled and linked correctly otherwise I have message boxes coming up to tell me what went wrong. And the only thing it says when it runs is that It Couldn't Find a Location which si the message box that will come up if after the call to glGetUniformLocation and the location is still -1;
Is the Program in use when checking the values?
If i remember correctly then you have to have called
glUseProgramObjectARB(prog)
before getUniform wil return correct values.
If i remember correctly then you have to have called
glUseProgramObjectARB(prog)
before getUniform wil return correct values.
OKay usually when I make these threads I find out I'm an idiot. When I was calling glLinkProgramARB, I was using the string that held the shader as the parameter and not the program object. Whoops. I didn't think that the actual program would compile if I did that. When the shader was compiled,linked,validated I called glGetObjectParameterARB and got the status of each one, and when I had it wrong it didn't tell me anything was wrong. But now it works, thanks for you're help guys.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement