title: OpenGL - Color Layout Location Not Working
body: <p>So I have an array of Vertex objects, which look like this:</p>
  
  <pre><code>Vertex: {[0.0, 0.0], [1.0, 1.0, 1.0, 1.0], [0.0, 0.0]}
  Vertex: {[0.0, 512.0], [1.0, 1.0, 1.0, 1.0], [0.0, 1.0]}
  Vertex: {[512.0, 0.0], [1.0, 1.0, 1.0, 1.0], [1.0, 0.0]}
  Vertex: {[512.0, 512.0], [1.0, 1.0, 1.0, 1.0], [1.0, 1.0]}
  </code></pre>
  
  <p>Where it's organized like this:</p>
  
  <pre><code>{[X, Y], [R, G, B, A], [U, V]}
  </code></pre>
  
  <p>And I have a shader that accepts these as attributes;</p>
  
  <p>Sprite.vs:</p>
  
  <pre><code>#version 330 core
  layout (location = 0) in vec2 vertex; 
  layout (location = 1) in vec4 color;
  layout (location = 2) in vec2 texcoords;
  
  out vec4 SpriteColor;
  out vec2 TexCoords;
  
  uniform mat4 gProjection;
  
  void main()
  {
      SpriteColor = color;
      TexCoords = texcoords;
      gl_Position = gProjection * vec4(vertex, 0.0, 1.0);
  }
  </code></pre>
  
  <p>Sprite.fs:</p>
  
  <pre><code>#version 330 core
  
  in vec4 SpriteColor;
  in vec2 TexCoords;
  
  out vec4 color;
  
  uniform sampler2D gSpriteTexture;
  
  void main()
  {    
      color = SpriteColor * texture(gSpriteTexture, TexCoords);
  }
  </code></pre>
  
  <p>And here's how I'm attaching the attributes:</p>
  
  <pre><code>    FloatBuffer vertexBuf = BufferUtils.createFloatBuffer(vertices.length * Vertex.numFields());
      for (Vertex v : vertices) {
          vertexBuf.put(v.toFloatArray());
      }
      vertexBuf.flip();
  
      vao = glGenVertexArrays();
  
      int vbo = glGenBuffers();
  
      glBindBuffer(GL_ARRAY_BUFFER, vbo);
      glBufferData(GL_ARRAY_BUFFER, vertexBuf, GL_STATIC_DRAW);
  
      glBindVertexArray(vao);
  
      glEnableVertexAttribArray(0);
      glEnableVertexAttribArray(1);
      glEnableVertexAttribArray(2);
  
      glVertexAttribPointer(0, 2, GL_FLOAT, false, Vertex.stride(), 0);
      glVertexAttribPointer(1, 4, GL_FLOAT, false, Vertex.stride(), 8);
      glVertexAttribPointer(2, 2, GL_FLOAT, false, Vertex.stride(), 24);
  
      glDisableVertexAttribArray(0);
      glDisableVertexAttribArray(1);
      glDisableVertexAttribArray(2);
  
      glBindBuffer(GL_ARRAY_BUFFER, 0);
      glBindVertexArray(0);
  </code></pre>
  
  <p>Vertex.numFields is 8, and Vertex.stride() is 32.</p>
  
  <p>My draw function:</p>
  
  <pre><code>@Override
  public void draw(RenderTarget rt, RenderStates states) {
      ...
  
  
      texture.bind(COLOR_TEXTURE_UNIT);
  
      shader.enable();
  
      shader.setTextureUnit(COLOR_TEXTURE_UNIT_INDEX);
      shader.setProjection(getOrthoMatrix(rt.getView()));
  
      glBindVertexArray(vao);
  
      glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
      glBindVertexArray(0);
  
      ...
  }
  </code></pre>
  
  <p>I don't think the error is in here, though, as I didn't change the draw function from when it worked (when I was using a uniform variable for the sprite color)</p>
  
  <p>However, nothing is drawing here. What am I messing up?</p>
  
  <p>Even when I don't even use SpriteColor in my color output, it still outputs nothing.</p>