Blitz3D+ Command Reference

GetBrushTexture ( brush[,index] )

Parameters

brush - brush handle

index (optional) - texture layer to read, 0-7; 0 (default)

Description

Returns the texture sitting in one of a brush's texture layers.

A brush carries up to eight texture layers (the same index 0-7 you pass to BrushTexture), and this command lets you read one back. The classic use is poking around inside a loaded model: walk its surfaces with GetSurface, grab each surface's brush with GetSurfaceBrush, then use GetBrushTexture and TextureName to find out which image files the artist painted it with.

The returned handle is a NEW texture handle, not the brush's own - every call creates another one, even for the same layer. Free it with FreeTexture as soon as you have finished with it, or the copies pile up and the underlying image can never be released. Freeing the copy does not harm the brush; the image itself stays alive for as long as anything still uses it.

If the layer has no texture in it you still get a handle back - TextureName returns an empty string for it, and it still wants freeing like any other.

See also: BrushTexture, TextureName, GetEntityBrush, GetSurfaceBrush, FreeTexture.

Example

; GetBrushTexture Example
; -----------------------

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

camera=CreateCamera()
PositionEntity camera,0,1,-5

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

; Two textures: one from disk, one made in code
logo_tex=LoadTexture("media/b3dlogo.jpg")
code_tex=CreateTexture(64,64)
SetBuffer TextureBuffer(code_tex)
ClsColor 80,160,255
Cls
SetBuffer BackBuffer()

; A brush drives the look of this pickup crate
brush=CreateBrush()
BrushTexture brush,logo_tex
crate=CreateCube()
PositionEntity crate,0,1,0
PaintEntity crate,brush

While Not KeyDown(1)

    ; 1 / 2 retexture the brush, then repaint the crate with it
    If KeyHit(2)
        BrushTexture brush,logo_tex
        PaintEntity crate,brush
    EndIf
    If KeyHit(3)
        BrushTexture brush,code_tex
        PaintEntity crate,brush
    EndIf

    ; Ask the brush which texture sits in slot 0
    got=GetBrushTexture(brush,0)
    name$=TextureName$(got)
    If name$="" Then name$="(unnamed - created in code)"
    If Len(name$)>48 Then name$="..."+Right$(name$,45)
    ; The returned handle is a copy - free it or copies pile up
    FreeTexture got

    TurnEntity crate,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,"1/2: swap brush texture   Arrows: camera   Esc: exit"
    Text 0,20,"GetBrushTexture(brush,0) is "+name$

    Flip

Wend

End

Index