SFML 2.5.1

- Main Page
- Related Pages
- Topics
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | Protected Member Functions | Friends | List of all members
sf::Drawable Class Referenceabstract
Graphics module

Abstract base class for objects that can be drawn to a render target. More...

`#include <Drawable.hpp>`

Inheritance diagram for sf::Drawable:

## Public Member Functions

virtual | ~Drawable ()
| Virtual destructor.

## Protected Member Functions

virtual void | draw (RenderTarget &target, RenderStates states) const =0
| Draw the object to a render target.

## Friends

class | RenderTarget

## Detailed Description

Abstract base class for objects that can be drawn to a render target.

sf::Drawable is a very simple base class that allows objects of derived classes to be drawn to a sf::RenderTarget.

All you have to do in your derived class is to override the draw virtual function.

Note that inheriting from sf::Drawable is not mandatory, but it allows this nice syntax "window.draw(object)" rather than "object.draw(window)", which is more consistent with other SFML classes.

Example:

class MyDrawable : public sf::Drawable
{
public:
...
private:
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const
{
// You can draw other high-level objects
target.draw(m_sprite, states);
// ... or use the low-level API
states.texture = &m_texture;
target.draw(m_vertices, states);
// ... or draw with OpenGL directly
glBegin(GL_QUADS);
...
glEnd();
}
sf::Sprite m_sprite;
sf::Texture m_texture;
sf::VertexArray m_vertices;
};
sf::Drawable
Abstract base class for objects that can be drawn to a render target.
Definition Drawable.hpp:45
sf::RenderStates
Define the states used for drawing to a RenderTarget.
Definition RenderStates.hpp:46
sf::RenderStates::texture
const Texture * texture
Texture.
Definition RenderStates.hpp:117
sf::RenderTarget
Base class for all render targets (window, texture, ...)
Definition RenderTarget.hpp:53
sf::RenderTarget::draw
void draw(const Drawable &drawable, const RenderStates &states=RenderStates::Default)
Draw a drawable object to the render target.
sf::Sprite
Drawable representation of a texture, with its own transformations, color, etc.
Definition Sprite.hpp:48
sf::Texture
Image living on the graphics card that can be used for drawing.
Definition Texture.hpp:49
sf::VertexArray
Define a set of one or more 2D primitives.
Definition VertexArray.hpp:46

See also
  sf::RenderTarget

Definition at line 44 of file Drawable.hpp.

## Constructor & Destructor Documentation

## ◆ ~Drawable()

virtual sf::Drawable::~Drawable | ( |  | ) |

inline virtual

Virtual destructor.

Definition at line 52 of file Drawable.hpp.

## Member Function Documentation

## ◆ draw()

virtual void sf::Drawable::draw | ( | RenderTarget & | target,
|  | RenderStates | states ) const

protected pure virtual

Draw the object to a render target.

This is a pure virtual function that has to be implemented by the derived class to define how the drawable should be drawn.

Parameters

  target | Render target to draw to
  states | Current render states

## Friends And Related Symbol Documentation

## ◆ RenderTarget

friend class RenderTarget

friend

Definition at line 56 of file Drawable.hpp.

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

- Drawable.hpp