sf::RenderTarget Class Reference

Base class for all render targets (window, image, . More...

#include <RenderTarget.hpp>

Inheritance diagram for sf::RenderTarget:
sf::NonCopyable sf::RenderImage sf::RenderWindow

List of all members.

Public Member Functions

virtual ~RenderTarget ()
 Destructor.
void Clear (const Color &color=Color(0, 0, 0))
 Clear the entire target with a single color.
void Draw (const Drawable &object)
 Draw an object into the target.
void Draw (const Drawable &object, const Shader &shader)
 Draw an object into the target with a shader.
virtual unsigned int GetWidth () const =0
 Return the width of the rendering region of the target.
virtual unsigned int GetHeight () const =0
 Return the height of the rendering region of the target.
void SetView (const View &view)
 Change the current active view.
const ViewGetView () const
 Retrieve the view currently in use in the render target.
const ViewGetDefaultView () const
 Get the default view of the render target.
IntRect GetViewport (const View &view) const
 Get the viewport of a view, applied to this render target.
Vector2f ConvertCoords (unsigned int x, unsigned int y) const
 Convert a point from target coordinates to view coordinates.
Vector2f ConvertCoords (unsigned int x, unsigned int y, const View &view) const
 Convert a point from target coordinates to view coordinates.
void SaveGLStates ()
 Save the current OpenGL render states and matrices.
void RestoreGLStates ()
 Restore the previously saved OpenGL render states and matrices.

Protected Member Functions

 RenderTarget ()
 Default constructor.
void Initialize ()
 Performs the common initialization step after creation.

Detailed Description

Base class for all render targets (window, image, .

sf::RenderTarget defines the common behaviour of all the 2D render targets usable in the graphics module.

..)

It makes it possible to draw 2D entities like sprites, shapes, text without using any OpenGL command directly.

A sf::RenderTarget is also able to use views (sf::View), which are a kind of 2D cameras. With views you can globally scroll, rotate or zoom everything that is drawn, without having to transform every single entity. See the documentation of sf::View for more details and sample pieces of code about this class.

On top of that, render targets are still able to render direct OpenGL stuff. It is even possible to mix together OpenGL calls and regular SFML drawing commands. When doing so, make sure that OpenGL states are not messed up by calling the SaveGLStates / RestoreGLStates functions.

See also:
sf::RenderWindow, sf::RenderImage, sf::View

Definition at line 47 of file RenderTarget.hpp.


Constructor & Destructor Documentation

sf::RenderTarget::~RenderTarget (  )  [virtual]

Destructor.

Definition at line 50 of file RenderTarget.cpp.

sf::RenderTarget::RenderTarget (  )  [protected]

Default constructor.

Definition at line 40 of file RenderTarget.cpp.


Member Function Documentation

void sf::RenderTarget::Clear ( const Color color = Color(0, 0, 0)  ) 

Clear the entire target with a single color.

This function is usually called once every frame, to clear the previous contents of the target.

Parameters:
color Fill color to use to clear the render target

Definition at line 57 of file RenderTarget.cpp.

Vector2f sf::RenderTarget::ConvertCoords ( unsigned int  x,
unsigned int  y,
const View view 
) const

Convert a point from target coordinates to view coordinates.

Initially, a unit of the 2D world matches a pixel of the render target. But if you define a custom view, this assertion is not true anymore, ie. a point located at (10, 50) in your render target (for example a window) may map to the point (150, 75) in your 2D world -- for example if the view is translated by (140, 25).

For render windows, this function is typically used to find which point (or object) is located below the mouse cursor.

This version uses a custom view for calculations, see the other overload of the function to use the current view of the render target.

Parameters:
x X coordinate of the point to convert, relative to the render target
y Y coordinate of the point to convert, relative to the render target
view The view to use for converting the point
Returns:
The converted point, in "world" units

Definition at line 169 of file RenderTarget.cpp.

Vector2f sf::RenderTarget::ConvertCoords ( unsigned int  x,
unsigned int  y 
) const

Convert a point from target coordinates to view coordinates.

Initially, a unit of the 2D world matches a pixel of the render target. But if you define a custom view, this assertion is not true anymore, ie. a point located at (10, 50) in your render target (for example a window) may map to the point (150, 75) in your 2D world -- for example if the view is translated by (140, 25).

For render windows, this function is typically used to find which point (or object) is located below the mouse cursor.

This version uses the current view of the render target. See the other overload to specify a custom view.

Parameters:
x X coordinate of the point to convert, relative to the render target
y Y coordinate of the point to convert, relative to the render target
Returns:
The converted point, in "world" units

Definition at line 162 of file RenderTarget.cpp.

void sf::RenderTarget::Draw ( const Drawable object,
const Shader shader 
)

Draw an object into the target with a shader.

This function draws anything that inherits from the sf::Drawable base class (sf::Sprite, sf::Shape, sf::Text, or even your own derived classes). The shader alters the way that the pixels are processed right before being written to the render target.

Parameters:
object Object to draw
shader Shader to use for drawing the object

Definition at line 95 of file RenderTarget.cpp.

void sf::RenderTarget::Draw ( const Drawable object  ) 

Draw an object into the target.

This function draws anything that inherits from the sf::Drawable base class (sf::Sprite, sf::Shape, sf::Text, or even your own derived classes).

Parameters:
object Object to draw

Definition at line 65 of file RenderTarget.cpp.

const View & sf::RenderTarget::GetDefaultView (  )  const

Get the default view of the render target.

The default view has the initial size of the render target, and never changes after the target has been created.

Returns:
The default view of the render target
See also:
SetView, GetView

Definition at line 141 of file RenderTarget.cpp.

virtual unsigned int sf::RenderTarget::GetHeight (  )  const [pure virtual]

Return the height of the rendering region of the target.

Returns:
Height in pixels
See also:
GetWidth

Implemented in sf::RenderImage, and sf::RenderWindow.

const View & sf::RenderTarget::GetView (  )  const

Retrieve the view currently in use in the render target.

Returns:
The view object that is currently used
See also:
SetView, GetDefaultView

Definition at line 134 of file RenderTarget.cpp.

IntRect sf::RenderTarget::GetViewport ( const View view  )  const

Get the viewport of a view, applied to this render target.

The viewport is defined in the view as a ratio, this function simply applies this ratio to the current dimensions of the render target to calculate the pixels rectangle that the viewport actually covers in the target.

Parameters:
view The view for which we want to compute the viewport
Returns:
Viewport rectangle, expressed in pixels

Definition at line 148 of file RenderTarget.cpp.

virtual unsigned int sf::RenderTarget::GetWidth (  )  const [pure virtual]

Return the width of the rendering region of the target.

Returns:
Width in pixels
See also:
GetHeight

Implemented in sf::RenderImage, and sf::RenderWindow.

void sf::RenderTarget::Initialize (  )  [protected]

Performs the common initialization step after creation.

The derived classes must call this function after the target is created and ready for drawing.

Definition at line 212 of file RenderTarget.cpp.

void sf::RenderTarget::RestoreGLStates (  ) 

Restore the previously saved OpenGL render states and matrices.

See the description of SaveGLStates to get a detailed description of these functions.

See also:
SaveGLStates

Definition at line 198 of file RenderTarget.cpp.

void sf::RenderTarget::SaveGLStates (  ) 

Save the current OpenGL render states and matrices.

This function can be used when you mix SFML drawing and direct OpenGL rendering. Combined with RestoreGLStates, it ensures that:

  • SFML's internal states are not messed up by your OpenGL code
  • your OpenGL states are not modified by a call to a SFML function

More specifically, it must be used around code that calls Draw functions. Example: OpenGL code here... window.SaveGLStates(); window.Draw(...); window.Draw(...); window.RestoreGLStates(); OpenGL code here...

Note that this function is quite expensive and should be used wisely. It is provided for convenience, and the best results will be achieved if you handle OpenGL states yourself (because you really know which states have really changed, and need to be saved / restored).

See also:
RestoreGLStates

Definition at line 183 of file RenderTarget.cpp.

void sf::RenderTarget::SetView ( const View view  ) 

Change the current active view.

The new view will affect everything that is drawn, until another view is activated. The render target keeps its own copy of the view object, so it is not necessary to keep the original one alive as long as it is in use. To restore the original view of the target, you can pass the result of GetDefaultView() to this function.

Parameters:
view New view to use
See also:
GetView, GetDefaultView

Definition at line 125 of file RenderTarget.cpp.


The documentation for this class was generated from the following files: