DrawSetBlendMode

Syntax

Success = DrawSetBlendMode(Mode.i)

Description

Sets the blend mode for subsequent drawing operations within the current drawing context. The blend mode determines how the colors of newly drawn shapes (source) are combined with the existing colors on the drawing target (destination).

Parameters

Mode.i
The desired blend mode. Must be one of:

#PG_Blend_SourceOver : (Default) The source color is blended over the destination color based on the source alpha. Formula: result = source + destination * (1 - source_alpha).
#PG_Blend_Copy       : The source color completely replaces the destination color, ignoring alpha. Formula: result = source.
#PG_Blend_Min        : The minimum color component value between source and destination is used. Formula: result = min(source, destination). (Direct2D only)
#PG_Blend_Add        : Source and destination color components are added together, clamped at 1.0. Formula: result = min(1.0, source + destination). (Direct2D only)
#PG_Blend_Max        : The maximum color component value between source and destination is used. Formula: result = max(source, destination). (Direct2D only)

Return Value

Returns #True if the mode was successfully set, or #False if the mode value was invalid or if called outside a BeginDraw() / EndDraw() block.

Remarks

The setting persists until changed again or until the drawing state is restored via DrawRestore(). The default #PG_Blend_SourceOver provides standard alpha blending suitable for most UI drawing. Other modes are for special effects and may not be supported on all graphics backends.

Example

IncludeFile "ProGUI_PB.pbi"

StartProGUI()

Procedure DrawHandler(Window, EventType, *EventData.PG_EventDraw, *UserData)
  
    DrawClear(RGB(50, 50, 50), 1) ; Dark background

    ; Draw with default SourceOver blending
    DrawBox(10, 10, 100, 100, RGB(255, 0, 0), 0.7) ; Semi-transparent Red
    DrawBox(60, 60, 100, 100, RGB(0, 0, 255), 0.7) ; Semi-transparent Blue (overlap looks purple)

    ; Change to Additive blending
    DrawSetBlendMode(#PG_Blend_Add)

    ; Draw overlapping boxes with additive blending
    DrawBox(180, 10, 100, 100, RGB(255, 0, 0), 0.7) ; Semi-transparent Red
    DrawBox(230, 60, 100, 100, RGB(0, 0, 255), 0.7) ; Semi-transparent Blue (overlap looks brighter magenta)

    ; Restore default
    DrawSetBlendMode(#PG_Blend_SourceOver)

EndProcedure

MyWindow = CreateWindow(0, 0, 400, 200, "Set BlendMode Example")

If MyWindow
  AddEventHandler(MyWindow, #PG_Event_Draw, @DrawHandler())
  WindowShow(MyWindow, #True, #PG_Window_ScreenCentered)

  Repeat
    Event = WaitWindowEvent()
  Until Event = #PB_Event_CloseWindow
EndIf

StopProGUI()

See Also

DrawGetBlendMode, BeginDraw, EndDraw, DrawSave, DrawRestore

Supported OS

Windows, Linux (Note: Some modes like Add, Min, Max are Direct2D specific)