Drawing with vertex indices
One last thing that is quite important for us before moving on is covering a more efficient way of rendering shapes. Our current method is fine for rendering a single triangle, but it can get inefficient really quickly when rendering something more complex, like a cube. If we are using vertices only, it would require a grand total of 36 to render six cube faces. A much more efficient approach would obviously be submitting eight vertices for each corner of the cube and then reusing them to draw each face. Luckily, there is a way to do just that by using an index array.
Using indices simply means that for each model we are drawing, we also need to store an array of indices that represent the draw order of vertices. Each vertex in a model is given an index, starting from 0. An array of these indices would then be used to connect the vertices, instead of having to re-submit them. Let's implement this functionality, starting with the GL_Model
class:
class GL_Model {...