Struct sfml::graphics::BlendMode

source ·
#[repr(C)]
pub struct BlendMode { pub color_src_factor: BlendFactor, pub color_dst_factor: BlendFactor, pub color_equation: BlendEquation, pub alpha_src_factor: BlendFactor, pub alpha_dst_factor: BlendFactor, pub alpha_equation: BlendEquation, }
Expand description

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

  • Color Source Factor
  • Color Destination Factor
  • Color Blend Equation
  • Alpha Source Factor
  • Alpha Destination Factor
  • Alpha Blend 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):

dst.rgb = colorSrcFactor * src.rgb (colorEquation) colorDstFactor * dst.rgb
dst.a   = alphaSrcFactor * src.a   (alphaEquation) alphaDstFactor * 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: BlendFactor

Source blending factor for the color channels

§color_dst_factor: BlendFactor

Destination blending factor for the color channels

§color_equation: BlendEquation

Blending equation for the color channels

§alpha_src_factor: BlendFactor

Source blending factor for the alpha channel

§alpha_dst_factor: BlendFactor

Destination blending factor for the alpha channel

§alpha_equation: BlendEquation

Blending equation for the alpha channel

Implementations§

“Alpha” blend mode

“Add” blend mode

“Multiply” blend mode

“None” blend mode

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

Default blending mode is alpha blending.

This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

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.