[][src]Struct sfml::graphics::blend_mode::BlendMode

#[repr(C)]
pub struct BlendMode {
    pub color_src_factor: Factor,
    pub color_dst_factor: Factor,
    pub color_equation: Equation,
    pub alpha_src_factor: Factor,
    pub alpha_dst_factor: Factor,
    pub alpha_equation: Equation,
}

Blending modes for drawing.

BlendMode is a type that represents a blend mode.

A blend mode determines how the colors of an object you draw are mixed with the colors that are already in the buffer.

The type is composed of 6 components, each of which has its own public field:

  • Color Source Factor (color_src_factor)
  • Color Destination Factor (color_dst_factor)
  • Color Blend Equation (color_equation)
  • Alpha Source Factor (alpha_src_factor)
  • Alpha Destination Factor (alpha_dst_factor)
  • Alpha Blend Equation (alpha_equation)

The source factor specifies how the pixel you are drawing contributes to the final color. The destination factor specifies how the pixel already drawn in the buffer contributes to the final color.

The color channels RGB (red, green, blue; simply referred to as color) and A (alpha; the transparency) can be treated separately. This separation can be useful for specific blend modes, but most often you won't need it and will simply treat the color as a single unit.

The blend factors and equations correspond to their OpenGL equivalents. In general, the color of the resulting pixel is calculated according to the following formula (src is the color of the source pixel, dst the color of the destination pixel, the other variables correspond to the public members, with the equations being + or - operators):

This example is not tested
dst.rgb = color_src_factor * src.rgb (color_equation) color_dst_factor * dst.rgb
dst.a   = alpha_src_factor * src.a   (alpha_equation) alpha_dst_factor * dst.a

All factors and colors are represented as floating point numbers between 0 and 1. Where necessary, the result is clamped to fit in that range.

In SFML, a blend mode can be specified every time you draw a Drawable object to a render target. It is part of the RenderStates compound that is passed to RenderTarget::draw.

Fields

color_src_factor: Factor

Source blending factor for the color channels.

color_dst_factor: Factor

Destination blending factor for the color channels.

color_equation: Equation

Blending equation for the color channels.

alpha_src_factor: Factor

Source blending factor for the alpha channel.

alpha_dst_factor: Factor

Destination blending factor for the alpha channel.

alpha_equation: Equation

Blending equation for the alpha channel.

Methods

impl BlendMode[src]

pub fn new(
    col_src: Factor,
    col_dst: Factor,
    col_equ: Equation,
    alpha_src: Factor,
    alpha_dst: Factor,
    alpha_equ: Equation
) -> Self
[src]

Create a new BlendMode

pub const ALPHA: BlendMode[src]

"Alpha" blend mode

pub const ADD: BlendMode[src]

"Add" blend mode

pub const MULTIPLY: BlendMode[src]

"Multiply" blend mode

pub const NONE: BlendMode[src]

"None" blend mode

Trait Implementations

impl Clone for BlendMode[src]

impl Copy for BlendMode[src]

impl Default for BlendMode[src]

fn default() -> Self[src]

Default blending mode is alpha blending.

impl Eq for BlendMode[src]

impl PartialEq<BlendMode> for BlendMode[src]

impl Debug for BlendMode[src]

Auto Trait Implementations

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]