O'Reilly logo

Mastering SFML Game Development by Raimondas Pupius

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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:

Back face culling

This is because the order our vertices are rendered in actually defines whether a face of a piece of geometry is facing ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required