; ActiveTextures Example ; ---------------------- Graphics3D 640,480,0,2 SetBuffer BackBuffer() camera=CreateCamera() PositionEntity camera,0,1,-8 light=CreateLight() RotateEntity light,45,45,0 ; A textured crate for the basic scene crate=CreateCube() PositionEntity crate,0,1,0 crate_tex=LoadTexture("media/b3dlogo.jpg") EntityTexture crate,crate_tex ; Loading the same file again shares the cached image, so this ; second handle does NOT add another active texture crate_tex2=LoadTexture("media/b3dlogo.jpg") loaded=0 Dim tile(7) Dim tile_tex(7) While Not KeyDown(1) ; Space toggles a batch of eight code-built textures If KeyHit(57) If loaded=0 loaded=1 For i=0 To 7 ; Every CreateTexture adds one active texture tile_tex(i)=CreateTexture(64,64) SetBuffer TextureBuffer(tile_tex(i)) ClsColor 30*i,255-30*i,128 Cls SetBuffer BackBuffer() tile(i)=CreateCube() ScaleEntity tile(i),0.5,0.5,0.5 PositionEntity tile(i),(i-3.5)*1.5,-1,0 EntityTexture tile(i),tile_tex(i) Next Else loaded=0 For i=0 To 7 FreeEntity tile(i) ; Freeing the texture releases its cached image FreeTexture tile_tex(i) Next EndIf 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: load/free 8 textures Arrows: camera Esc: exit" Text 0,20,"ActiveTextures() = "+ActiveTextures() Flip Wend End