In this tutorial we add a lens flare to the scene and make it visible.
This tutorial is a continuation on the previous one called "Simple Free Look Camera"
Firstly the game engine takes care of creating and deleting the lensflare from the scene, so we dont need to handle that here.
We need to set up the lentflare position so that it is not to close to the camera position.
Also note that this position is relative to the camera's position, so there is no way that the camera will get too close to the lensflare causeing rendering artifacts.
To set the position of the lens flare we use the code below:
{This will always be relative to the camera's position} rglSetEnvironmentLensFlareLightPosition(-1500,500,-1000);
A point o note on the lensfrare object: This object automatically occludes itself when behind any non blended objects, so you dont have to worry about that.
After we set up the position, we need to load the seperate component images of the flare, we do this by using the code below:
{Once that is done, we load our lensflare textures, and we pass in the actual scene width and height} rglInitEnvironmentLensFlare('Data/Flare0.jpg', 'Data/Flare1.jpg', 'Data/Flare2.jpg', 'Data/Flare3.jpg', 'Data/Flare4.jpg', 'Data/Flare5.jpg', 'Data/Flare6.jpg', 'Data/Flare7.jpg', 'Data/Flare8.jpg', rglGetSceneActualWidth, rglGetSceneActualHeight);
We load up 9 different flares for the object, and also pass in the actual width and height of the scene.
As a side note: rglGetSceneActualWidth and rglGetSceneActualHeight are used to get the actual scene dimentions.
These two functions exists because when you are in windowed mode the borders of the window needs to be subtracted from the window to find the rendering area's dimentions. This is very important for accurate occlusion culling.
The lensflare can be enabled or disabled using rglSetEnvironmentLensFlareVisibleFlag(True or false); but it is not necisary to enable it initially because it is done as soon as you call rglInitEnvironmentLensFlare
And that is basically it! Nothing else is needed.
Download the code
Please note: In order to use and compile any of these tutotrials, you will need to download the Binary and Art for the engine
|