- 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);
- use
- imp: dont unbind EBO before VAO