GameKit  0.0.1a
C++ gamedev tools
Public Member Functions | Protected Member Functions | Friends | List of all members
gk::IDrawable Class Referenceabstract

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

#include <IDrawable.hpp>

Inheritance diagram for gk::IDrawable:
gk::ApplicationState gk::Image gk::RectangleShape gk::Scene gk::Text gk::TextInput gk::Tilemap gk::TilemapRenderer

Public Member Functions

virtual ~IDrawable ()=default
 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.

This part of the documentation has been taken from SFML. Once the migration to 2.6 is done, this file will be removed.

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

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

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

Example:

class MyDrawable : public gk::IDrawable {
public:
...
private:
void draw(gk::RenderTarget &target, gk::RenderStates states) const override {
// 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, GL_QUADS, 0, 16, states);
}
gk::Sprite m_sprite;
gk::Texture m_texture;
};
See also
gk::RenderTarget

Definition at line 25 of file IDrawable.hpp.

Constructor & Destructor Documentation

§ ~IDrawable()

virtual gk::IDrawable::~IDrawable ( )
virtualdefault

Virtual destructor.

Member Function Documentation

§ draw()

virtual void gk::IDrawable::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

Implemented in gk::ApplicationState, gk::Scene, gk::Text, gk::Image, gk::RectangleShape, gk::Tilemap, gk::TextInput, and gk::TilemapRenderer.

Friends And Related Function Documentation

§ RenderTarget

friend class RenderTarget
friend

Definition at line 34 of file IDrawable.hpp.


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