Blitz3D+ Command Reference

SetGamma src_red,src_green,src_blue,dest_red#,dest_green#,dest_blue#

Parameters

src_red - red level being remapped; 0 to 255

src_green - green level being remapped; 0 to 255

src_blue - blue level being remapped; 0 to 255

dest_red# - red level to show instead; 0 to 255

dest_green# - green level to show instead; 0 to 255

dest_blue# - blue level to show instead; 0 to 255

Description

Sets one entry of the display's gamma ramp.

The gamma ramp is a 256-entry lookup table that sits between what your game draws and what the monitor shows. Each entry says "when a pixel comes out at this level, light the screen to that level instead". SetGamma writes a single entry, one level per colour channel, so a full ramp means a loop over all 256 values.

That loop is the whole technique. A straight line - entry i mapping to i - is the untouched default. Scaling every destination by a value that slides from 1 down to 0 gives you a whole-screen fade to black without drawing a single rectangle; the classic power curve 255*(i/255)^g is a brightness slider for your options menu; pushing the red destinations up and the blue ones down tints the world for a sunset, a poison effect or a damage flash. Because it happens after everything else, it colours your HUD and your particles too, with no cost per frame.

Nothing reaches the screen until you call UpdateGamma - SetGamma only fills the table in memory. Destination values are clamped into 0 to 255 for you, so a fade that overshoots is harmless, and source indexes wrap at 256. The three channels are independent: you can hand the same number to all three for a neutral curve, or three different numbers for a tint.

The big honesty note: on the modern DirectX 12 backend the table is stored and can be read back with GammaRed, GammaGreen and GammaBlue, but UpdateGamma does not push it to the display, so the screen brightness does not actually change. Gamma fades therefore need to be drawn instead - a full-screen black Rect with an alpha, or a shader - and SetGamma is best treated as a settings value your renderer consults. The table belongs to the graphics system, so open a mode with Graphics before touching it.

See also: UpdateGamma, GammaRed, GammaGreen, GammaBlue, Graphics.

Example

; SetGamma Example
; ----------------

Graphics 640,480,0,2
SetBuffer BackBuffer()

; Curve strength for the ramp we build. 1.0 is a straight line, lower
; brightens the midtones, higher darkens them.
power#=1.0

While Not KeyDown(1)

    Cls

    ; [ and ] bend the curve
    If KeyDown(26) And power>0.4 Then power=power-0.01
    If KeyDown(27) And power<3.0 Then power=power+0.01

    ; Fill all 256 entries of the gamma table. Each call maps one
    ; source level to the level the display should show instead.
    For i=0 To 255
        level#=255.0*((i/255.0)^power)
        SetGamma i,i,i,level,level,level
    Next

    ; Hand the finished table to the display driver
    UpdateGamma 0

    ; Top strip: the plain greys we asked for
    For x=0 To 255
        Color x,x,x
        Rect 60+x,140,1,60
    Next

    ; Bottom strip: the same greys read back through the table, which
    ; is what the screen would look like if the ramp reached it
    For x=0 To 255
        Color GammaRed(x),GammaGreen(x),GammaBlue(x)
        Rect 60+x,220,1,60
    Next

    Color 255,255,255

    Text 0,0,"[ / ] : bend the gamma curve   Esc: exit"
    Text 0,20,"SetGamma i,i,i,255*(i/255)^"+power+" for i=0 to 255"
    Text 0,40,"Entry 128 now maps to "+GammaRed(128)

    Text 60,120,"Source levels"
    Text 60,200,"Through the gamma table"

    Text 0,420,"The table is stored and readable, but the DirectX 12 backend"
    Text 0,440,"does not push it to the monitor, so the window itself does not"
    Text 0,460,"change brightness - the lower strip previews what it would do."

    Flip

Wend

End

Index