module SF::Drawable
Overview
Abstract module for objects that can be drawn to a render target
SF::Drawable
is a very simple module that allows objects
of derived classes to be drawn to a SF::RenderTarget
.
All you have to do in your derived class is to implement the
#draw
function.
Note that including 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
include SF::Drawable
def draw(target : SF::RenderTarget, states : SF::RenderStates)
# You can draw other high-level objects
target.draw(@sprite, states)
# ... or use the low-level API
states.texture = @texture
target.draw(@vertices, states)
# ... or draw with OpenGL directly
glBegin(GL_QUADS)
# [...]
glEnd()
end
@sprite : SF::Sprite
@texture : SF::Texture
@vertices : SF::VertexArray
end
See also: SF::RenderTarget
Direct including types
Defined in:
graphics/graphics.crgraphics/obj.cr
Instance Method Summary
-
#draw(target : RenderTarget, states : RenderStates)
Draw the object to a render target.
Instance Method Detail
Draw the object to a render target.
This is an abstract method that has to be implemented by the including class to define how the drawable should be drawn.
- target - Render target to draw to
- states - Current render states