'' ----------------------------------------------------------------------------
'' Irrlicht Wrapper For Imperative Languages - Freebasic Examples
'' Frank Dodd (2006)
'' ----------------------------------------------------------------------------
'' Blitz-Irrlicht 1.8.3 Interface by Ed Musolino (AquaLung 2015)
'' ----------------------------------------------------------------------------
'' Example 94 : Bump Mapping
'' This example loads in a Mesh Model And Then Then textures it using a bump
'' mapping technique called Normal Mapping. To see this effect your Graphics
'' card will need To support pixel And vertex shaders version 1.1
'' ----------------------------------------------------------------------------

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

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

' irrlicht objects
Global ModelMesh:Int
Global DiffuseTexture:Int
Global BumpTexture:Int
Global SceneNodeNormal:Int
Global SceneNodeParallax:Int
Global OurCamera:Int
Global Light:Int


'' ////////////////////////////////////////////////////////////////////////////
' start the irrlicht interface
iIrr3D( 1024, 768, 32, False )

' set the window caption
iAppTitle( "Example 94: Bump Mapping" )

' Load a mesh this acts as a blue Print For the model
ModelMesh = iLoadMesh( "./media/sphere.obj" )

' the mesh is quite small so scale it up without effecting lighting
iScaleMesh( ModelMesh, 12.5, 0, 0, 0 )

' Load texture resources For texturing the scene node
DiffuseTexture = iLoadTexture( "./media/detailmap-dim.jpg" )
BumpTexture = iLoadTexture( "./media/earthbump.bmp" )

' convert the grey scale image into a normal mapping texture. If you wish you
' can Create your own normal mapping texture but it is often simpler To Create
' a simple greyscale image as a bump map that defines the height of the surface
iNormalMapTexture( BumpTexture, 9.0 )

' add the mesh To the scene twice To display two types of bump mapping effects
' the mesh is added with a special command that creates a model with lighting
' information embedded into it this is required For bump mapping
SceneNodeNormal = iStaticMeshForNormalMapping( ModelMesh )
iPositionNode( SceneNodeNormal, 0, 0, -15 )
SceneNodeParallax = iStaticMeshForNormalMapping( ModelMesh )
iPositionNode( SceneNodeParallax, 0, 0, 15 )

' apply a material To the node To give its surface color
iNodeTexture( SceneNodeNormal, DiffuseTexture, 0 )
iNodeTexture( SceneNodeNormal, BumpTexture, 1 )
iNodeTexture( SceneNodeParallax, DiffuseTexture, 0 )
iNodeTexture( SceneNodeParallax, BumpTexture, 1 )

' Bump mapping is pointless unless lighting in enabled. we set the materials on
' one of the nodes To Normal Mapping And on the other To Parallax mapping.
' parallax mapping gives a richer deeping bump mapping effect but does require
' a more modern Graphics card
iNodeMaterialType ( SceneNodeNormal, IRR_EMT_NORMAL_MAP_SOLID )
iNodeMaterialType ( SceneNodeParallax, IRR_EMT_PARALLAX_MAP_SOLID )
iNodeMaterialFlag( SceneNodeNormal, IRR_EMF_LIGHTING, True )
iNodeMaterialFlag( SceneNodeParallax, IRR_EMF_LIGHTING, True )

' add a camera into the scene
OurCamera = iCreateCamera( False )
iPositionNode( OurCamera, 40, 0, 0 )

' finally we need To add a light into the scene. bump mapping requires a
' dynamic light To Create the bump mapping effect. additionally the lights need
' To be animated To show the changing light on the surface.
Light = iCreateLight( False, 100,100,-100, 0.9,0.3,0.3, 600.0 )
iFlyCircleAnimator( Light, 0,0,0, 100, 0.001 )

' hide the mouse pointer away
iHideMouse()

' -----------------------------------------------------------------------------
' 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()

Wend

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


End