#Include "Ninfa3d.bi"

dim Shared camera As nCAMERA
dim As nLIGHT light01
Dim As nMESH goku,vegeta,piccolo,sp
Dim sprite As nSPRITE
Dim As nTEXTURE tex01,tex02
Dim cartoon As nSHADER

'Enable vertical synch.
EnableVsync()

'Starts the Ninfa3D Engine
InitEngine(640,480,32,0)
	BackGroundColor(128,128,128)'Background Color
	AmbientLight(64,64,64)'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 = CreateCameraFPS(100,0.5)
	PositionEntity(camera,0,64,256)' Position

'Creates the lights
light01 = CreateLight(LGT_POINT)
	PositionEntity(light01,0,128,256)' Position
	LightCastShadow(light01)'It makes the light cast shadows.
	LightRadius(light01,256)' Radius of the light
	
sprite = LoadSprite("media/glow.bmp")
	EntityParent(sprite,light01)
	ScaleSprite(sprite,30,30)

CreateGround()'Creates the test area

'Create array	
'For the effect that items below, served to obscure the edges of the model.
Dim silhouette As S = 0.2f

'Loads the shader
cartoon = LoadShader("media\ToonShading.vert","media\ToonShading.frag")

'Set the value to a variable effect, in this case the silhouette.
'I use the command PixelShaderConstant, because that variable is stored in
'the file pixel, and only has a value, I would get a one.
	PixelShaderConstant(cartoon,"silhouetteThreshold",@silhouette,1)

'Load meshs
goku = LoadMesh("media\goku.b3d")
	AnimateMesh(goku,1,30,1,235,1)'Animate the mesh
	PositionEntity(goku,0,25,25)'Move the mesh
	RotateEntity(goku,0,180,0)
	ScaleMesh(goku,2.5,2.5,2.5)
	EntityShininess(goku,20)
	ApplyShadersEntity(cartoon,goku)'Apply graphic effects.

vegeta = LoadMesh("media\vegeta.b3d")
	AnimateMesh(vegeta,1,30,1,235,1)'Animate the mesh
	PositionEntity(vegeta,50,25,0)'Move the mesh
	RotateEntity(vegeta,0,180,0)
	ScaleMesh(vegeta,2.5,2.5,2.5)
	EntityShininess(vegeta,20)
	ApplyShadersEntity(cartoon,vegeta)'Apply graphic effects.
	
piccolo = LoadMesh("media\piccolo.b3d")
	AnimateMesh(piccolo,1,30,1,235,1)'Animate the mesh
	PositionEntity(piccolo,-50,25,0)'Move the mesh
	RotateEntity(piccolo,0,180,0)
	ScaleMesh(piccolo,2.5,2.5,2.5)
	EntityShininess(piccolo,20)
	ApplyShadersEntity(cartoon,piccolo)'Apply graphic effects.
		
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)

	'Creates the contour lines of the model
	OutlineMesh(goku,2,0,0,0)
	OutlineMesh(vegeta,2,0,0,0)
	OutlineMesh(piccolo,2,0,0,0)
	
	'Displays the interface (FPS and triangles)
	Interface()

	'End the scene
	EndScene()
	
Wend

'Ends Ninfa3D Engine
EndEngine()