Jump to content
  • Advertisement
Sign in to follow this  
darrenc182

GLSL glGetUniformLocationARB Returns -1

This topic is 3740 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'm working on a tool and a section of my code that is used for game world previewing generates an invalid return value when I call glGetUniformLocation. The return value that I get is -1, which from what I understand means that the function could not find the value for the uniform I'm looking for or that the uniform I am looking for is not used inside of the shader. That would be perfect if it were true that uniform could not be found, but I can see it very well in my vertex shader and it is in use in the shader. Also to make sure that the correct shader is being loaded I checked my debug data to make sure that the uniform was being loaded at runtime. The correct shaders are being loaded and the debug data shows that the uniform is in there and is correct. Below I have some code snippets: Vertex Shader Code:
uniform vec3 Light, Eye;

void main()
{
	// Unnormalized vector to light.
	vec3 L = Light - gl_Vertex.xyz;

	// Unnormalized vector to eye.
	vec3 V = Eye - gl_Vertex.xyz;

Application Code:
shader->TurnOn();
lightPosID = shader->GetVariable("Light");
shader->SetFloat3(lightPosID, vPosition.x, vPosition.y, vPosition.z);

The shader class used in the above code has been used in other applications and should work fine, however I will test this to see if it is in fact true. If my question is not clear right now, it is that I would like to know why I am getting a -1 return value from the glUniformLocation function. If anyone knows why this might be the case, I will get very grateful. Thank you in advance for any and all help.

Share this post


Link to post
Share on other sites
Advertisement
Make sure that the current shader is actually used : glUseProgram(yourShaderID).
Then glGetUniformLoc.

You also need to make sure that your shader compiles, which it looks like your shader probably isnt compiling unless you have more to it that u omitted.

Share this post


Link to post
Share on other sites
I found some errors and here they are:

(31) : error C0000: syntax error, unexpected $undefined at token "<undefined>"
(31) : error C0501: type name expected at token "<undefined>"

I have no idea what these mean. Does anyone know what they might mean? They came from the vertex shader.

Also I checked the validity of the vertex shader in GLSL Validation and everything seems to be fine with the shader so the problem must be with the application itself.

I think I should also mention that I'm using MFC for my application

Share this post


Link to post
Share on other sites
Alright I got it working. The problem I believe was my OpenGL device context. I was not using the correct one. Thank you to everyone that posted to help me with this issue.

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!