title: Duplicated vertices in opengl shader programs
body: <p>I am rendering two different objects to the screen using two rendering programs. Each program has it's own vertex and fragment shader associated with it.</p>
  
  <p>In the following code I am creating the first rendering program and using a GL_ARRAY_BUFFER to load the vertices into the shader:</p>
  
  <pre><code>boardRenderingProgram = compileBoardShaders();
  
  vector&lt;GLfloat&gt; boardVertices = board.getBorderVertices();
  GLfloat* borderVertices = &amp;boardVertices[0];
  
  GLuint numberOfVerts = boardVertices.size();
  
  GLuint anotherVBO;
  GLuint anotherBuffer;
  
  glGenVertexArrays(1, &amp;anotherVBO);
  glBindVertexArray(anotherVBO); 
  glGenBuffers(1, &amp;anotherBuffer);
  glBindBuffer(GL_ARRAY_BUFFER, anotherBuffer);
  
  glBufferData(GL_ARRAY_BUFFER, numberOfVerts*3*sizeof(GLfloat), NULL, GL_STATIC_DRAW);
  glBufferSubData(GL_ARRAY_BUFFER, 0, numberOfVerts*3*sizeof(GLfloat), borderVertices);
  
  vert = glGetAttribLocation(boardRenderingProgram, "vBoardPosition");
  glVertexAttribPointer(vert, 3, GL_FLOAT, GL_FALSE, 0, 0);   
  
  glEnableVertexAttribArray(vert);
  </code></pre>
  
  <p>Vertex shader for first program: </p>
  
  <pre><code>#version 330 core                           
  layout(location = 0) in vec4 vBoardPosition;    
  
  void main() {                               
      gl_Position = vBoardPosition;               
  }                                           
  </code></pre>
  
  <p>I then do exactly the same thing for the second rendering program, I am also setting a rotation and translation matrix in the second program:</p>
  
  <pre><code>renderingProgram = compileShaders();
  
  moveMatrix = glm::make_mat4(moveArray);
  
  currentBlockVertices = generator.getRandomBlock(blockNumber).getVertices();
  
  numberOfVertices = 8;
  
  GLfloat* vertices = &amp;currentBlockVertices[0];
  
  glGenVertexArrays(1, &amp;vertexArrayObject);
  glBindVertexArray(vertexArrayObject); 
  glGenBuffers(1, &amp;buffer);
  glBindBuffer(GL_ARRAY_BUFFER, buffer);
  
  glBufferData(GL_ARRAY_BUFFER, numberOfVertices*7*sizeof(GLfloat), NULL, GL_STATIC_DRAW);
  
  glBufferSubData(GL_ARRAY_BUFFER, 0, numberOfVertices*3*sizeof(GLfloat), vertices);
  
  
  vpos = glGetAttribLocation(renderingProgram, "vPosition"); 
  glVertexAttribPointer(vpos, 3, GL_FLOAT, GL_FALSE, 0, 0);   
  
  mpos = glGetUniformLocation(renderingProgram, "mMove");
  rpos = glGetUniformLocation(renderingProgram, "mRotate");
  
  glProgramUniformMatrix4fv(renderingProgram, mpos, 1, GL_FALSE, glm::value_ptr(moveMatrix));
  glProgramUniformMatrix4fv(renderingProgram, rpos, 1, GL_FALSE, glm::value_ptr(rotateMatrix));
  
  glEnableVertexAttribArray(vpos);
  </code></pre>
  
  <p>Vertex shader for second program:</p>
  
  <pre><code>#version 330 core                           
  layout(location = 0) in vec4 vPosition; 
  layout(location = 1) uniform mat4 mMove;    
  layout(location = 2) uniform mat4 mRotate;  
  
  void main() {                               
      gl_Position = mMove * mRotate * vPosition;      
  }                                           
  </code></pre>
  
  <p>Once these programs are created I use the following code in my render function to draw them to the screen:</p>
  
  <pre><code>glUseProgram(boardRenderingProgram);
  glDrawArrays(GL_POINTS, 0, 8);
  
  glUseProgram(renderingProgram);
  glDrawArrays(GL_LINE_LOOP, 0, 8);
  SwapBuffers(hDC_);
  </code></pre>
  
  <p>However, despite specifying different vertices to load into each rendering program, both rendering programs draw the same vertices to the screen. It also seems that the rendering program that is created second determines which vertices are used.</p>
  
  <p>I have tried adding additional glUseProgram() calls before and after the vertex and matrix attributes are set but this doesn't seem to help.</p>
  
  <p>Why are the two programs drawing the same vertices when I have loaded different vertices into each one?</p>