'' ----------------------------------------------------------------------------
'' Irrlicht Wrapper For Imperative Languages - Freebasic Examples
'' Frank Dodd (2006)
'' ----------------------------------------------------------------------------
'' Blitz-Irrlicht 1.8.3 Interface by Ed Musolino (AquaLung 2015)
'' ----------------------------------------------------------------------------
'' Example 111: Fade Animator For Transparency
'' This example demonstrates the fade animator applied To transparent nodes.
'' ----------------------------------------------------------------------------

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


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

' irrlicht objects
Global Billboard:Int[3]
Global BillboardTexture:Int
Global Camera:int


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

' send the window caption
iAppTitle( "Example 111: Fade Animator for Transparency" )

' Load the texture resource For the billboard
BillboardTexture = iLoadTexture( "./media/beam.png" )

' add the billboard To the scene, the first two parameters are the size of the
' billboard in this instance they match the pixel size of the bitmap To give
' the correct aspect ratio. the last three parameters are the position of the
' billboard Object
Billboard(1) = iCreateBillBoard( 30.0,100.0, -30.0,0.0,100.0 )
Billboard(2) = iCreateBillBoard( 30.0,100.0,   0.0,0.0,100.0 )
Billboard(3) = iCreateBillBoard( 30.0,100.0,  30.0,0.0,100.0 )

' now we apply the loaded texture To the billboard using node material index 0
iNodeTexture( Billboard(1), BillboardTexture, 0 )
iNodeTexture( Billboard(2), BillboardTexture, 0 )
iNodeTexture( Billboard(3), BillboardTexture, 0 )

' fading requires that lighting is enabled
iNodeMaterialFlag( Billboard(1), IRR_EMF_LIGHTING, True )
iNodeMaterialFlag( Billboard(2), IRR_EMF_LIGHTING, True )
iNodeMaterialFlag( Billboard(3), IRR_EMF_LIGHTING, True )

' apply transparent materials types
iNodeMaterialType ( Billboard(1), IRR_EMT_TRANSPARENT_ADD_COLOR )
iNodeMaterialType ( Billboard(2), IRR_EMT_TRANSPARENT_ALPHA_CHANNEL )
iNodeMaterialType ( Billboard(3), IRR_EMT_TRANSPARENT_ALPHA_CHANNEL_REF )

' add a first person perspective camera into the scene so we can move around
' the billboard And see how it reacts
Camera = iCreateCamera( False )
iCameraTarget( Camera, 50, 0, 20 )

' hide the mouse pointer
iHideMouse()

' set the ambient light level across the entire scene
iAmbientLight( 1,1,1 )

iScaleNode( Billboard(1), 0.5,0.5,0.5 )

iCameraCLSColor( 128, 128, 255 )

' -----------------------------------------------------------------------------
' While the irrlicht environment is still running
While iRun() And (Not iKeyHit( KEY_ESCAPE ))

         ' begin the scene, erasing the canvas with sky-blue before rendering
        iBeginScene()
    
        ' draw the scene
        iDrawScene()
    
        ' End drawing the scene And render it
        iEndScene()
        
        ' wait Until 100 frames have elapsed
        frames = frames + 1
        If frames = 100 Then
            ' Add the fade, scale And Delete animator
            iFadeAnimator( Billboard(1), 3000, -0.5 )      ' shrink
            iFadeAnimator( Billboard(2), 3000,  0.0 )      ' dont scale
            iFadeAnimator( Billboard(3), 3000,  0.5 )      ' expand
        EndIf

Wend

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


End

