# struct `SF::BlendMode`

inherits `Struct`

#

Blending modes for drawing

`SF::BlendMode`

is a struct 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 struct is composed of 6 components, each of which has its own public member variable:

- 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):

```
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
```

The most common blending modes are defined as constants in the SF module:
`SF::BlendAlpha`

, `SF::BlendAdd`

, `SF::BlendMultiply`

, `SF::BlendNone`

.

In SFML, a blend mode can be specified every time you draw a `SF::Drawable`

object to a render target. It is part of the `SF::RenderStates`

compound
that is passed to the member function `SF::RenderTarget.draw()`

.

*See also:* `SF::RenderStates`

, `SF::RenderTarget`

## Constants#

### ```
BlendAdd =
````BlendMode.new(BlendMode::SrcAlpha, BlendMode::One, BlendMode::Add, BlendMode::One, BlendMode::One, BlendMode::Add)`

#

`BlendMode.new(BlendMode::SrcAlpha, BlendMode::One, BlendMode::Add, BlendMode::One, BlendMode::One, BlendMode::Add)`

Add source to dest

### ```
BlendAlpha =
````BlendMode.new(BlendMode::SrcAlpha, BlendMode::OneMinusSrcAlpha, BlendMode::Add, BlendMode::One, BlendMode::OneMinusSrcAlpha, BlendMode::Add)`

#

`BlendMode.new(BlendMode::SrcAlpha, BlendMode::OneMinusSrcAlpha, BlendMode::Add, BlendMode::One, BlendMode::OneMinusSrcAlpha, BlendMode::Add)`

Blend source and dest according to dest alpha

### ```
BlendMultiply =
````BlendMode.new(BlendMode::DstColor, BlendMode::Zero)`

#

`BlendMode.new(BlendMode::DstColor, BlendMode::Zero)`

Multiply source and dest

### ```
BlendNone =
````BlendMode.new(BlendMode::One, BlendMode::Zero)`

#

`BlendMode.new(BlendMode::One, BlendMode::Zero)`

Overwrite dest with source

## Class methods#

### ```
.new
````(color_source_factor : BlendMode::Factor, color_destination_factor : BlendMode::Factor, color_blend_equation : BlendMode::Equation, alpha_source_factor : BlendMode::Factor, alpha_destination_factor : BlendMode::Factor, alpha_blend_equation : BlendMode::Equation)`

#

`(color_source_factor : BlendMode::Factor, color_destination_factor : BlendMode::Factor, color_blend_equation : BlendMode::Equation, alpha_source_factor : BlendMode::Factor, alpha_destination_factor : BlendMode::Factor, alpha_blend_equation : BlendMode::Equation)`

Construct the blend mode given the factors and equation.

*color_source_factor*- Specifies how to compute the source factor for the color channels.*color_destination_factor*- Specifies how to compute the destination factor for the color channels.*color_blend_equation*- Specifies how to combine the source and destination colors.*alpha_source_factor*- Specifies how to compute the source factor.*alpha_destination_factor*- Specifies how to compute the destination factor.*alpha_blend_equation*- Specifies how to combine the source and destination alphas.

### ```
.new
````(source_factor : BlendMode::Factor, destination_factor : BlendMode::Factor, blend_equation : BlendMode::Equation = Add)`

#

`(source_factor : BlendMode::Factor, destination_factor : BlendMode::Factor, blend_equation : BlendMode::Equation = Add)`

Construct the blend mode given the factors and equation.

This constructor uses the same factors and equation for both color and alpha components. It also defaults to the Add equation.

*source_factor*- Specifies how to compute the source factor for the color and alpha channels.*destination_factor*- Specifies how to compute the destination factor for the color and alpha channels.*blend_equation*- Specifies how to combine the source and destination colors and alpha.

## Methods#

### ```
#!=
````(right : BlendMode) : Bool`

#

`(right : BlendMode) : Bool`

Overload of the != operator

*left*- Left operand*right*- Right operand

*Returns:* True if blending modes are different, false if they are equal

### ```
#==
````(right : BlendMode) : Bool`

#

`(right : BlendMode) : Bool`

Overload of the == operator

*left*- Left operand*right*- Right operand

*Returns:* True if blending modes are equal, false if they are different

### ```
#alpha_dst_factor
````: BlendMode::Factor`

#

`: BlendMode::Factor`

Destination blending factor for the alpha channel

### ```
#color_dst_factor
````: BlendMode::Factor`

#

`: BlendMode::Factor`

Destination blending factor for the color channels

### ```
#dup
````: BlendMode`

#

`: BlendMode`

Returns a shallow copy of this object.

Because `Value`

is a value type, this method returns `self`

,
which already involves a shallow copy of this object because
value types are passed by value.