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§
source§impl<'texture, 'shader, 'shader_texture> RenderStates<'texture, 'shader, 'shader_texture>
impl<'texture, 'shader, 'shader_texture> RenderStates<'texture, 'shader, 'shader_texture>
sourcepub fn new(
blend_mode: BlendMode,
transform: Transform,
texture: Option<&'texture Texture>,
shader: Option<&'shader Shader<'shader_texture>>
) -> Self
pub fn new(
blend_mode: BlendMode,
transform: Transform,
texture: Option<&'texture Texture>,
shader: Option<&'shader Shader<'shader_texture>>
) -> Self
Create a new RenderStates
.
Arguments
blend_mode
- TheBlendMode
- 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
sourcepub fn set_texture(&mut self, texture: Option<&'texture Texture>)
pub fn set_texture(&mut self, texture: Option<&'texture Texture>)
Sets the texture
sourcepub fn set_shader(&mut self, shader: Option<&'shader Shader<'shader_texture>>)
pub fn set_shader(&mut self, shader: Option<&'shader Shader<'shader_texture>>)
Sets the shader
Trait Implementations§
source§impl<'texture, 'shader, 'shader_texture: 'shader> Clone for RenderStates<'texture, 'shader, 'shader_texture>
impl<'texture, 'shader, 'shader_texture: 'shader> Clone for RenderStates<'texture, 'shader, 'shader_texture>
source§fn clone(&self) -> RenderStates<'texture, 'shader, 'shader_texture>
fn clone(&self) -> RenderStates<'texture, 'shader, 'shader_texture>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more