Blitz3D+ Command Reference

FreeTexture texture

Parameters

texture - texture handle

Description

Frees a texture.

Call it when you are done with a texture handle - typically after applying the texture to everything that needs it. Textures are reference-counted internally, so entities and brushes that already use the texture keep working; the pixel data is only released once nothing references it any more.

After FreeTexture the handle itself is invalid: don't pass it to any texture command again. Set your variable to 0 as a reminder.

See also: LoadTexture, CreateTexture, EntityTexture, FreeBrush.

Example

; FreeTexture Example
; -------------------

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

camera=CreateCamera()

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

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

; Load a texture and apply it to the crate
tex=LoadTexture("media/b3dlogo.jpg")
EntityTexture crate,tex

While Not KeyDown(1)

    ; Space frees the texture. Entities that were already textured keep
    ; their own copy, so the crate is unaffected.
    If KeyHit(57) And tex<>0
        FreeTexture tex
        tex=0
    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,"Space: free the texture   Arrows: camera   Esc: exit"
    If tex<>0
        Text 0,20,"Texture loaded - press Space to call FreeTexture"
    Else
        Text 0,20,"FreeTexture called - the crate keeps its texture"
    EndIf

    Flip

Wend

End

Index