; TextureReloadError Example ; -------------------------- ; Requires Extended mode. Graphics3D 640,480,0,2 SetBuffer BackBuffer() SeedRnd MilliSecs() camera=CreateCamera() PositionEntity camera,0,0,-4 light=CreateLight() RotateEntity light,45,45,0 ; Write the texture file this example will reload, then load it PaintFile 30,70,160 crate=CreateCube() texture=LoadTexture("reload_error_demo.bmp") EntityTexture crate,texture While Not KeyDown(1) ; Space repaints the file properly and reloads it - this succeeds If KeyHit(57) Then PaintFile Rand(0,255),Rand(0,255),Rand(0,255) ok=ReloadTexture(texture) EndIf ; B overwrites the file with junk and reloads - the reload fails, ; the crate keeps its previous pixels, and the error is recorded If KeyHit(48) Then file=WriteFile("reload_error_demo.bmp") WriteLine file,"this is not a bitmap" CloseFile file ok=ReloadTexture(texture) EndIf TurnEntity crate,0.5,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: good repaint B: corrupt the file Arrows: camera Esc: exit" ; TextureReloadError holds the most recent failure, or "" after success If TextureReloadError(texture)<>"" Then Text 0,20,"TextureReloadError: "+TextureReloadError(texture) Else Text 0,20,"TextureReloadError is empty - last reload succeeded" Flip Wend ; Remove the file this example created FreeTexture texture DeleteFile "reload_error_demo.bmp" End ; Draw a coloured pattern and save it as the reloadable file on disk Function PaintFile(red,green,blue) scratch=CreateTexture(64,64) SetBuffer TextureBuffer(scratch) ClsColor red,green,blue Cls Color 255-red,255-green,255-blue Oval 12,12,40,40,True SetBuffer BackBuffer() Color 255,255,255 SaveBuffer TextureBuffer(scratch),"reload_error_demo.bmp" FreeTexture scratch End Function