Blitz3D+ Command Reference

ImageBuffer ( image[,frame] )

Parameters

image - handle of the image whose buffer you want

frame (optional) - frame of an animated image; 0 (default)

Description

Returns the drawing buffer of an image, so you can draw into the image itself.

Hand the result to SetBuffer and every drawing command that follows lands inside the picture instead of on the screen: Cls, Rect, Line, Text, even DrawImage to stamp one image into another. Next time you draw the image, your changes are there.

That covers a lot of ground: painting damage or graffiti onto a wall texture, building a HUD panel once instead of assembling it every frame, compositing a character out of separate body-part sprites, or generating a starfield into a blank CreateImage. It is also the buffer you pass to the pixel commands - ReadPixel, WritePixel, CopyPixel - when you want to work on an image pixel by pixel.

Each frame of an animated image is its own buffer, so pass the frame number to reach the right one.

Always put the buffer back when you are done, usually with SetBuffer BackBuffer(). Forgetting is the classic cause of "my game went blank" - everything is still being drawn, just into the image. And remember the buffer belongs to the image: after FreeImage it is gone.

See also: SetBuffer, BackBuffer, CreateImage, GrabImage, GraphicsBuffer.

Example

; ImageBuffer Example
; -------------------

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

; A blank canvas image we will paint onto while the program runs
canvas=CreateImage(640,480)

While Not KeyDown(1)

    Cls

    ; Hold the left mouse button to paint INTO the canvas image
    If MouseDown(1) Then
        SetBuffer ImageBuffer(canvas)     ; drawing now goes into the image
        Color Rand(60,255),Rand(60,255),Rand(60,255)
        Oval MouseX()-8,MouseY()-8,16,16,True
        SetBuffer BackBuffer()            ; back to normal screen drawing
    End If

    ; Draw the canvas image - it keeps everything painted so far
    DrawImage canvas,0,0

    ; A ring shows the brush position
    Color 255,255,255
    Oval MouseX()-8,MouseY()-8,16,16,False

    Text 0,0,"Hold the left mouse button to paint into the image   Esc: exit"
    Text 0,20,"SetBuffer ImageBuffer(canvas) redirects drawing into the image"

    Flip

Wend

End

Index