[][src]Struct sfml::graphics::RenderStates

pub struct RenderStates<'texture, 'shader, 'shader_texture: 'shader> {
    pub blend_mode: BlendMode,
    pub transform: Transform,
    pub texture: Option<&'texture Texture>,
    pub shader: Option<&'shader Shader<'shader_texture>>,
}

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.

This example is not tested
window.draw(sprite);

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

let mut states = RenderStates::default();
states.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

Blending mode.

transform: Transform

Transform

texture: Option<&'texture Texture>

Texture

shader: Option<&'shader Shader<'shader_texture>>

Shader

Methods

impl<'texture, 'shader, 'shader_texture> RenderStates<'texture, 'shader, 'shader_texture>[src]

pub fn new(
    blend_mode: BlendMode,
    transform: Transform,
    texture: Option<&'texture Texture>,
    shader: Option<&'shader Shader<'shader_texture>>
) -> Self
[src]

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

Trait Implementations

impl<'texture, 'shader, 'shader_texture: 'shader> Clone for RenderStates<'texture, 'shader, 'shader_texture>[src]

impl<'texture, 'shader, 'shader_texture: 'shader> Copy for RenderStates<'texture, 'shader, 'shader_texture>[src]

impl<'texture, 'shader, 'shader_texture: 'shader> Default for RenderStates<'texture, 'shader, 'shader_texture>[src]

impl<'texture, 'shader, 'shader_texture: 'shader> Debug for RenderStates<'texture, 'shader, 'shader_texture>[src]

Auto Trait Implementations

impl<'texture, 'shader, 'shader_texture> !Send for RenderStates<'texture, 'shader, 'shader_texture>

impl<'texture, 'shader, 'shader_texture> !Sync for RenderStates<'texture, 'shader, 'shader_texture>

impl<'texture, 'shader, 'shader_texture> Unpin for RenderStates<'texture, 'shader, 'shader_texture> where
    'shader_texture: 'shader, 

impl<'texture, 'shader, 'shader_texture> UnwindSafe for RenderStates<'texture, 'shader, 'shader_texture>

impl<'texture, 'shader, 'shader_texture> RefUnwindSafe for RenderStates<'texture, 'shader, 'shader_texture>

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]