' ------------------------------------------------------------
'   n3xt-D exemples
'
'   Sample  031   as   simple lightmapping test.
'   Historique   as 
'     29/03/09  19 as 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)
If app=NULL Then
  End
End If


'---------------------------
' define a ManualContruct Mesh
  Dim mesh as Mesh

' Create empty mesh
  mesh=_CreateEmptyMesh(EVT_2TCOORDS)
  
  
  
' 3 first vertices
  Dim v1 as Integer = _AddVertexMesh(mesh, 0, 0,0,0)
  Dim v2 as Integer = _AddVertexMesh(mesh, 0, 2,2,0)
  Dim v3 as Integer = _AddVertexMesh(mesh, 0, 2,0,0)
  ' first face
  _AddFaceMesh(mesh, 0, v1,v2,v3)
' 3 Next vertices
  Dim v4 as Integer = _AddVertexMesh(mesh, 0, 0,2,0)
  Dim v5 as Integer = _AddVertexMesh(mesh, 0, 2,2,0)
  Dim v6 as Integer = _AddVertexMesh(mesh, 0, 0,0,0)
  ' second face
  _AddFaceMesh(mesh, 0, v4,v5,v6)


  ' texture coordinate layer 0  
  
  _VertexTexCoord1Mesh( mesh, 0,0,  0, 1)
  _VertexTexCoord1Mesh( mesh, 0,1,  1, 0)
  _VertexTexCoord1Mesh( mesh, 0,2,  0, 0)
  
  _VertexTexCoord1Mesh( mesh, 0,3,  1, 1)
  _VertexTexCoord1Mesh( mesh, 0,4,  1, 0)
  _VertexTexCoord1Mesh( mesh, 0,5,  0, 1)
' texture coordinate layer 1  ( the same in this Case)
  _VertexTexCoord2Mesh( mesh, 0,0,  0, 1)
  _VertexTexCoord2Mesh( mesh, 0,1,  1, 0)
  _VertexTexCoord2Mesh( mesh, 0,2,  0, 0)
  _VertexTexCoord2Mesh( mesh, 0,3,  1, 1)
  _VertexTexCoord2Mesh( mesh, 0,4,  1, 0)
  _VertexTexCoord2Mesh( mesh, 0,5,  0, 1)
  
' 
Dim entitymesh as EntityNode = _CreateEntityNode(mesh)  
' set material of the mesh with EMT_LIGHTMAP mode
_MaterialTypeNode(entitymesh,  EMT_LIGHTMAP )
' Load two textures
Dim colormap as NTexture = _LoadTexture( "media/rockwall.bmp") 
Dim lightmap as NTexture = _LoadTexture( "media/lightmap.bmp") 
' set two texture layer
_MaterialTextureNode(entitymesh, colormap , 0)
_MaterialTextureNode(entitymesh, lightmap , 1)




' Create a camera
Dim cam As CameraNode = _CreateCamera( )
_PositionNode(cam, 0,0,-4)


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

' If Escape Key, Exit	
  If _GetKeyDown(KEY_ESCAPE) then
    Quit=1
  EndIf
  
  _TurnNode(entitymesh,0,0.5,0)
  

  	' ---------------
  	'      Render
  	' ---------------
  _BeginScene(30,20,10)
     _DrawScene()
  _EndScene()

Wend 
' end
_FreeEngine()

