struct SF::RenderStates

Overview

Define the states used for drawing to a RenderTarget

There are four global states that can be applied to the drawn objects:

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.cr
graphics/obj.cr

Constant Summary

Default = new

Special instance holding the default render states

Constructors

Instance Method Summary

Constructor Detail

def self.new(blend_mode : BlendMode, transform : Transform, texture : Texture | Nil, shader : Shader | Nil) #

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

[View source]
def self.new(blend_mode : BlendMode) #

Construct a default set of render states with a custom blend mode

  • blend_mode - Blend mode to use

[View source]
def self.new(transform : Transform) #

Construct a default set of render states with a custom transform

  • transform - Transform to use

[View source]
def self.new(texture : Texture | Nil) #

Construct a default set of render states with a custom texture

  • texture - Texture to use

[View source]
def self.new(shader : Shader | Nil) #

Construct a default set of render states with a custom shader

  • shader - Shader to use

[View source]
def self.new #

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

[View source]

Instance Method Detail

def blend_mode : BlendMode #

Blending mode


[View source]
def blend_mode=(blend_mode : BlendMode) #

[View source]
def dup : RenderStates #
Description copied from struct Value

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.


[View source]
def inspect(io) #

[View source]
def shader : Shader | Nil #

Shader


[View source]
def shader=(shader : Shader | Nil) #

[View source]
def texture : Texture | Nil #

Texture


[View source]
def texture=(texture : Texture | Nil) #

[View source]
def transform : Transform #

Transform


[View source]
def transform=(transform : Transform) #

[View source]