Blitz3D+ Command Reference

SetBuffer buffer

Parameters

buffer - the buffer to draw to: FrontBuffer(), BackBuffer(), an ImageBuffer() or a TextureBuffer()

Description

Sets the buffer that all following drawing commands draw to.

Everything that draws - Cls, Plot, Line, Rect, Oval, Text, DrawImage and friends - lands on the current buffer. After Graphics the current buffer is the front buffer (the visible screen); the first thing most games do is SetBuffer BackBuffer() to set up the classic draw-then-Flip loop. Graphics3D starts you on the back buffer already.

Pointing it at an ImageBuffer() lets you build pictures at runtime: render a minimap, compose a background once and draw it each frame, scribble onto a sprite. Point it back at BackBuffer() when done. In 3D games a TextureBuffer() works the same way for drawing onto textures.

Gotcha: SetBuffer also resets per-buffer drawing state - Origin goes back to 0,0, the Viewport opens up to the whole buffer, and the Print/Write cursor returns to the top left. Set Origin and Viewport after SetBuffer, not before.

The exception to "everything draws to the current buffer" is the Print family (Print, Write, Input), which always uses the front buffer.

See also: GraphicsBuffer, BackBuffer, FrontBuffer, ImageBuffer, TextureBuffer, Origin.

Example

; SetBuffer Example
; -----------------

Graphics 640,480,0,2

; SetBuffer redirects ALL drawing commands to the chosen buffer
SetBuffer BackBuffer()

use_back=1
x#=0

While Not KeyDown(1)

    ; Space switches the drawing buffer with SetBuffer
    If KeyHit(57) Then
        use_back=1-use_back
        If use_back Then SetBuffer BackBuffer() Else SetBuffer FrontBuffer()
    EndIf

    ; A ball drifting across the screen
    x=x+3
    If x>640 Then x=-40

    Cls
    Color 255,200,0
    Oval x,220,40,40,1

    Color 255,255,255
    Text 0,0,"Space: switch drawing buffer   Esc: exit"

    If use_back Then
        Text 0,20,"SetBuffer BackBuffer() - hidden until Flip: smooth animation"
        Flip
    Else
        Text 0,20,"SetBuffer FrontBuffer() - drawn straight to the screen: flicker"
        ; No Flip on the front buffer; a small delay paces the loop
        Delay 16
    EndIf

Wend

End

Index