Skip to content

Latest commit

 

History

History
23 lines (21 loc) · 681 Bytes

3.3 Hello_Triangle_pt3.md

File metadata and controls

23 lines (21 loc) · 681 Bytes
  • lets draw rectangle:)
  • rectangle = 2 triangles = 6 vertices
  • problem : total 4 unique vertices but 2 repeating
  • solution : lets store only unique vertices and specify indices of vertices for each triangle
GLfloat indices[] = {
0, 1, 3, // first triangle
1, 2, 3 // second triangle
};

Element buffer Object serves this feature

  • create VAO VBO EBO
  • bind VAO
  • bind VBO,EBO
  • add data to VBO, EBO
  • now use VAO to draw triangles!
  • while drawing:
    • use glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
    • instead glDrawArrays(GL_TRIANGLES, 0, 6);
  • imp: dont unbind EBO before VAO