Skip to content

struct SF::RenderStates
inherits Struct #

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

Constants#

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

  • blend_mode - Blend mode to use
  • transform - Transform to use
  • texture - Texture to use
  • shader - Shader to use
View source

.new(blend_mode : BlendMode)#

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

  • blend_mode - Blend mode to use
View source

.new(transform : Transform)#

Construct a default set of render states with a custom transform

  • transform - Transform to use
View source

.new(texture : Texture | Nil)#

Construct a default set of render states with a custom texture

  • texture - Texture to use
View source

.new(shader : Shader | Nil)#

Construct a default set of render states with a custom shader

  • shader - Shader to use
View source

.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

Methods#

#blend_mode : BlendMode#

Blending mode

View source

#blend_mode=(blend_mode : BlendMode)#

View source

#dup : RenderStates#

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

#inspect(io)#

View source

#shader : Shader | ::Nil#

Shader

View source

#shader=(shader : Shader | Nil)#

View source

#texture : Texture | ::Nil#

Texture

View source

#texture=(texture : Texture | Nil)#

View source

#transform : Transform#

Transform

View source

#transform=(transform : Transform)#

View source