Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have the following vertex shader:

#version 120

attribute vec4 position;
attribute vec4 acolor;

varying vec4 theColor;

void main(){
    gl_Position = position;
    //theColor = acolor;  //[1]
    theColor = vec4(1.0,0.0,0.0,1.0); //[2]

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.

enter image description here enter image description here

UPDATE: render code on Github

share|improve this question
up vote 2 down vote accepted

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.

share|improve this answer
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. – Zhen Feb 5 '13 at 17:36
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. – Le Comte du Merde-fou Feb 6 '13 at 0:56

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.