Support :


----TUTORIAL 6---

Adding LensFlare and Glow Effect

You will Need The NemoX engine Get it Here

download the Visual Basic Source code here

we'll use the same BaseCode as the Previous tutorial.


1. New Objects Declaration and initialization

2. Setting Up our Lens Flare

3. Game Loop Modification



1. New Objects Declaration and initialization

'The Main One is The NemoX renderer
Dim Nemo As NemoX

'we're gonna use a Nemo class for rendering a mesh or polygons
'we use cNemo_Mesh class

Dim Mesh As cNemo_Mesh
'we will need a quick acces to very important and useful functions
Dim Tool As cNemo_Tools

Dim Sky As cNemo_SkyBox

'the lensflare object
'====NEW OBJECT====

Dim LENS As cNemo_LensFlare

Now in our initialization code we Add a new initializer code provided by NemoX engine

'we will used that sub for the engine initialization

Sub InitEngine()

 'first thing allocate memory for the main Object
  Set Nemo = New Nemo
  Set Tool = New cNemo_Tools

'we use this method
'now we allow the user to choose options
'32/16 bit backbuffer
  If Not (Nemo.INIT_ShowDeviceDLG(Form1.hWnd)) Then
   End 'terminate here if error
  End If
  'set the back clearcolor
  Nemo.BackBuffer_ClearCOLOR = &HFFC0C0C0
  'set some parameters
  Nemo.Set_ViewFrustum 1, 15000, 3.14 / 4
  Nemo.Set_light True
  'set our camera
  Nemo.Camera_set_EYE Tool.Vector(0, 15, 0)
End Sub

2.Setting Up our Lens Flare

Now we add the Lensflare initialization code at our Builgeometry sub routine

        '============NEW CODE========
        ' setting up the Lensflare
        'allocate memory for our Lensflare class
        Set LENS = New cNemo_LensFlare
        'set our SunGlow textureFile,Position, and size
        LENS.Add_SunTEX App.Path + "\flare\flare_sun.bmp", Tool.Vector(800, 900, 0), 500
        'configurate our cameraLensburningout color default=white &HFFFFFFFF
        LENS.Set_SunburningEffectColor 255, 150, 255
        'specify that we wil use a static position for our lenslare
        'this allow to simultate Ray of lens from any Static lightSource
        'In this demo we will use a static source
        LENS.Set_LensPositionStatus STATIC_SOURCE
        'activate randomizer
        Randomize Timer
        'we add 6 Lens Spark.....TextureFile,index,size,position,Color,SpecularColor
        'TextureFile =any TGA,BMP,JPG file
        'index       =the Index for the lensSpark
        'size        =the size of our spark
        'position    =the position the sun pos is 100, middle distance=50
        'Color       =main Color for the spark
        'highlight   =color for the outter of the circle
        LENS.Add_Lens App.Path + "\flare\flare1.jpg", 0, 15, 90, &HFFFFFFFF * Rnd, &HFFFFFFFF * Rnd
        LENS.Add_Lens App.Path + "\flare\flare2.jpg", 1, 10, 50, &HFFFFFFFF * Rnd, &HFFFFFFFF * Rnd
        LENS.Add_Lens App.Path + "\flare\flare3.jpg", 2, 7, 30, &HFFFFFFFF * Rnd, &HFFFFFFFF * Rnd
        LENS.Add_Lens App.Path + "\flare\flare4.jpg", 3, 5, 15, &HFFFFFFFF * Rnd, &HFFFFFFFF * Rnd
        LENS.Add_Lens App.Path + "\flare\flare5.jpg", 4, 3, 0, &HFFFFFFFF * Rnd, &HFFFFFFFF * Rnd
        LENS.Add_Lens App.Path + "\flare\flare6.jpg", 5, 1, -4, &HFFFFFFFF * Rnd, &HFFFFFFFF * Rnd
      'this next line allow to specify the blending mode


3.Game Loop Modification

'this sub is the main loop for a game or 3d apllication
Sub gameLoop()
            'loop untill player press 'ESCAPE'
               '=====Keyboard handler can be added here
               Call GetKey 'go to the previous tutorial for details
               'start the 3d renderer
                     '===============ADD game rendering mrthod here
               'render the sky


               'draw our floor

                             '===NEW CODE===

               'Render lastly our lensflare

               '===END NEW CODE==
               'show the FPS at pixel(5,10) color White
               Nemo.Draw_Text "FPS:" + Str(Nemo.Framesperseconde), 5, 10, &HFFFF0000
               'end the 3d renderer
            'check the player keyPressed
    Loop Until Nemo.Get_KeyPress(NEMO_KEY_ESCAPE)
    Call EndGame 'go to the previous tutorial for details

End Sub

Here is a screenshot for our tutorial project

download the Visual Basic Source code here

See you in the next Tutorial.....sincerly Polaris..Don't forget Any Bugs detected mailMe


    The PreviousTutorial 5 :Adding SkyBox environnment

The Next Tutorial 7 :Adding New Geometry datas