Why is glGetActiveUniform() misbehaving?

I just learned about glGetActiveUniform(), so naturally I introduced a uniform in my vertex shader

uniform int sup;

and in my code, I wrote


GLuint supUniformLocation = glGetUniformLocation(<program_ID>, "sup");
glUniform1i(supUniformLocation, 1);    // just in case being uninitialized messes things up
GLint supSize;
GLchar supName[100];
glGetActiveUniform(programID, supUniformLocation, sizeof(supName) - 1, NULL, &supSize, NULL, supName);
std::cout << supName << " " << supSize << std::endl;

All of this compiles fine, and spits out the following garbage:

supName: ╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠****╠╠╠╠╠╠╠╠, supSize: -858993460

I cannot figure out what is wrong. :confused:

Any errors returned by OpenGL ?
Is your uniform used in your shader or just declared ?

The return value of glGetUniformLocation() is GLint, not GLuint; the return value will be -1 if the name doesn’t identify an active uniform. But the index parameter to glGetActiveUniform() is GLuint, and

GL_INVALID_VALUE is generated if index is greater than or equal to the number of active uniform variables in program.

So you need to check that the location isn’t negative prior to casting.

The uniform variable will be eliminated by the compiler if its value isn’t required to compute the program’s outputs (this is why there’s a concept of “active” uniforms).

Silence and GClements: I used the uniform in the shader, and now it outputs the uniform name and size fine. Thanks!