Struct sfml::graphics::RenderStates

source ·
#[repr(C)]
pub struct RenderStates<'texture, 'shader, 'shader_texture: 'shader> { pub blend_mode: BlendMode, pub transform: Transform, /* private fields */ }
Expand description

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);

To draw with a specific render state, use RenderTarget::draw_with_renderstates.

let mut states = RenderStates::default();
states.set_shader(Some(&shader));
window.draw_with_renderstates(&sprite, &states);

When you’re inside the draw function of a drawable object (implementing 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.

Fields§

§blend_mode: BlendMode

The blending mode

§transform: Transform

The transform

Implementations§

Create a new RenderStates.

Arguments
  • blend_mode - The BlendMode
  • transform - The transform
  • texture - Some(texture) if there is a texture, None otherwise
  • shader - Some(shader) if there is a shader, None otherwise

Return a new default RenderStates

Sets the texture

Sets the shader

The default render state.

This can be used in a const context, unlike the Default implementation.

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.