aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/irrlicht-1.8.1/doc/html/example020.html
blob: 0431cbb6caf520a2d5e693f1188976321ecff955 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>Irrlicht 3D Engine: Tutorial 20: Managed Lights</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  <td id="projectlogo"><img alt="Logo" src="irrlichtlogo.png"/></td>
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">Irrlicht 3D Engine
   
   </div>
   
  </td>
  
  
  
   
   <td>        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
</td>
   
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<script type="text/javascript" src="dynsections.js"></script>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('example020.html','');
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">Tutorial 20: Managed Lights </div>  </div>
</div>
<div class="contents">
<div class="textblock"><div class="image">
<img src="020shot.jpg" alt="020shot.jpg"/>
</div>
 <p>Written by Colin MacDonald. This tutorial explains the use of the Light Manager of Irrlicht. It enables the use of more dynamic light sources than the actual hardware supports. Further applications of the Light Manager, such as per scene node callbacks, are left out for simplicity of the example. </p>
<div class="fragment"><pre class="fragment"><span class="preprocessor">#include &lt;<a class="code" href="irrlicht_8h.html" title="Main header file of the irrlicht, the only file needed to include.">irrlicht.h</a>&gt;</span>
<span class="preprocessor">#include &quot;<a class="code" href="driver_choice_8h.html">driverChoice.h</a>&quot;</span>

<span class="keyword">using namespace </span>irr;
<span class="keyword">using namespace </span>core;

<span class="preprocessor">#if defined(_MSC_VER)</span>
<span class="preprocessor"></span><span class="preprocessor">#pragma comment(lib, &quot;Irrlicht.lib&quot;)</span>
<span class="preprocessor">#endif // MSC_VER</span>
</pre></div><p>Normally, you are limited to 8 dynamic lights per scene: this is a hardware limit. If you want to use more dynamic lights in your scene, then you can register an optional light manager that allows you to to turn lights on and off at specific point during rendering. You are still limited to 8 lights, but the limit is per scene node.</p>
<p>This is completely optional: if you do not register a light manager, then a default distance-based scheme will be used to prioritise hardware lights based on their distance from the active camera.</p>
<p>NO_MANAGEMENT disables the light manager and shows Irrlicht's default light behaviour. The 8 lights nearest to the camera will be turned on, and other lights will be turned off. In this example, this produces a funky looking but incoherent light display.</p>
<p>LIGHTS_NEAREST_NODE shows an implementation that turns on a limited number of lights per mesh scene node. If finds the 3 lights that are nearest to the node being rendered, and turns them on, turning all other lights off. This works, but as it operates on every light for every node, it does not scale well with many lights. The flickering you can see in this demo is due to the lights swapping their relative positions from the cubes (a deliberate demonstration of the limitations of this technique).</p>
<p>LIGHTS_IN_ZONE shows a technique for turning on lights based on a 'zone'. Each empty scene node is considered to be the parent of a zone. When nodes are rendered, they turn off all lights, then find their parent 'zone' and turn on all lights that are inside that zone, i.e. are descendents of it in the scene graph. This produces true 'local' lighting for each cube in this example. You could use a similar technique to locally light all meshes in (e.g.) a room, without the lights spilling out to other rooms.</p>
<p>This light manager is also an event receiver; this is purely for simplicity in this example, it's neither necessary nor recommended for a real application. </p>
<div class="fragment"><pre class="fragment"><span class="keyword">class </span>CMyLightManager : <span class="keyword">public</span> scene::ILightManager, <span class="keyword">public</span> IEventReceiver
{
    <span class="keyword">typedef</span> <span class="keyword">enum</span>
    {
        NO_MANAGEMENT,
        LIGHTS_NEAREST_NODE,
        LIGHTS_IN_ZONE
    }
    LightManagementMode;

    LightManagementMode Mode;
    LightManagementMode RequestedMode;

    <span class="comment">// These data represent the state information that this light manager</span>
    <span class="comment">// is interested in.</span>
    scene::ISceneManager * SceneManager;
    core::array&lt;scene::ISceneNode*&gt; * SceneLightList;
    <a class="code" href="namespaceirr_1_1scene.html#a7862269bd1abc123929d4dbb8200d67f" title="Enumeration for render passes.">scene::E_SCENE_NODE_RENDER_PASS</a> CurrentRenderPass;
    scene::ISceneNode * CurrentSceneNode;

<span class="keyword">public</span>:
    CMyLightManager(scene::ISceneManager* sceneManager)
        : Mode(NO_MANAGEMENT), RequestedMode(NO_MANAGEMENT),
        SceneManager(sceneManager), SceneLightList(0),
        CurrentRenderPass(scene::<a class="code" href="namespaceirr_1_1scene.html#a7862269bd1abc123929d4dbb8200d67fa1f79a46e7a41716dcae5c8dfe8d310bb" title="No pass currently active.">ESNRP_NONE</a>), CurrentSceneNode(0)
    { }

    <span class="comment">// The input receiver interface, which just switches light management strategy</span>
    <span class="keywordtype">bool</span> OnEvent(<span class="keyword">const</span> SEvent &amp; event)
    {
        <span class="keywordtype">bool</span> handled = <span class="keyword">false</span>;

        <span class="keywordflow">if</span> (event.EventType == <a class="code" href="namespaceirr.html#ac9eed96e06e85ce3c86fcbbbe9e48a0ca6f90390f3147a1693e5e2e3422d6ca09" title="A key input event.">irr::EET_KEY_INPUT_EVENT</a> &amp;&amp; event.KeyInput.PressedDown)
        {
            handled = <span class="keyword">true</span>;
            <span class="keywordflow">switch</span>(event.KeyInput.Key)
            {
            <span class="keywordflow">case</span> <a class="code" href="namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3a61ec605d669b598d2e7106981a326fde">irr::KEY_KEY_1</a>:
                RequestedMode = NO_MANAGEMENT;
                <span class="keywordflow">break</span>;
            <span class="keywordflow">case</span> <a class="code" href="namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3aa7574bf313b5c29547f01c36f0a4a4f8">irr::KEY_KEY_2</a>:
                RequestedMode = LIGHTS_NEAREST_NODE;
                <span class="keywordflow">break</span>;
            <span class="keywordflow">case</span> <a class="code" href="namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3a577dcff3b86e6dd45f70d8c691dd3c91">irr::KEY_KEY_3</a>:
                RequestedMode = LIGHTS_IN_ZONE;
                <span class="keywordflow">break</span>;
            <span class="keywordflow">default</span>:
                handled = <span class="keyword">false</span>;
                <span class="keywordflow">break</span>;
            }

            <span class="keywordflow">if</span>(NO_MANAGEMENT == RequestedMode)
                SceneManager-&gt;setLightManager(0); <span class="comment">// Show that it&#39;s safe to register the light manager</span>
            <span class="keywordflow">else</span>
                SceneManager-&gt;setLightManager(<span class="keyword">this</span>);
        }

        <span class="keywordflow">return</span> handled;
    }


    <span class="comment">// This is called before the first scene node is rendered.</span>
    <span class="keyword">virtual</span> <span class="keywordtype">void</span> OnPreRender(core::array&lt;scene::ISceneNode*&gt; &amp; lightList)
    {
        <span class="comment">// Update the mode; changing it here ensures that it&#39;s consistent throughout a render</span>
        Mode = RequestedMode;

        <span class="comment">// Store the light list. I am free to alter this list until the end of OnPostRender().</span>
        SceneLightList = &amp;lightList;
    }

    <span class="comment">// Called after the last scene node is rendered.</span>
    <span class="keyword">virtual</span> <span class="keywordtype">void</span> OnPostRender()
    {
        <span class="comment">// Since light management might be switched off in the event handler, we&#39;ll turn all</span>
        <span class="comment">// lights on to ensure that they are in a consistent state. You wouldn&#39;t normally have</span>
        <span class="comment">// to do this when using a light manager, since you&#39;d continue to do light management</span>
        <span class="comment">// yourself.</span>
        <span class="keywordflow">for</span> (<a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> i = 0; i &lt; SceneLightList-&gt;size(); i++)
            (*SceneLightList)[i]-&gt;setVisible(<span class="keyword">true</span>);
    }

    <span class="keyword">virtual</span> <span class="keywordtype">void</span> OnRenderPassPreRender(<a class="code" href="namespaceirr_1_1scene.html#a7862269bd1abc123929d4dbb8200d67f" title="Enumeration for render passes.">scene::E_SCENE_NODE_RENDER_PASS</a> renderPass)
    {
        <span class="comment">// I don&#39;t have to do anything here except remember which render pass I am in.</span>
        CurrentRenderPass = renderPass;
    }

    <span class="keyword">virtual</span> <span class="keywordtype">void</span> OnRenderPassPostRender(<a class="code" href="namespaceirr_1_1scene.html#a7862269bd1abc123929d4dbb8200d67f" title="Enumeration for render passes.">scene::E_SCENE_NODE_RENDER_PASS</a> renderPass)
    {
        <span class="comment">// I only want solid nodes to be lit, so after the solid pass, turn all lights off.</span>
        <span class="keywordflow">if</span> (<a class="code" href="namespaceirr_1_1scene.html#a7862269bd1abc123929d4dbb8200d67fad058b020ab42ad745cc03fe379148e1f" title="Solid scene nodes or special scene nodes without materials.">scene::ESNRP_SOLID</a> == renderPass)
        {
            <span class="keywordflow">for</span> (<a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> i = 0; i &lt; SceneLightList-&gt;size(); ++i)
                (*SceneLightList)[i]-&gt;setVisible(<span class="keyword">false</span>);
        }
    }

    <span class="comment">// This is called before the specified scene node is rendered</span>
    <span class="keyword">virtual</span> <span class="keywordtype">void</span> OnNodePreRender(scene::ISceneNode* node)
    {
        CurrentSceneNode = node;

        <span class="comment">// This light manager only considers solid objects, but you are free to manipulate</span>
        <span class="comment">// lights during any phase, depending on your requirements.</span>
        <span class="keywordflow">if</span> (<a class="code" href="namespaceirr_1_1scene.html#a7862269bd1abc123929d4dbb8200d67fad058b020ab42ad745cc03fe379148e1f" title="Solid scene nodes or special scene nodes without materials.">scene::ESNRP_SOLID</a> != CurrentRenderPass)
            <span class="keywordflow">return</span>;

        <span class="comment">// And in fact for this example, I only want to consider lighting for cube scene</span>
        <span class="comment">// nodes.  You will probably want to deal with lighting for (at least) mesh /</span>
        <span class="comment">// animated mesh scene nodes as well.</span>
        <span class="keywordflow">if</span> (node-&gt;getType() != <a class="code" href="namespaceirr_1_1scene.html#acad3d7ef92a9807d391ba29120f3b7bda44d66f5c284aed4d0698d6854b6a72e3" title="simple cube scene node">scene::ESNT_CUBE</a>)
            <span class="keywordflow">return</span>;

        <span class="keywordflow">if</span> (LIGHTS_NEAREST_NODE == Mode)
        {
            <span class="comment">// This is a naive implementation that prioritises every light in the scene</span>
            <span class="comment">// by its proximity to the node being rendered.  This produces some flickering</span>
            <span class="comment">// when lights orbit closer to a cube than its &#39;zone&#39; lights.</span>
            <span class="keyword">const</span> <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">vector3df</a> nodePosition = node-&gt;getAbsolutePosition();

            <span class="comment">// Sort the light list by prioritising them based on their distance from the node</span>
            <span class="comment">// that&#39;s about to be rendered.</span>
            array&lt;LightDistanceElement&gt; sortingArray;
            sortingArray.reallocate(SceneLightList-&gt;size());

            <a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> i;
            <span class="keywordflow">for</span>(i = 0; i &lt; SceneLightList-&gt;size(); ++i)
            {
                scene::ISceneNode* lightNode = (*SceneLightList)[i];
                <span class="keyword">const</span> <a class="code" href="namespaceirr.html#a1325b02603ad449f92c68fc640af9b28" title="64 bit floating point variable.">f64</a> distance = lightNode-&gt;getAbsolutePosition().getDistanceFromSQ(nodePosition);
                sortingArray.push_back(LightDistanceElement(lightNode, distance));
            }

            sortingArray.sort();

            <span class="comment">// The list is now sorted by proximity to the node.</span>
            <span class="comment">// Turn on the three nearest lights, and turn the others off.</span>
            <span class="keywordflow">for</span>(i = 0; i &lt; sortingArray.size(); ++i)
                sortingArray[i].node-&gt;setVisible(i &lt; 3);
        }
        <span class="keywordflow">else</span> <span class="keywordflow">if</span>(LIGHTS_IN_ZONE == Mode)
        {
            <span class="comment">// Empty scene nodes are used to represent &#39;zones&#39;.  For each solid mesh that</span>
            <span class="comment">// is being rendered, turn off all lights, then find its &#39;zone&#39; parent, and turn</span>
            <span class="comment">// on all lights that are found under that node in the scene graph.</span>
            <span class="comment">// This is a general purpose algorithm that doesn&#39;t use any special</span>
            <span class="comment">// knowledge of how this particular scene graph is organised.</span>
            <span class="keywordflow">for</span> (<a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> i = 0; i &lt; SceneLightList-&gt;size(); ++i)
            {
                <span class="keywordflow">if</span> ((*SceneLightList)[i]-&gt;getType() != <a class="code" href="namespaceirr_1_1scene.html#acad3d7ef92a9807d391ba29120f3b7bda73c87b4a418b0b7dc9d441cdf45f51e3" title="Light Scene Node.">scene::ESNT_LIGHT</a>)
                    <span class="keywordflow">continue</span>;
                scene::ILightSceneNode* lightNode = <span class="keyword">static_cast&lt;</span>scene::ILightSceneNode*<span class="keyword">&gt;</span>((*SceneLightList)[i]);
                video::SLight &amp; lightData = lightNode-&gt;getLightData();

                <span class="keywordflow">if</span> (<a class="code" href="namespaceirr_1_1video.html#aaf0e02f6f83cc35cf9e764bf18400d39a46a64f42740c097ee15d5c3a87961788" title="directional light, coming from a direction from an infinite distance">video::ELT_DIRECTIONAL</a> != lightData.Type)
                    lightNode-&gt;setVisible(<span class="keyword">false</span>);
            }

            scene::ISceneNode * parentZone = findZone(node);
            <span class="keywordflow">if</span> (parentZone)
                turnOnZoneLights(parentZone);
        }
    }

    <span class="comment">// Called after the specified scene node is rendered</span>
    <span class="keyword">virtual</span> <span class="keywordtype">void</span> OnNodePostRender(scene::ISceneNode* node)
    {
        <span class="comment">// I don&#39;t need to do any light management after individual node rendering.</span>
    }

<span class="keyword">private</span>:

    <span class="comment">// Find the empty scene node that is the parent of the specified node</span>
    scene::ISceneNode * findZone(scene::ISceneNode * node)
    {
        <span class="keywordflow">if</span> (!node)
            <span class="keywordflow">return</span> 0;

        <span class="keywordflow">if</span> (node-&gt;getType() == <a class="code" href="namespaceirr_1_1scene.html#acad3d7ef92a9807d391ba29120f3b7bda977d9500eeb4d4f23e5676a312367f57" title="Empty Scene Node.">scene::ESNT_EMPTY</a>)
            <span class="keywordflow">return</span> node;

        <span class="keywordflow">return</span> findZone(node-&gt;getParent());
    }

    <span class="comment">// Turn on all lights that are children (directly or indirectly) of the</span>
    <span class="comment">// specified scene node.</span>
    <span class="keywordtype">void</span> turnOnZoneLights(scene::ISceneNode * node)
    {
        core::list&lt;scene::ISceneNode*&gt; <span class="keyword">const</span> &amp; children = node-&gt;getChildren();
        <span class="keywordflow">for</span> (core::list&lt;scene::ISceneNode*&gt;::ConstIterator child = children.begin();
            child != children.end(); ++child)
        {
            <span class="keywordflow">if</span> ((*child)-&gt;getType() == <a class="code" href="namespaceirr_1_1scene.html#acad3d7ef92a9807d391ba29120f3b7bda73c87b4a418b0b7dc9d441cdf45f51e3" title="Light Scene Node.">scene::ESNT_LIGHT</a>)
                (*child)-&gt;setVisible(<span class="keyword">true</span>);
            <span class="keywordflow">else</span> <span class="comment">// Assume that lights don&#39;t have any children that are also lights</span>
                turnOnZoneLights(*child);
        }
    }


    <span class="comment">// A utility class to aid in sorting scene nodes into a distance order</span>
    <span class="keyword">class </span>LightDistanceElement
    {
    <span class="keyword">public</span>:
        LightDistanceElement() {};

        LightDistanceElement(scene::ISceneNode* n, <a class="code" href="namespaceirr.html#a1325b02603ad449f92c68fc640af9b28" title="64 bit floating point variable.">f64</a> d)
            : node(n), distance(d) { }

        scene::ISceneNode* node;
        <a class="code" href="namespaceirr.html#a1325b02603ad449f92c68fc640af9b28" title="64 bit floating point variable.">f64</a> distance;

        <span class="comment">// Lower distance elements are sorted to the start of the array</span>
        <span class="keywordtype">bool</span> operator &lt; (<span class="keyword">const</span> LightDistanceElement&amp; other)<span class="keyword"> const</span>
<span class="keyword">        </span>{
            <span class="keywordflow">return</span> (distance &lt; other.distance);
        }
    };
};
</pre></div><div class="fragment"><pre class="fragment"><span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argumentCount, <span class="keywordtype">char</span> * argumentValues[])
{
    <span class="comment">// ask user for driver</span>
    <a class="code" href="namespaceirr_1_1video.html#ae35a6de6d436c76107ad157fe42356d0" title="An enum for all types of drivers the Irrlicht Engine supports.">video::E_DRIVER_TYPE</a> driverType=driverChoiceConsole();
    <span class="keywordflow">if</span> (driverType==<a class="code" href="namespaceirr_1_1video.html#ae35a6de6d436c76107ad157fe42356d0ae685cada50f8c100403134d932d0414c" title="No driver, just for counting the elements.">video::EDT_COUNT</a>)
        <span class="keywordflow">return</span> 1;

    IrrlichtDevice *device = <a class="code" href="namespaceirr.html#abaf4d8719cc26b0d30813abf85e47c76" title="Creates an Irrlicht device. The Irrlicht device is the root object for using the engine.">createDevice</a>(driverType,
            dimension2d&lt;u32&gt;(640, 480), 32);

    <span class="keywordflow">if</span>(!device)
        <span class="keywordflow">return</span> -1;

    <a class="code" href="namespaceirr.html#a0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a> <span class="keyword">const</span> lightRadius = 60.f; <span class="comment">// Enough to reach the far side of each &#39;zone&#39;</span>

    video::IVideoDriver* driver = device-&gt;getVideoDriver();
    scene::ISceneManager* smgr = device-&gt;getSceneManager();
    gui::IGUIEnvironment* guienv = device-&gt;getGUIEnvironment();

    gui::IGUISkin* skin = guienv-&gt;getSkin();
    <span class="keywordflow">if</span> (skin)
    {
        skin-&gt;setColor(<a class="code" href="namespaceirr_1_1gui.html#abd15860fde29833c48daff5f95d5467aa03e6e93fa9356e9d8d743e6928111185" title="Text on a button.">gui::EGDC_BUTTON_TEXT</a>, video::SColor(255, 255, 255, 255));
        gui::IGUIFont* font = guienv-&gt;getFont(<span class="stringliteral">&quot;../../media/fontlucida.png&quot;</span>);
        <span class="keywordflow">if</span>(font)
            skin-&gt;setFont(font);
    }

    guienv-&gt;addStaticText(L<span class="stringliteral">&quot;1 - No light management&quot;</span>, core::rect&lt;s32&gt;(10,10,200,30));
    guienv-&gt;addStaticText(L<span class="stringliteral">&quot;2 - Closest 3 lights&quot;</span>, core::rect&lt;s32&gt;(10,30,200,50));
    guienv-&gt;addStaticText(L<span class="stringliteral">&quot;3 - Lights in zone&quot;</span>, core::rect&lt;s32&gt;(10,50,200,70));
</pre></div><p>Add several "zones". You could use this technique to light individual rooms, for example. </p>
<div class="fragment"><pre class="fragment">    <span class="keywordflow">for</span>(<a class="code" href="namespaceirr.html#a0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a> zoneX = -100.f; zoneX &lt;= 100.f; zoneX += 50.f)
        <span class="keywordflow">for</span>(<a class="code" href="namespaceirr.html#a0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a> zoneY = -60.f; zoneY &lt;= 60.f; zoneY += 60.f)
        {
            <span class="comment">// Start with an empty scene node, which we will use to represent a zone.</span>
            scene::ISceneNode * zoneRoot = smgr-&gt;addEmptySceneNode();
            zoneRoot-&gt;setPosition(<a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">vector3df</a>(zoneX, zoneY, 0));

            <span class="comment">// Each zone contains a rotating cube</span>
            scene::IMeshSceneNode * node = smgr-&gt;addCubeSceneNode(15, zoneRoot);
            scene::ISceneNodeAnimator * rotation = smgr-&gt;createRotationAnimator(<a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">vector3df</a>(0.25f, 0.5f, 0.75f));
            node-&gt;addAnimator(rotation);
            rotation-&gt;drop();

            <span class="comment">// And each cube has three lights attached to it.  The lights are attached to billboards so</span>
            <span class="comment">// that we can see where they are.  The billboards are attached to the cube, so that the</span>
            <span class="comment">// lights are indirect descendents of the same empty scene node as the cube.</span>
            scene::IBillboardSceneNode * billboard = smgr-&gt;addBillboardSceneNode(node);
            billboard-&gt;setPosition(<a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">vector3df</a>(0, -14, 30));
            billboard-&gt;setMaterialType(<a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1a1b5a814c4466aca2943ff056003a50d1" title="A transparent material.">video::EMT_TRANSPARENT_ADD_COLOR</a> );
            billboard-&gt;setMaterialTexture(0, driver-&gt;getTexture(<span class="stringliteral">&quot;../../media/particle.bmp&quot;</span>));
            billboard-&gt;setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#a8a3bc00ae8137535b9fbc5f40add70d3acea597a2692b8415486a464a7f954d34" title="Will this material be lighted? Default: true.">video::EMF_LIGHTING</a>, <span class="keyword">false</span>);
            smgr-&gt;addLightSceneNode(billboard, <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">vector3df</a>(0, 0, 0), video::SColorf(1, 0, 0), lightRadius);

            billboard = smgr-&gt;addBillboardSceneNode(node);
            billboard-&gt;setPosition(<a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">vector3df</a>(-21, -14, -21));
            billboard-&gt;setMaterialType(<a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1a1b5a814c4466aca2943ff056003a50d1" title="A transparent material.">video::EMT_TRANSPARENT_ADD_COLOR</a> );
            billboard-&gt;setMaterialTexture(0, driver-&gt;getTexture(<span class="stringliteral">&quot;../../media/particle.bmp&quot;</span>));
            billboard-&gt;setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#a8a3bc00ae8137535b9fbc5f40add70d3acea597a2692b8415486a464a7f954d34" title="Will this material be lighted? Default: true.">video::EMF_LIGHTING</a>, <span class="keyword">false</span>);
            smgr-&gt;addLightSceneNode(billboard, <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">vector3df</a>(0, 0, 0), video::SColorf(0, 1, 0), lightRadius);

            billboard = smgr-&gt;addBillboardSceneNode(node);
            billboard-&gt;setPosition(<a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">vector3df</a>(21, -14, -21));
            billboard-&gt;setMaterialType(<a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1a1b5a814c4466aca2943ff056003a50d1" title="A transparent material.">video::EMT_TRANSPARENT_ADD_COLOR</a> );
            billboard-&gt;setMaterialTexture(0, driver-&gt;getTexture(<span class="stringliteral">&quot;../../media/particle.bmp&quot;</span>));
            billboard-&gt;setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#a8a3bc00ae8137535b9fbc5f40add70d3acea597a2692b8415486a464a7f954d34" title="Will this material be lighted? Default: true.">video::EMF_LIGHTING</a>, <span class="keyword">false</span>);
            smgr-&gt;addLightSceneNode(billboard, <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">vector3df</a>(0, 0, 0), video::SColorf(0, 0, 1), lightRadius);

            <span class="comment">// Each cube also has a smaller cube rotating around it, to show that the cubes are being</span>
            <span class="comment">// lit by the lights in their &#39;zone&#39;, not just lights that are their direct children.</span>
            node = smgr-&gt;addCubeSceneNode(5, node);
            node-&gt;setPosition(<a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">vector3df</a>(0, 21, 0));
        }

    smgr-&gt;addCameraSceneNode(0, <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">vector3df</a>(0,0,-130), <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">vector3df</a>(0,0,0));

    CMyLightManager * myLightManager = <span class="keyword">new</span> CMyLightManager(smgr);
    smgr-&gt;setLightManager(0); <span class="comment">// This is the default: we won&#39;t do light management until told to do it.</span>
    device-&gt;setEventReceiver(myLightManager);

    <span class="keywordtype">int</span> lastFps = -1;

    <span class="keywordflow">while</span>(device-&gt;run())
    {
        driver-&gt;beginScene(<span class="keyword">true</span>, <span class="keyword">true</span>, video::SColor(255,100,101,140));
        smgr-&gt;drawAll();
        guienv-&gt;drawAll();
        driver-&gt;endScene();

        <span class="keywordtype">int</span> fps = driver-&gt;getFPS();
        <span class="keywordflow">if</span>(fps != lastFps)
        {
            lastFps = fps;
            <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">core::stringw</a> str = L<span class="stringliteral">&quot;Managed Lights [&quot;</span>;
            str += driver-&gt;getName();
            str += <span class="stringliteral">&quot;] FPS:&quot;</span>;
            str += fps;
            device-&gt;setWindowCaption(str.c_str());
        }
    }

    myLightManager-&gt;drop(); <span class="comment">// Drop my implicit reference</span>
    device-&gt;drop();
    <span class="keywordflow">return</span> 0;
}
</pre></div> </div></div>
</div>
  <div id="nav-path" class="navpath">
    <ul>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Namespaces</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(9)"><span class="SelectionMark">&#160;</span>Friends</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(10)"><span class="SelectionMark">&#160;</span>Defines</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>


    <li class="footer">
<a href="http://irrlicht.sourceforge.net" target="_blank">Irrlicht 
Engine</a> Documentation &copy; 2003-2012 by Nikolaus Gebhardt. Generated on Sun Nov 17 2013 20:18:41 for Irrlicht 3D Engine by
<a href="http://www.doxygen.org/index.html" target="_blank">Doxygen</a> 1.7.5.1 </li>
   </ul>
 </div>


</body>
</html>