dsfml.graphics.drawable

$(U Drawable) is a very simple base interface that allows objects of derived classes to be drawn to a RenderTarget.

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

Note that inheriting from $(DRAWABLE_LINK) is not mandatory, but it allows this nice syntax window.draw(object) rather than object.draw(window), which is more consistent with other DSFML classes.

Members

Interfaces

Drawable
interface Drawable

Interface for objects that can be drawn to a render target.

Examples

1 class MyDrawable : Drawable
2 {
3 public:
4 
5    this()
6    {
7        m_sprite = Sprite();
8        m_texture = Texture();
9        m_vertices = VertexArray();
10 
11        // additional setup
12    }
13   ...
14 
15    void draw(RenderTarget target, RenderStates states) const
16    {
17        // You can draw other high-level objects
18        target.draw(m_sprite, states);
19 
20        // ... or use the low-level API
21        states.texture = m_texture;
22        target.draw(m_vertices, states);
23 
24        // ... or draw with OpenGL directly
25        glBegin(GL_QUADS);
26        ...
27        glEnd();
28    }
29 
30 private:
31    Sprite m_sprite;
32    Texture m_texture;
33    VertexArray m_vertices;
34 }

See Also

$(RENDERTARGET_LINK)

Meta