' ------------------------------------------------------------
'   n3xt-D exemples
'
'   Sample 038  : Occlusion Test.
'   Historique  :
'     29/03/09  19:16    TMyke
'
' ------------------------------------------------------------
' Includes libraries
#include "N3xtD.bi"

' Dimes
Dim app As any Ptr
Dim Quit As Integer


'----------------------------------------------------------
' open n3xt-D screen
app = _CreateGraphics3D(800,600, 32, FALSE, FALSE)
If app=NULL Then
  End
End If
 

'---------------------------------------------
' Create light And set position
  Dim light As LightNode = _CreateLight( &hffffffff, 50) 
  _PositionNode(light, 0,5,-20)
  
  
  
'---------------------------------------------
' Create mesh
 Dim cubemesh As Mesh = _CreateCubeMesh()
 Dim spheremesh As Mesh = _CreateSphereMesh(1.0, 32)
 Dim cylindermesh As Mesh= _CreateCylinderMesh(1.0, 3.0)

 
'---------------------------------------------
' Create a cube And set position
Dim cube As EntityNode = _CreateEntityNode(cubemesh)
_ScaleNode(cube, 8,8,1)
_PositionNode(cube, -1,0,-5) 




'---------------------------------------------
' Create 12 sphere entities, with occlusion
' system test
Dim i As Integer, j As Integer
For i =0 To 3
  For  j  = 0 To 3
     Dim sphere As EntityNode = _CreateEntityNode(spheremesh)
    _PositionNode(sphere, -1.5+i, -1.5+j,0) 
    _LoadTextureNode(sphere, "media/five.bmp") 
    _AddOcclusionQuery(sphere, spheremesh)
  Next
Next


'---------------------------------------------
' Create a cylinder entity And set position
 Dim cylinder As EntityNode = _CreateEntityNode(cylindermesh)
_PositionNode(cylinder, 2,2,0) 




' Create a camera
dim cam As CameraNode = _CreateCameraFPS(80, 0.03 )
_PositionNode(cam, 0,0,-20)


  
'-----------------------------------
' Load font png
_LoadFont("media/courriernew.png")
Dim font As IGUIFont = _GetFont()


' ---------------------------------------
'           Main loop
' ---------------------------------------
While Quit=0
 

' If Escape Key, Exit	
  If _GetKeyDown(KEY_ESCAPE) then
    Quit=1
  EndIf
  

  
  	' ---------------
  	'      Render
  	' ---------------
  	_BeginScene(128,128,128) 	
     _DrawScene()
     _DrawText(font, "Move arround the plane, FPS : "+ Str(_FPS())  ,  10,25,0,0, &hffffffff)
     _DrawText(font, "Primitives: "+ Str(_PrimitiveCountDrawn())  ,  10,45,0,0, &hffffffff)   
  _EndScene()


Wend 
' end
_FreeEngine()


