Blitz3D+ Command Reference

BackBuffer ( )

Parameters

None.

Description

Returns a handle to the back buffer - the off-screen half of the display.

The display has two buffers: the front buffer, which is what the player sees, and the back buffer, which is hidden. The classic game loop draws the whole frame on the back buffer, then calls Flip to show it - so the player only ever sees finished frames, never half-drawn ones. Drawing straight to the front buffer instead tends to flicker.

So the usual setup is SetBuffer BackBuffer() right after Graphics, then a loop of Cls, draw everything, Flip. Nothing you draw on the back buffer is visible until Flip.

The handle can also be passed to commands that take a buffer, such as CopyRect, ReadPixel or GrabImage. In 3D games RenderWorld renders to the back buffer too, so 2D drawing after RenderWorld lands on top of the scene - that is how HUDs are done.

The handle becomes invalid when the display changes, so grab it again after any new Graphics call rather than storing it forever.

See also: FrontBuffer, SetBuffer, Flip, Cls, ImageBuffer.

Example

; BackBuffer Example
; ------------------

Graphics 640,480,0,2

; Draw to the hidden back buffer; Flip then shows each finished frame
SetBuffer BackBuffer()

use_back=1
x#=0

While Not KeyDown(1)

    ; Space toggles between back-buffer and front-buffer drawing
    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: toggle BackBuffer/FrontBuffer drawing   Esc: exit"

    If use_back Then
        Text 0,20,"Drawing to BackBuffer() - Flip shows each finished frame: smooth"
        Flip
    Else
        Text 0,20,"Drawing to FrontBuffer() - every step is visible at once: flicker"
        ; No Flip on the front buffer; a small delay paces the loop
        Delay 16
    EndIf

Wend

End

Index