Declare vertex inputs with layout(location = 0) in
Declare vertex inputs with layout(location = 0) in so the shader fixes attribute locations itself, available in GLSL 3.30 and OpenGL 3.3.
Without a layout qualifier, the linker picks attribute locations and you must ask for them with glGetAttribLocation. Writing the location in the shader makes the C side a constant.
#version 330 core
layout(location = 0) in vec3 a_pos;
layout(location = 1) in vec2 a_uv;
layout(location = 2) in vec3 a_normal;
out vec2 v_uv;
uniform mat4 u_mvp;
void main() {
v_uv = a_uv;
gl_Position = u_mvp * vec4(a_pos, 1.0);
}glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 32, (void *)0);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 32, (void *)12);
glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 32, (void *)20);The layout(location = N) form for vertex inputs is core in GLSL 3.30, which OpenGL 3.3 uses, as the GLSL specification defines. Older versions need the extension ARB_explicit_attrib_location. A mat4 input takes four consecutive locations, so the next input after it must skip three numbers.
Two inputs sharing a location is a link error, which is better than the silent mix-up of automatic assignment.