Blitz3D+ Command Reference

WritePixelFast x,y,argb[,buffer]

Parameters

x - x coordinate of the pixel; must be inside the buffer

y - y coordinate of the pixel; must be inside the buffer

argb - colour to write, as one integer: alpha, red, green and blue bytes

buffer (optional) - buffer to write to, e.g. BackBuffer(); the current buffer set with SetBuffer (default)

Description

Writes a pixel colour with all safety checks skipped for speed.

The fast partner of WritePixel: in a locked buffer it can fill effects pixel by pixel at full speed - plasma, fire, static, procedural textures, software blends. Build the colour with shifts ((alpha Shl 24) Or (red Shl 16) Or (green Shl 8) Or blue) and remember $FF alpha for solid pixels.

Nothing is checked: coordinates are not clipped and Origin is ignored. Writing outside the buffer's 0 to width-1, 0 to height-1 range scribbles over memory that is not yours and can crash the program outright. Your loop bounds are the only safety net.

Keep the classic rules: LockBuffer first, write, UnlockBuffer after. On the modern runtime the lock is instant, but the no-clipping danger is fully intact.

See also: WritePixel, ReadPixelFast, LockBuffer, UnlockBuffer.

Example

; WritePixelFast Example
; ----------------------

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

t#=0

While Not KeyDown(1)

    Cls
    t=t+4

    ; WritePixelFast requires a locked buffer
    LockBuffer BackBuffer()

    ; Write a plasma pattern pixel by pixel into a small panel
    For y=0 To 95
        For x=0 To 127
            v#=Sin(x*4+t)+Sin(y*5-t)+Sin((x+y)*3+t*2)
            r=128+v*42
            g=128+Sin(v*60+t)*127
            b=255-r

            ; Pack alpha, red, green and blue into one ARGB value
            WritePixelFast 256+x,192+y,$FF000000 Or (r Shl 16) Or (g Shl 8) Or b
        Next
    Next

    ; Unlock before using any other drawing command
    UnlockBuffer BackBuffer()

    Color 255,255,255
    Rect 255,191,130,98,0
    Text 0,0,"Esc: exit"
    Text 0,20,"WritePixelFast plots 12,288 plasma pixels per frame"

    Flip

Wend

End

Index