Game Development Reference
In-Depth Information
sf::RenderTarget and sf::RenderWindow
We are already familiar with the RenderWindow class, but we haven't covered it in de-
tail. One reason is that we don't need to know too much besides its RenderWin-
dow::draw() method to work with it in the early stages. However, now that we are go-
ing to talk about rendering on different targets (textures in this instance), it is important to
understand what RenderWindow is.
We will start with the introduction of the concept of a render target. A render target is an
object that we can use the graphics module to draw on. In order for a class to be considered
a render target, it has to inherit from sf::RenderTarget . The class provides the inter-
face needed in the child classes for drawing Drawable objects, using Views (or camer-
as), shaders, and so on. The RenderWindow class is one of those children classes.
The inheritance tree of the RenderWindow class looks like this:
From this, we can get an understanding of what the class represents—a way for us to draw
a Drawable object in a window. If we look at the base Window class we see no drawing
functionality in it, only window related properties—such as handling events, changing size,
title, position, and so on. In order to draw something in the base Window class, we have to
use OpenGL. However, every class that implements the RenderTarget methods can
serve as a canvas for all the features of the graphics module—most importantly the Draw-
able objects. And that is the reason why RenderTarget is so important—without the
functionality that the class provides, we cannot utilize most of the module's features.
Most of the RenderWindow methods we have talked about before are actually declared
in RenderTarget draw() , setView() , clear() , mapPixelToCoords() , and
so on. Some of those methods are implemented differently depending on RenderTar-
get , but most of them work in the same way. Before we go any further there is an import-
ant note which we have to mention about the RenderTarget::draw() method.
Search WWH ::




Custom Search