Blitz3D+ Command Reference

LoadBrush ( file$[,texture_flags][,u_scale#][,v_scale#] )

Parameters

file$ - image file to load as the brush's texture
texture_flags (optional) - texture flags, as per LoadTexture; 1: colour (default)
u_scale# (optional) - texture scale across the surface; 1 (default)
v_scale# (optional) - texture scale down the surface; 1 (default)

Description

Creates a brush with a texture loaded from an image file, and returns the brush handle.

It is a shortcut for CreateBrush + LoadTexture + BrushTexture: the result is a white brush with the image in texture layer 0. The optional texture_flags parameter takes the same values as LoadTexture (2 alpha, 4 masked, 8 mipmapped and so on), and u_scale/v_scale pre-scale the texture exactly like ScaleTexture.

If the image cannot be loaded, 0 is returned - check before painting with the handle.

Once loaded, treat it like any other brush: adjust it with the Brush commands and apply it with PaintSurface, PaintMesh or PaintEntity.

See also: CreateBrush, LoadTexture, BrushTexture, ScaleTexture, PaintMesh, FreeBrush.

Example

; LoadBrush Example
; -----------------

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

camera=CreateCamera()

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

; A crate to paint. A brush is a 'paint recipe' applied with PaintEntity.
crate=CreateCube()
PositionEntity crate,0,0,5

scale#=1.0

; LoadBrush loads a texture and returns a ready-made brush in one call.
; Parameters: file$, texture flags (1=color), then u and v texture scale.
brush=LoadBrush("media/b3dlogo.jpg",1,scale,scale)
PaintEntity crate,brush

While Not KeyDown(1)

    ; Press [ / ] to halve/double the texture scale and reload the brush
    changed=0
    If KeyHit(26) And scale>0.25
        scale=scale/2
        changed=1
    EndIf
    If KeyHit(27) And scale<4
        scale=scale*2
        changed=1
    EndIf

    If changed
        FreeBrush brush
        brush=LoadBrush("media/b3dlogo.jpg",1,scale,scale)
        PaintEntity crate,brush
    EndIf

    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,"[ / ] : change texture scale   Arrows: camera   Esc: exit"
    Text 0,20,"LoadBrush media/b3dlogo.jpg, flags 1, scale "+scale+","+scale

    Flip

Wend

End

Index