Public Member Functions | Protected Member Functions | Friends | List of all members
cpp3ds::Drawable Class Referenceabstract

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

#include <Drawable.hpp>

Inheritance diagram for cpp3ds::Drawable:
cpp3ds::Console cpp3ds::Shape cpp3ds::Sprite cpp3ds::Text cpp3ds::VertexArray cpp3ds::CircleShape cpp3ds::ConvexShape cpp3ds::RectangleShape

Public Member Functions

virtual ~Drawable ()
 Virtual destructor. More...
 

Protected Member Functions

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

Friends

class RenderTarget
 

Detailed Description

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

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

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

Note that inheriting from cpp3ds::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 cpp3ds::Drawable
{
public :
...
private :
virtual void draw(cpp3ds::RenderTarget& target, cpp3ds::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();
}
cpp3ds::Sprite m_sprite;
cpp3ds::Texture m_texture;
cpp3ds::VertexArray m_vertices;
};
See also
cpp3ds::RenderTarget

Definition at line 43 of file Drawable.hpp.

Constructor & Destructor Documentation

virtual cpp3ds::Drawable::~Drawable ( )
inlinevirtual

Virtual destructor.

Definition at line 51 of file Drawable.hpp.

Member Function Documentation

virtual void cpp3ds::Drawable::draw ( RenderTarget target,
RenderStates  states 
) const
protectedpure 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
targetRender target to draw to
statesCurrent render states

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