#[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