struct SF::RenderStates
- SF::RenderStates
- Struct
- Value
- Object
Overview
Define the states used for drawing to a RenderTarget
There are four global states that can be applied to the drawn objects:
- the blend mode: how pixels of the object are blended with the background
- the transform: how the object is positioned/rotated/scaled
- the texture: what image is mapped to the object
- the shader: what custom effect is applied to the object
High-level objects such as sprites or text force some of these states when they are drawn. For example, a sprite will set its own texture, so that you don't have to care about it when drawing the sprite.
The transform is a special case: sprites, texts and shapes (and it's a good idea to do it with your own drawable classes too) combine their transform with the one that is passed in the RenderStates structure. So that you can use a "global" transform on top of each object's transform.
Most objects, especially high-level drawables, can be drawn directly without defining render states explicitly -- the default set of states is OK in most cases.
window.draw(sprite)
If you want to use a single specific render state, for example a
shader, you can pass it to the constructor of SF::RenderStates
.
window.draw(sprite, SF::RenderStates.new(shader))
When you're inside the draw
function of a drawable
object (one that includes SF::Drawable
), you can
either pass the render states unmodified, or change
some of them.
For example, a transformable object will combine the
current transform with its own transform. A sprite will
set its texture. Etc.
See also: SF::RenderTarget
, SF::Drawable
Defined in:
graphics/graphics.crgraphics/obj.cr
Constant Summary
-
Default =
new
-
Special instance holding the default render states
Constructors
-
.new(blend_mode : BlendMode, transform : Transform, texture : Texture | Nil, shader : Shader | Nil)
Construct a set of render states with all its attributes
-
.new(blend_mode : BlendMode)
Construct a default set of render states with a custom blend mode
-
.new(transform : Transform)
Construct a default set of render states with a custom transform
-
.new(texture : Texture | Nil)
Construct a default set of render states with a custom texture
-
.new(shader : Shader | Nil)
Construct a default set of render states with a custom shader
-
.new
Default constructor
Instance Method Summary
-
#blend_mode : BlendMode
Blending mode
- #blend_mode=(blend_mode : BlendMode)
-
#dup : RenderStates
Returns a shallow copy of this object.
- #inspect(io)
-
#shader : Shader | Nil
Shader
- #shader=(shader : Shader | Nil)
-
#texture : Texture | Nil
Texture
- #texture=(texture : Texture | Nil)
-
#transform : Transform
Transform
- #transform=(transform : Transform)
Constructor Detail
Construct a set of render states with all its attributes
- blend_mode - Blend mode to use
- transform - Transform to use
- texture - Texture to use
- shader - Shader to use
Construct a default set of render states with a custom blend mode
- blend_mode - Blend mode to use
Construct a default set of render states with a custom transform
- transform - Transform to use
Construct a default set of render states with a custom texture
- texture - Texture to use
Construct a default set of render states with a custom shader
- shader - Shader to use
Default constructor
Constructing a default set of render states is equivalent
to using SF::RenderStates::Default
.
The default set defines:
- the
BlendAlpha
blend mode - the identity transform
- a null texture
- a null shader
Instance Method Detail
Returns a shallow copy of this object.
Because Value
is a value type, this method returns self
,
which already involves a shallow copy of this object because
value types are passed by value.