Function glBlendFunc

  • Pixels can be drawn using a function that blends the incoming (source) RGBA values with the RGBA values that are already in the frame buffer (the destination values). Blending is initially disabled. Use glEnable and glDisable with argument GL_BLEND to enable and disable blending.

    glBlendFunc defines the operation of blending when it is enabled. sfactor specifies which method is used to scale the source color components. dfactor specifies which method is used to scale the destination color components. Both parameters must be one of the following symbolic constants: GL_ZERO, GL_ONE, GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR, GL_DST_COLOR, GL_ONE_MINUS_DST_COLOR, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA, GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR, GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA, GL_SRC_ALPHA_SATURATE, GL_SRC1_COLOR, GL_ONE_MINUS_SRC1_COLOR, GL_SRC1_ALPHA, and GL_ONE_MINUS_SRC1_ALPHA. The possible methods are described in the following table. Each method defines four scale factors, one each for red, green, blue, and alpha. In the table and in subsequent equations, first source, second source and destination color components are referred to as (๐‘s0,๐†s0,๐s0,๐€s0), (๐‘s1,๐†s1,๐s1,๐€s1) and (๐‘d,๐†d,๐d,๐€d), respectively. The color specified by glBlendColor is referred to as (๐‘c,๐†c,๐c,๐€c). They are understood to have integer values between 0 and (k๐‘,k๐†,k๐,k๐€), where

    ๐Š๐‘ = 2แตแถœ โˆ’ 1

    and (๐ฆ๐‘…, ๐ฆ๐บ, ๐ฆ๐ต, ๐ฆ๐ด) is the number of red, green, blue, and alpha bitplanes.

    Source and destination scale factors are referred to as (๐‘ ๐‘,๐‘ ๐†,๐‘ ๐,๐‘ ๐€) and (d๐‘,d๐†,d๐,d๐€). The scale factors described in the table, denoted (f๐‘,f๐†,f๐,f๐€), represent either source or destination factors. All scale factors have range [0,1].

    Parameter (ฦ’๐‘, ฦ’๐†, ฦ’๐, ฦ’๐€)
    GL_ZERO (0, 0, 0, 0)
    GL_ONE (1, 1, 1, 1)
    GL_SRC_COLOR (๐‘s0/๐Š๐‘, ๐†s0/๐Š๐†, ๐s0/๐Š๐, ๐€s0/๐Š๐€)
    GL_ONE_MINUS_SRC_COLOR (1, 1, 1, 1) โˆ’ (๐‘s0/๐Š๐‘, ๐†s0/๐Š๐†, ๐s0/๐Š๐, ๐€s0/๐Š๐€)
    GL_DST_COLOR (๐‘d/๐Š๐‘, ๐†d/๐Š๐†, ๐d/๐Š๐, ๐€d/๐Š๐€)
    GL_ONE_MINUS_DST_COLOR (1, 1, 1, 1) โˆ’ (๐‘d/๐Š๐‘, ๐†d/๐Š๐†, ๐d/๐Š๐, ๐€d/๐Š๐€)
    GL_SRC_ALPHA (๐€s0/๐Š๐€, ๐€s0/๐Š๐€, ๐€s0/๐Š๐€, ๐€s0/๐Š๐€)
    GL_ONE_MINUS_SRC_ALPHA (1, 1, 1, 1) โˆ’ (๐€s0/๐Š๐€, ๐€s0/๐Š๐€, ๐€s0/๐Š๐€, ๐€s0/๐Š๐€)
    GL_DST_ALPHA (๐€d/๐Š๐€, ๐€d/๐Š๐€, ๐€d/๐Š๐€, ๐€d/๐Š๐€)
    GL_ONE_MINUS_DST_ALPHA (1, 1, 1, 1) โˆ’ (๐€d/๐Š๐€, ๐€d/๐Š๐€, ๐€d/๐Š๐€, ๐€d/๐Š๐€)
    GL_CONSTANT_COLOR (๐‘๐‘, ๐†๐‘, ๐๐‘, ๐€๐‘)
    GL_ONE_MINUS_CONSTANT_COLOR (1, 1, 1, 1) โˆ’ (๐‘๐‘, ๐†๐‘, ๐๐‘, ๐€๐‘)
    GL_CONSTANT_ALPHA (๐€๐‘, ๐€๐‘, ๐€๐‘, ๐€๐‘)
    GL_ONE_MINUS_CONSTANT_ALPHA (1, 1, 1, 1) โˆ’ (๐€๐‘, ๐€๐‘, ๐€๐‘, ๐€๐‘)
    GL_SRC_ALPHA_SATURATE (๐ข, ๐ข, ๐ข, 1)
    GL_SRC1_COLOR (๐‘s1/๐Š๐‘, ๐†s1/๐Š๐†, ๐s1/๐Š๐, ๐€s1/๐Š๐€)
    GL_ONE_MINUS_SRC1_COLOR (1, 1, 1, 1) โˆ’ (๐‘s1/๐Š๐‘, ๐†s1/๐Š๐†, ๐s1/๐Š๐, ๐€s1/๐Š๐€)
    GL_SRC1_ALPHA (๐€s1/๐Š๐€, ๐€s1/๐Š๐€, ๐€s1/๐Š๐€, ๐€s1/๐Š๐€)
    GL_ONE_MINUS_SRC1_ALPHA (1, 1, 1, 1) โˆ’ (๐€s1/๐Š๐€, ๐€s1/๐Š๐€, ๐€s1/๐Š๐€, ๐€s1/๐Š๐€)

    In the table,

    ๐ข = min(๐€๐‘ , ๐Š๐€ โˆ’ ๐€d) / ๐Š๐€

    To determine the blended RGBA values of a pixel, the system uses the following equations:

    ๐‘๐‘‘ = min(๐Š๐‘…, ๐‘โ‚›s๐‘… + ๐‘๐‘‘d๐‘…) ๐†d = min(๐Š๐บ, ๐†โ‚›s๐บ + ๐†๐‘‘d๐บ) ๐๐‘‘ = min(๐Š๐ต, ๐โ‚›s๐ต + ๐๐‘‘d๐ต) ๐€d = min(๐Š๐ด, ๐€โ‚›s๐ด + ๐€๐‘‘d๐ด)

    Despite the apparent precision of the above equations, blending arithmetic is not exactly specified, because blending operates with imprecise integer color values. However, a blend factor that should be equal to 1 is guaranteed not to modify its multiplicand, and a blend factor equal to 0 reduces its multiplicand to 0. For example, when sfactor is GL_SRC_ALPHA, dfactor is GL_ONE_MINUS_SRC_ALPHA, and ๐€โ‚› is equal to ๐Š๐ด, the equations reduce to simple replacement:

    ๐‘๐‘‘ = ๐‘โ‚› ๐†d = ๐†โ‚› ๐๐‘‘ = ๐โ‚› ๐€d = ๐€โ‚›

    Parameters

    Returns void

    Summary

    specify pixel arithmetic

    See

    glBlendFunc

Generated using TypeDoc