'' ----------------------------------------------------------------------------
'' Irrlicht Wrapper For Imperative Languages - Freebasic Examples
'' Frank Dodd (2006-2010)
'' ----------------------------------------------------------------------------
'' Blitz-Irrlicht 1.8.3 Interface by Ed Musolino (AquaLung 2015)
'' ----------------------------------------------------------------------------
'' Example 38 : Dynamic Lighting
'' This example changes the properties of the lighting dynamically as the
'' program runs
'' ----------------------------------------------------------------------------

'' ////////////////////////////////////////////////////////////////////////////
'' Includes For extension libraries
Framework usr.birrlicht

'' ////////////////////////////////////////////////////////////////////////////
'' Global variables

' irrlicht objects
Global SphereNode:Int
Global NodeTexture:Int
Global Material:Int
Global Light:Int
Global LightAmbient:Int
Global Camera:Int
Global attenuation:Float = 1.0
Global red_diffuse:Float = 1.0
Global green_diffuse:Float = 0.0
Global blue_diffuse:Float = 0.5
Global ambient:Float = 0.0

'' ////////////////////////////////////////////////////////////////////////////
' start the irrlicht interface
iIrr3D( 800, 600, 32, False )

' set the window caption
iAppTitle( "Example 38: Dynamic Lighting" )

' Create some simple scene objects
SphereNode = iCreateSphere( 32, False )
iScaleNode( SphereNode, 20, 20, 20 )

' add a simple point light
Light = iCreateLight( False, -100,100,100, 1.0,1.0,1.0, 600.0 )

' add a black light used To introduce ambient lighting
LightAmbient = iCreateLight( False, 0,0,0, 0.0,0.0,0.0, 600.0 )

' add a camera To the scene To view the objects
Camera = iCreateCamera( False )

iPositionNode( Camera, -50,0,0 )

' we also hide the mouse pointer To see the view better
iHideMouse()

' erase the canvas with sky-blue before rendering
iCameraCLSColor( 0, 0, 0 )

' -----------------------------------------------------------------------------
' While the irrlicht environment is still running

While iRun() And (Not iKeyHit( KEY_ESCAPE ))

	' begin the scene
	iBeginScene()

	' change the diffuse color emitted by the light over time
	iLightDiffuseColor( Light, red_diffuse, green_diffuse, blue_diffuse )
	If red_diffuse > 0.0 Then red_diffuse = red_diffuse - 0.00001
	If green_diffuse < 1.0 Then green_diffuse = green_diffuse + 0.00001
	If blue_diffuse < 1.0 Then blue_diffuse = blue_diffuse + 0.00001
    
	' slowly introduce ambient light
	iLightAmbientColor( LightAmbient, ambient, ambient, ambient )
	If ambient < 0.1 Then ambient = ambient + 0.000001
    
	' draw the scene
	iDrawScene()
        
	' End drawing the scene And render it
	iEndScene()

Wend 

' -----------------------------------------------------------------------------
' Stop the irrlicht engine And Release resources
iEndIrr3D()


End