'' ----------------------------------------------------------------------------
'' Irrlicht Wrapper For Imperative Languages - Freebasic Examples
'' Frank Dodd (2006)
'' ----------------------------------------------------------------------------
'' Blitz-Irrlicht 1.8.3 Interface by Ed Musolino (AquaLung 2015)
'' ----------------------------------------------------------------------------
'' Example 78: 2D Overlaid Hud
'' This example loads a BSP map from a pk3 archive And creates a first person
'' perspective camera so you can move around And view the map it also overlays
'' a 2D hud onto the screen To display information
'' ----------------------------------------------------------------------------

'' ////////////////////////////////////////////////////////////////////////////
'' Includes For extension libraries
Framework usr.birrlicht

'' ////////////////////////////////////////////////////////////////////////////
'' Global variables

' irrlicht objects
Global BSPMesh:Int
Global BSPNode:Int
Global Camera:Int
Global CameraNode:Int
Global HUDBulletTexture:Int
Global HUDCharacterTexture:Int

'' ////////////////////////////////////////////////////////////////////////////
' start the irrlicht interface
iVSync( True )
iIrr3D( 800, 600, 32, False )

' send the window caption
iAppTitle( "Example 78: 2D Overlaid HUD" )

' first we add the pk3 archive To our filing system. once we have done this
' we can open any of the files in the archive as If they were in the Current
' working directory
iAddZipFile( "./media/map-20kdm2.pk3", IRR_IGNORE_CASE, IRR_IGNORE_PATHS, "" )

' Load the BSP map from the archive as a mesh Object. any polygons in the mesh
' that do Not have textures will be removed from the scene!
BSPMesh = iLoadOctreeMesh( "20kdm2.bsp" )


' Load hud components
HUDBulletTexture = iLoadTexture( "./media/HUDBullet.tga" )
HUDCharacterTexture = iLoadTexture( "./media/HUDCharacter.tga" )

' add the map To the scene as a node. when adding the mesh this call uses a 
' mechanism called an octtree that If very efficient at rendering large amounts
' of complext geometry most of which cant be seen, using this call For maps
' will greatly improve your framerates
BSPNode = iAddOctreeMeshNode( BSPMesh )

' add a first person perspective camera into the scene that is controlled with
' the mouse And the cursor keys. If however you capture events when starting
' irrlicht this will become a normal camera that can only be moved by code
Camera = iCreateFPSCamera( 0,100.0,0.5,-1,0,0,0,0.0 )

' when we add a camera we are returned a camera Object however we can perform
' node operations on many different Object types that are entities within the
' scene however first we need To convert the camera Type into a node Type
CameraNode = Camera

' reposition And rotate the camera To look at a nice part of the map
iPositionNode( CameraNode, 1750, 149, 1369 )
iRotateNode( CameraNode, 4, -461.63, 0 )

' hide the mouse pointer
iHideMouse()

' erase the canvas with sky-blue before rendering
iCameraCLSColor( 128, 255, 255 )

' -----------------------------------------------------------------------------
' While the irrlicht environment is still running
While iRun() And (Not iKeyHit( KEY_ESCAPE ))

    ' begin the scene
    iBeginScene()

    ' draw the scene
    iDrawScene()
 
    ' draw some bullets
    For i = 0 To 3
        iDrawImageElement( HUDBulletTexture,754, 4 + i * 16, 0,0,32,16, True )
    Next

    ' draw a character
    iDrawImageElement( HUDCharacterTexture, 4, 4, 0,0,64,64, True )

    ' End drawing the scene And display it
    iEndScene()

Wend

' -----------------------------------------------------------------------------
' Stop the irrlicht engine And Release resources
iEndIrr3D()

End