When I use line [1], the color is transmitted rigth to the fragment shader, but when I change the color to the attribute acolor (using the line [2]) the positions of the triangles appear wrong. From the data of the main program, it seems to me like the positions get the color values.

I put two images, 1 with the rigth vertex positions and 2 with the wrong vertex positions.

1 Answer
1

Check your glBindAttribLocation calls - you'll probably find that one of two things are happening; either (1) you're not doing any such calls and therefore GL is assigning it's own arbitrary attrib locations which are mismatching those used in your glVertexAttribPointer calls, or (2) you have specified a mismatch yourself.

Either way, the recommended approach would be to use "layout(location=" syntax in your vertex shader, which will make this kind of ambiguity go away.

Thanks, I'm using layout + location syntax in the 3.30 version of the shader, but with 1.20 it's not available. I assumed that attributes were listed the same order that source code declarations. WRONG, I addded glBindAttribLocation and now it works.
–
ZhenFeb 5 '13 at 17:36

1

You should also check for GL_ARB_explicit_attrib_location which would allow you to use layout(location= with older GL_VERSIONs, and which in practice will work on any GL2.1 hardware for which a reasonably up to date driver is available. On the other hand you may prefer to not have a third shader variation, but that should be manageable with some #defines.
–
Darth SatanFeb 6 '13 at 0:56