title: Cant draw multiple objects in opengl
body: <p>I cant work out why the following code doesn't work, I am attempting to draw 2 shapes, a triangle that is coloured red and a cube that is multi coloured, by themselves they draw perfectly but if I try to draw both at once it gives weird bugs, I have tried changing lines around changing variable's modifying my shaders and I cant seem to get anywhere near the result I want, the current code ends up drawing 2 identical triangles that use the cubes colours.</p>
  
  <pre><code>GLuint VertexArrayID;
  
  glGenVertexArrays(1, &amp;VertexArrayID);
  glBindVertexArray(VertexArrayID);
  
  GLuint MatrixID = glGetUniformLocation(shader-&gt;id(), "MVP");
  
  glm::mat4 Projection = glm::perspective(45.0f, 4.0f / 3.0f, 0.1f, 100.0f);
  glm::mat4 View       = glm::lookAt(
  glm::vec3(4,2,2), // Camera location
  glm::vec3(0,0,0), // and looks at the origin
  glm::vec3(0,1,0)  // Head is up (set to 0,-1,0 to look upside-down)
  );
  
  glm::mat4 myMatrix = glm::translate(-2.f,0.f,0.f);
  glm::mat4 Model = glm::mat4(1.f);
  Model= myMatrix * Model;
  glm::mat4 MVP = Projection * View * Model;
  
  glm::mat4 myMatrix2 = glm::translate(2.f,0.f,0.f);
  glm::mat4 Model2 = glm::mat4(1.f);
  Model2= myMatrix2 * Model2;
  glm::mat4 MVP2 = Projection * View * Model2;
  
  glViewport(0, 0, windowWidth, windowHeight); // set viewport to the size of the window
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT  | GL_STENCIL_BUFFER_BIT);
  
  shader-&gt;bind();
  glUniformMatrix4fv(MatrixID, 1, GL_FALSE, &amp;MVP[0][0]);
  
  glEnableVertexAttribArray(0);
  glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
  glVertexAttribPointer(0,3,GL_FLOAT,GL_FALSE,0,(void*)0);
  
  glEnableVertexAttribArray(1);
  glBindBuffer(GL_ARRAY_BUFFER, colourBuffer);
  glVertexAttribPointer(1,3,GL_FLOAT,GL_FALSE,0,(void*)0);
  
  glDrawArrays(GL_TRIANGLES,0,12*3);
  
  glDisableVertexAttribArray(0);
  glDisableVertexAttribArray(1);
  
  glUniformMatrix4fv(MatrixID, 1, GL_FALSE, &amp;MVP2[0][0]);
  glEnableVertexAttribArray(0);
  glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer2);
  glVertexAttribPointer(0,3,GL_FLOAT,GL_FALSE,0,(void*)0);
  
  glEnableVertexAttribArray(1);
  glBindBuffer(GL_ARRAY_BUFFER, colourBuffer2);
  glVertexAttribPointer(1,3,GL_FLOAT,GL_FALSE,0,(void*)0);
  
  glDrawArrays(GL_TRIANGLES, 0, 3);
  glDisableVertexAttribArray(0);
  glDisableVertexAttribArray(1);
  
  SwapBuffers(hdc);
  
  glDeleteBuffers(1, &amp;vertexBuffer);
  glDeleteBuffers(1, &amp;vertexBuffer2);
  glDeleteBuffers(1, &amp;colourBuffer);
  glDeleteBuffers(1, &amp;colourBuffer2);
  shader-&gt;unbind();
  glDeleteVertexArrays(1, &amp;VertexArrayID);
  </code></pre>
  
  <p>that's the main code. I create all the buffers in a similar way by basically using variations of the following 3 lines to insert the different buffer names and data,</p>
  
  <pre><code>glGenBuffers(1, &amp;vertexBuffer);
  glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
  glBufferData(GL_ARRAY_BUFFER,sizeof(Cube), Cube, GL_STATIC_DRAW);
  </code></pre>
  
  <p>fragment shader</p>
  
  <pre><code>#version 330 core
  in vec3 fragmentColour;
  out vec3 colour;
  void main(){
  colour = fragmentColour;
  }
  </code></pre>
  
  <p>vertex shader</p>
  
  <pre><code>  #version 330 core
  
    uniform mat4 MVP;
  
    layout(location = 0) in vec3 vertexPosition_modelspace;
    layout(location = 1) in vec3 vertexColour;
    out vec3 fragmentColour;
  
     void main(){
  
      gl_Position =  MVP * vec4(vertexPosition_modelspace,1);
      fragmentColour = vertexColour;
     }
  </code></pre>