Search code examples
c++openglopengl-3

Why glGetAttribLocation returns same value for two different attribute?


i'm a beginner in OpenGL, and i write a vertex shader and do other things like compiling shader.

Vertex shader:

in vec4 vPosition;
in vec4 vColor;

out vec4 Color;

void main(void){
    gl_Position = vPosition;
    Color = vColor;
}

After i write this code in C++:

GLuint PositionID = glGetAttribLocation(SProgram, "vPosition");
GLuint ColorID = glGetAttribLocation(SProgram, "vColor");

cout << "vPosition location: " << PositionID << endl << "vColor location: " << ColorID << endl;

And result was pretty interesting, two same locations:

vPosition location: 4294967295
vColor location: 4294967295

What is why of that?


Solution

  • Actually the return type of glGetAttribLocation is not GLuint but GLint (which is signed).

    So 4294967295 it's indeed -1 which means that a problem occurred somewhere. Causes could be many:

    • program is invalid or incorrectly linked
    • attribute is not used
    • attribute name is invalid

    It's hard to tell the cause since we can't guess your code but the problem is somewhere else.