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

Integrating the Renderer class

There is obviously no point in even having the Renderer class, if it is not going to be in its proper place or used at all. Since its only job is to draw things on screen with the correct effect being applied, a fitting place for it would be inside the Window class:

class Window{ 
public: 
  ... 
  Renderer* GetRenderer(); 
  ... 
private: 
  ... 
  Renderer m_renderer; 
}; 

Because outside classes rely on it as well, it is a good idea to provide a getter method for easy retrieval of this object.

Actually integrating it into the rest of the code is surprisingly easy. A good place to start is giving the Renderer access to the Window class like so:

Window::Window(...) : m_renderer(this, l_useShaders) { ... } 

The renderer also has hooks ...

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