Back face culling
In order to save on performance, it is a good idea to let OpenGL know that we would like to cull faces that are not visible from the current perspective. This feature can be enabled like so:
Game::Game() ... {
...
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
...
}
After we glEnable
face culling, the glCullFace
function is invoked to let OpenGL know which faces to cull. This will work right out of the box, but we may notice weird artifacts like this if our model data is not set up correctly:
This is because the order our vertices are rendered in actually defines whether a face of a piece of geometry is facing inwards or outwards. For example, if the vertices of a face are rendered in a clockwise sequence, the face, by default, is considered to be facing inwards of the model and vice versa. Consider the following diagram:
Setting up the model draw order correctly allows us to save on performance by not drawing invisible faces, and having...