;; ----------------------------------------------------------------------------
;; Irrlicht Wrapper For Imperative Languages - Purebasic Examples
;; IrrlichtWrapper and FreeBasic-Example by Frank Dodd (2006)
;; Improved IrrlichtWrapper - Michael Taupitz (2007)
;; PureBasic-Examples by Michael Taupitz (neotoma) & Marius Eckardt (Thalius) 
;; ----------------------------------------------------------------------------
;; Example 16 : 2D Text at a 3D location
;; This example draws 2D text at a location on the screen that is directly over
;; specific 3D point in the scene. That point is set To hover over a models
;; head making it appear like the model has a text label
;; ----------------------------------------------------------------------------

;; ////////////////////////////////////////////////////////////////////////////
;; Include the Irr3D-Requester
XIncludeFile "Irr3DRequester.pb"

; irrlicht objects
*MD2Mesh.irr_mesh
*MeshTexture.irr_texture
*SceneNode.irr_node
*OurCamera.irr_camera
*BitmapFont.irr_font
X.l
Y.l
vect.IRR_VECTOR


;; ////////////////////////////////////////////////////////////////////////////
;; GDB debugger main() function

; -----------------------------------------------------------------------------
; To Start the Irrlicht-Device we use the Irr3DRequester, to make it more comfortable
; for the Users, and also easier to test different resolutions and devices.
If Irr3DRequester()

  ; send the window caption
  IrrSetWindowCaption( "Example 16: 2D Text at a 3D Location" )
  
  ; load the bitmap font as a texture
  *BitmapFont = IrrGetFont ( "media\bitmapfont.bmp" )
  
  ; load a mesh
  *MD2Mesh = IrrGetMesh( "media\sydney.md2" )
  
  ; load texture resources for texturing models
  *MeshTexture = IrrGetTexture( "media\sydney.bmp" )
  
  ; add the mesh to the scene a couple of times
  *SceneNode = IrrAddMeshToScene( *MD2Mesh )
  
  ; the node is still at the origin move the vector to just over the nodes
  ; head
  vect\X = 0
  vect\Y = 0
  vect\Z = 0
  
  ; apply a material to the object
  IrrSetNodeMaterialTexture( *SceneNode, *MeshTexture, 0 )
  
  ; switch off lighting effects on this model
  IrrSetNodeMaterialFlag( *SceneNode, #IRR_EMF_LIGHTING, #IRR_OFF )
  
  ; play specific animation sequences
  IrrPlayNodeMD2Animation( *SceneNode, #IRR_EMAT_STAND )
  
  ; add a camera into the scene and move it into position
  *OurCamera = IrrAddFPSCamera()
  IrrSetNodePosition( *OurCamera, 80,0,0 )
  IrrSetCameraTarget( *OurCamera, 0,0,0 )
  
  ; hide the mouse from the screen
  IrrHideMouse()
  
  ; -----------------------------------------------------------------------------
  ; while the irrlicht environment is still running
  While IrrRunning()
      ; begin the scene, erasing the canvas with grey before rendering
      IrrBeginScene( 128,128,128 )
  
      ; draw the scene
      IrrDrawScene()
  
      IrrGetNodePosition(*SceneNode,@vect\X,@vect\Y,@vect\Z)
          
      ; using the 3D coordinate get the X and Y position of this coordinate as it
      ; appears on the screen
      IrrGetScreenCoordinatesFrom3DPosition( @X, @Y, @vect ) 
  
      ; Debug(Str(X)+","+Str(Y))
  
      ; draw the name of the model over the head of the model
      Irr2DFontDraw ( *BitmapFont, "SYDNEY", X-15, Y-200, X+35, Y )
  
      ; end drawing the scene and render it
      IrrEndScene()
  Wend
  
  ; -----------------------------------------------------------------------------
  ; Stop the irrlicht engine and release resources
  IrrStop()

EndIf  

End

; IDE Options = PureBasic 4.10 Beta 3 (Windows - x86)
; CursorPosition = 91
; FirstLine = 50
; Folding = -