Jump to content
  • Advertisement
Sign in to follow this  
SirOnion

OpenGL glGetUniformLocation returning -1(Solved)

This topic is 4839 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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;

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!