Blitz3D+ Command Reference

TextureBuffer ( texture[,frame] )

Parameters

texture - texture handle
frame (optional) - which frame's buffer to get, for multi-frame textures; 0 (default)

Description

Returns the drawing buffer of a texture, for use with SetBuffer.

SetBuffer TextureBuffer(texture) redirects the 2D drawing commands - Rect, Text, DrawImage and friends - into the texture itself. Draw, then SetBuffer BackBuffer() to go back to normal rendering. Anything using the texture shows the new pixels: live scoreboards, security monitors, decals, procedural art.

Two practical notes. For frequent updates it is often quicker to draw into an image and CopyRect the result onto the texture buffer than to draw piece by piece directly. And to show 3D on a texture, render normally and CopyRect from BackBuffer() to the texture buffer.

Like all buffer handles, the value is only valid for the life of the texture - grab it fresh rather than caching it across texture reloads.

See also: CreateTexture, SetBuffer, CopyRect, BackBuffer, TextureWidth.

Example

; TextureBuffer Example
; ---------------------

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

camera=CreateCamera()

light=CreateLight()
RotateEntity light,45,45,0

cube=CreateCube()
PositionEntity cube,0,0,5

; Start with a plain white texture on the cube
tex=CreateTexture(256,256)
SetBuffer TextureBuffer(tex)
ClsColor 255,255,255
Cls
SetBuffer BackBuffer()
EntityTexture cube,tex

SeedRnd MilliSecs()

While Not KeyDown(1)

    ; Space wipes the texture clean
    If KeyHit(57)
        SetBuffer TextureBuffer(tex)
        Cls
        SetBuffer BackBuffer()
    EndIf

    ; Splat a random paint blob into the texture every frame.
    ; TextureBuffer lets the 2D drawing commands work on the texture itself.
    SetBuffer TextureBuffer(tex)
    Color Rand(0,255),Rand(0,255),Rand(0,255)
    Oval Rand(0,240),Rand(0,240),16,16,1
    SetBuffer BackBuffer()
    Color 255,255,255

    TurnEntity cube,0,1,0

    ; Arrow keys move the camera
    If KeyDown(200) Then MoveEntity camera,0,0,0.1
    If KeyDown(208) Then MoveEntity camera,0,0,-0.1
    If KeyDown(203) Then TurnEntity camera,0,1,0
    If KeyDown(205) Then TurnEntity camera,0,-1,0

    RenderWorld

    Text 0,0,"Space: clean the texture   Arrows: camera   Esc: exit"
    Text 0,20,"Paint is drawn into TextureBuffer(tex) every frame"

    Flip

Wend

End

Index