Book Image

Mastering SFML Game Development

By : Raimondas Pupius
Book Image

Mastering SFML Game Development

By: Raimondas Pupius

Overview of this book

SFML is a cross-platform software development library written in C++ with bindings available for many programming languages. It provides a simple interface to the various components of your PC, to ease the development of games and multimedia applications. This book will help you become an expert of SFML by using all of its features to its full potential. It begins by going over some of the foundational code necessary in order to make our RPG project run. By the end of chapter 3, we will have successfully picked up and deployed a fast and efficient particle system that makes the game look much more ‘alive’. Throughout the next couple of chapters, you will be successfully editing the game maps with ease, all thanks to the custom tools we’re going to be building. From this point on, it’s all about making the game look good. After being introduced to the use of shaders and raw OpenGL, you will be guided through implementing dynamic scene lighting, the use of normal and specular maps, and dynamic soft shadows. However, no project is complete without being optimized first. The very last chapter will wrap up our project by making it lightning fast and efficient.
Table of Contents (17 chapters)
Mastering SFML Game Development
Credits
About the Author
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface

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...