#Include "Ninfa3d.bi"

dim Shared camera As nCAMERA
dim As nLIGHT light01,light02,light03,light04
Dim As nMESH pivot,cube
Dim As nSPRITE sprite01,sprite02,sprite03,sprite04
Dim As nTEXTURE tex0,tex1,tex2,tex3
Dim As Integer wire 
Dim As nFONT font01 

'Enable vertical synch.
EnableVsync()

'Starts the Ninfa3D Engine
InitEngine(640,480,32,0)
	BackGroundColor(128,128,128)'Background Color
	AmbientLight(100,100,100)'Ambient color

'Include the file "SampleFuntions.bi.
'It contains useful features, such as drawing the interface and create the test area.
#Include "SampleFunctions.bi"

'Create a camera
camera = CreateCameraMaya(-200,100,200)
	CameraTarget(camera,0,0,0)

font01 = LoadFont("media\courier.xml")'Load the font, in format XML

pivot = CreateMeshNull()'Creates an empty mesh is used as the pivot.

'Creates the lights
' White
light01 = CreateLight(LGT_POINT)
	EntityParent(light01,pivot)
	PositionEntity(light01,0,0,100)' Position
    
sprite01 = LoadSprite("media/glow.bmp")
	EntityParent(sprite01,light01)
	ScaleSprite(sprite01,30,30)

' Red
light02 = CreateLight(LGT_POINT)
	EntityParent(light02,pivot)
	PositionEntity(light02,0,0,-100)' Position

sprite02 = LoadSprite("media/glow.bmp")
	EntityParent(sprite02,light02)
	ScaleSprite(sprite02,30,30)
	SpriteColor(sprite02,255,0,0)

'Load textures
tex0 = LoadTexture("media/mur_Ambiant.jpg")
tex1 = LoadTexture("media/mur_Hauteur.jpg")

'Load mesh.
cube = LoadMesh("media/cube.ms3d",VT_TANGENTS)
	EntityTexture(cube,tex0,0)
	EntityTexture(cube,tex1,1)

While(EngineRun)'Returns 1 if the engine is running.

	'Begins scene
	BeginScene()
	
	'By pressing the "ESCAPE" closes the engine.
	If KeyHit(KEY_ESCAPE) Then CloseEngine()
	
	'Update the Engine.
	'Changing the value (only affects the physics) that will update the
	'Physical faster or slower.
	UpdateEngine(0)

	If KeyHit(KEY_1) Then EntityType(cube,MT_SOLID)
	If KeyHit(KEY_2) Then EntityType(cube,MT_NORMAL_MAP)'Apply graphic effects.
	If KeyHit(KEY_3) Then EntityType(cube,MT_PARALLAX_MAP)'Apply graphic effects.

	If KeyHit(KEY_W) Then wire = wire + 1

	If wire>1 Then wire = 0

	If Wire = 1 Then
		EntityFlag(cube,0,1)
	Else
		EntityFlag(cube,0,0)
	EndIf

	TurnEntity(pivot,0.5,0.5,0.5)

	Font(font01)'assign the font to use
	Text(15,75,"Press:",0,0)
	Text(15,100,"1 - Solid",0,0)
	Text(15,125,"2 - BumpMapping",0,0)
	Text(15,150,"3 - ParallaxMapping",0,0)
	Text(15,175,"4 - SpecularMapping",0,0)
	Text(15,200,"W - Wireframe",0,0)

	'Displays the interface (FPS and triangles)
	Interface()

	'End the scene
	EndScene()

Wend

'Ends Ninfa3D Engine
EndEngine()