Using multiple UV sets in same VBO

I’m trying to define a mesh (using VBO) with 2 layers of textures using 2 sets of UVs coords, with the glVertexAttribPointer method:

...
glVertexAttribPointer(2, 2, GL_FLOAT, false, stride, offset);
glVertexAttribPointer(3, 2, GL_FLOAT, false, stride, offset + 8);

And then access it in the vertex shader with the following code:

#version 120
...
in vec2 texCoords1;
in vec2 texCoords2;

void main(void){
	...
	vTex1 = texCoords1;
	vTex2 = texCoords2;
}

but when I use the vTex2 variable i the Fragment shader, I always get a constant value (1,1), even though I set both values to be the same.

Is there anything I am missing?

Did you remember glEnableVertexAttribArray?

Also: if you’re actually using hard-coded constants for the attribute location, you need to specify that either with a layout(location=...) qualifier in the shader or with glBindAttribLocation (prior to linking) in the client.

Thanks for your quick answer,

Did you remember glEnableVertexAttribArray ?

yup, that did it.

but, as I am using version 120, isn’t the layout qualifier not valid? because I’ve tried and it’s not recognized.

Right. layout(location=...) needs GLSL 3.3, so you either need to use glBindAttribLocation to set the locations or allow the linker to assign them and use glGetAttribLocation to query them.