Interface for objects that can be drawn to a render target.
class MyDrawable : Drawable { public: this() { m_sprite = Sprite(); m_texture = Texture(); m_vertices = VertexArray(); // additional setup } ... void draw(RenderTarget target, 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(); } private: Sprite m_sprite; Texture m_texture; VertexArray m_vertices; }
$(RENDERTARGET_LINK)
$(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.