aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/irrlicht-1.8/doc/html/example011.html
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/irrlicht-1.8/doc/html/example011.html')
-rw-r--r--libraries/irrlicht-1.8/doc/html/example011.html483
1 files changed, 0 insertions, 483 deletions
diff --git a/libraries/irrlicht-1.8/doc/html/example011.html b/libraries/irrlicht-1.8/doc/html/example011.html
deleted file mode 100644
index 1706066..0000000
--- a/libraries/irrlicht-1.8/doc/html/example011.html
+++ /dev/null
@@ -1,483 +0,0 @@
1<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2<html xmlns="http://www.w3.org/1999/xhtml">
3<head>
4<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
5<title>Irrlicht 3D Engine: Tutorial 11: Per-Pixel Lighting</title>
6
7<link href="tabs.css" rel="stylesheet" type="text/css"/>
8<link href="doxygen.css" rel="stylesheet" type="text/css" />
9<link href="navtree.css" rel="stylesheet" type="text/css"/>
10<script type="text/javascript" src="jquery.js"></script>
11<script type="text/javascript" src="resize.js"></script>
12<script type="text/javascript" src="navtree.js"></script>
13<script type="text/javascript">
14 $(document).ready(initResizable);
15</script>
16<link href="search/search.css" rel="stylesheet" type="text/css"/>
17<script type="text/javascript" src="search/search.js"></script>
18<script type="text/javascript">
19 $(document).ready(function() { searchBox.OnSelectItem(0); });
20</script>
21
22</head>
23<body>
24<div id="top"><!-- do not remove this div! -->
25
26
27<div id="titlearea">
28<table cellspacing="0" cellpadding="0">
29 <tbody>
30 <tr style="height: 56px;">
31
32 <td id="projectlogo"><img alt="Logo" src="irrlichtlogo.png"/></td>
33
34
35 <td style="padding-left: 0.5em;">
36 <div id="projectname">Irrlicht 3D Engine
37
38 </div>
39
40 </td>
41
42
43
44
45 <td> <div id="MSearchBox" class="MSearchBoxInactive">
46 <span class="left">
47 <img id="MSearchSelect" src="search/mag_sel.png"
48 onmouseover="return searchBox.OnSearchSelectShow()"
49 onmouseout="return searchBox.OnSearchSelectHide()"
50 alt=""/>
51 <input type="text" id="MSearchField" value="Search" accesskey="S"
52 onfocus="searchBox.OnSearchFieldFocus(true)"
53 onblur="searchBox.OnSearchFieldFocus(false)"
54 onkeyup="searchBox.OnSearchFieldChange(event)"/>
55 </span><span class="right">
56 <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
57 </span>
58 </div>
59</td>
60
61
62 </tr>
63 </tbody>
64</table>
65</div>
66
67<!-- Generated by Doxygen 1.7.5.1 -->
68<script type="text/javascript">
69var searchBox = new SearchBox("searchBox", "search",false,'Search');
70</script>
71<script type="text/javascript" src="dynsections.js"></script>
72</div>
73<div id="side-nav" class="ui-resizable side-nav-resizable">
74 <div id="nav-tree">
75 <div id="nav-tree-contents">
76 </div>
77 </div>
78 <div id="splitbar" style="-moz-user-select:none;"
79 class="ui-resizable-handle">
80 </div>
81</div>
82<script type="text/javascript">
83 initNavTree('example011.html','');
84</script>
85<div id="doc-content">
86<div class="header">
87 <div class="headertitle">
88<div class="title">Tutorial 11: Per-Pixel Lighting </div> </div>
89</div>
90<div class="contents">
91<div class="textblock"><div class="image">
92<img src="011shot.jpg" alt="011shot.jpg"/>
93</div>
94 <p>This tutorial shows how to use one of the built in more complex materials in irrlicht: Per pixel lighted surfaces using normal maps and parallax mapping. It will also show how to use fog and moving particle systems. And don't panic: You do not need any experience with shaders to use these materials in Irrlicht.</p>
95<p>At first, we need to include all headers and do the stuff we always do, like in nearly all other tutorials. </p>
96<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>
97<span class="preprocessor">#include &quot;<a class="code" href="driver_choice_8h.html">driverChoice.h</a>&quot;</span>
98
99<span class="keyword">using namespace </span>irr;
100
101<span class="preprocessor">#ifdef _MSC_VER</span>
102<span class="preprocessor"></span><span class="preprocessor">#pragma comment(lib, &quot;Irrlicht.lib&quot;)</span>
103<span class="preprocessor">#endif</span>
104</pre></div><p>For this example, we need an event receiver, to make it possible for the user to switch between the three available material types. In addition, the event receiver will create some small GUI window which displays what material is currently being used. There is nothing special done in this class, so maybe you want to skip reading it. </p>
105<div class="fragment"><pre class="fragment"><span class="keyword">class </span>MyEventReceiver : <span class="keyword">public</span> IEventReceiver
106{
107<span class="keyword">public</span>:
108
109 MyEventReceiver(scene::ISceneNode* room,scene::ISceneNode* earth,
110 gui::IGUIEnvironment* env, video::IVideoDriver* driver)
111 {
112 <span class="comment">// store pointer to room so we can change its drawing mode</span>
113 Room = room;
114 Earth = earth;
115 Driver = driver;
116
117 <span class="comment">// set a nicer font</span>
118 gui::IGUISkin* skin = env-&gt;getSkin();
119 gui::IGUIFont* font = env-&gt;getFont(<span class="stringliteral">&quot;../../media/fonthaettenschweiler.bmp&quot;</span>);
120 <span class="keywordflow">if</span> (font)
121 skin-&gt;setFont(font);
122
123 <span class="comment">// add window and listbox</span>
124 gui::IGUIWindow* window = env-&gt;addWindow(
125 core::rect&lt;s32&gt;(460,375,630,470), <span class="keyword">false</span>, L<span class="stringliteral">&quot;Use &#39;E&#39; + &#39;R&#39; to change&quot;</span>);
126
127 ListBox = env-&gt;addListBox(
128 core::rect&lt;s32&gt;(2,22,165,88), window);
129
130 ListBox-&gt;addItem(L<span class="stringliteral">&quot;Diffuse&quot;</span>);
131 ListBox-&gt;addItem(L<span class="stringliteral">&quot;Bump mapping&quot;</span>);
132 ListBox-&gt;addItem(L<span class="stringliteral">&quot;Parallax mapping&quot;</span>);
133 ListBox-&gt;setSelected(1);
134
135 <span class="comment">// create problem text</span>
136 ProblemText = env-&gt;addStaticText(
137 L<span class="stringliteral">&quot;Your hardware or this renderer is not able to use the &quot;</span>\
138 L<span class="stringliteral">&quot;needed shaders for this material. Using fall back materials.&quot;</span>,
139 core::rect&lt;s32&gt;(150,20,470,80));
140
141 ProblemText-&gt;setOverrideColor(video::SColor(100,255,255,255));
142
143 <span class="comment">// set start material (prefer parallax mapping if available)</span>
144 video::IMaterialRenderer* renderer =
145 Driver-&gt;getMaterialRenderer(<a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1a833aaad409476c3c4baf59e2d1096f4a" title="Just like EMT_NORMAL_MAP_SOLID, but uses parallax mapping.">video::EMT_PARALLAX_MAP_SOLID</a>);
146 <span class="keywordflow">if</span> (renderer &amp;&amp; renderer-&gt;getRenderCapability() == 0)
147 ListBox-&gt;setSelected(2);
148
149 <span class="comment">// set the material which is selected in the listbox</span>
150 setMaterial();
151 }
152
153 <span class="keywordtype">bool</span> OnEvent(<span class="keyword">const</span> SEvent&amp; event)
154 {
155 <span class="comment">// check if user presses the key &#39;E&#39; or &#39;R&#39;</span>
156 <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;
157 !event.KeyInput.PressedDown &amp;&amp; Room &amp;&amp; ListBox)
158 {
159 <span class="comment">// change selected item in listbox</span>
160
161 <span class="keywordtype">int</span> sel = ListBox-&gt;getSelected();
162 <span class="keywordflow">if</span> (event.KeyInput.Key == <a class="code" href="namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3a69dba8cbd4fc6825c6ac18ebe13c6eba">irr::KEY_KEY_R</a>)
163 ++sel;
164 <span class="keywordflow">else</span>
165 <span class="keywordflow">if</span> (event.KeyInput.Key == <a class="code" href="namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3af378ce3d6f5cbd09a1ae4ec8f44a0079">irr::KEY_KEY_E</a>)
166 --sel;
167 <span class="keywordflow">else</span>
168 <span class="keywordflow">return</span> <span class="keyword">false</span>;
169
170 <span class="keywordflow">if</span> (sel &gt; 2) sel = 0;
171 <span class="keywordflow">if</span> (sel &lt; 0) sel = 2;
172 ListBox-&gt;setSelected(sel);
173
174 <span class="comment">// set the material which is selected in the listbox</span>
175 setMaterial();
176 }
177
178 <span class="keywordflow">return</span> <span class="keyword">false</span>;
179 }
180
181<span class="keyword">private</span>:
182
183 <span class="comment">// sets the material of the room mesh the the one set in the</span>
184 <span class="comment">// list box.</span>
185 <span class="keywordtype">void</span> setMaterial()
186 {
187 <a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1" title="Abstracted and easy to use fixed function/programmable pipeline material modes.">video::E_MATERIAL_TYPE</a> type = <a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1a9bc471b9c18c9e2d20496004d2a2e803" title="Standard solid material.">video::EMT_SOLID</a>;
188
189 <span class="comment">// change material setting</span>
190 <span class="keywordflow">switch</span>(ListBox-&gt;getSelected())
191 {
192 <span class="keywordflow">case</span> 0: type = <a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1a9bc471b9c18c9e2d20496004d2a2e803" title="Standard solid material.">video::EMT_SOLID</a>;
193 <span class="keywordflow">break</span>;
194 <span class="keywordflow">case</span> 1: type = <a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1a89220ece17ea7d54a530de9756734c70" title="A solid normal map renderer.">video::EMT_NORMAL_MAP_SOLID</a>;
195 <span class="keywordflow">break</span>;
196 <span class="keywordflow">case</span> 2: type = <a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1a833aaad409476c3c4baf59e2d1096f4a" title="Just like EMT_NORMAL_MAP_SOLID, but uses parallax mapping.">video::EMT_PARALLAX_MAP_SOLID</a>;
197 <span class="keywordflow">break</span>;
198 }
199
200 Room-&gt;setMaterialType(type);
201
202 <span class="comment">// change material setting</span>
203 <span class="keywordflow">switch</span>(ListBox-&gt;getSelected())
204 {
205 <span class="keywordflow">case</span> 0: type = <a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1a26529b1cf18ec4d8073809f6bd15ebbb" title="Makes the material transparent based on the vertex alpha value.">video::EMT_TRANSPARENT_VERTEX_ALPHA</a>;
206 <span class="keywordflow">break</span>;
207 <span class="keywordflow">case</span> 1: type = <a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1a0d6f6973795d52d137955699537565db" title="A transparent (based on the vertex alpha value) normal map renderer.">video::EMT_NORMAL_MAP_TRANSPARENT_VERTEX_ALPHA</a>;
208 <span class="keywordflow">break</span>;
209 <span class="keywordflow">case</span> 2: type = <a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1a4c3e6b604a6d0fc5dffec661f470c11a" title="A material like EMT_PARALLAX_MAP_SOLID, but transparent.">video::EMT_PARALLAX_MAP_TRANSPARENT_VERTEX_ALPHA</a>;
210 <span class="keywordflow">break</span>;
211 }
212
213 Earth-&gt;setMaterialType(type);
214</pre></div><p>We need to add a warning if the materials will not be able to be displayed 100% correctly. This is no problem, they will be rendered using fall back materials, but at least the user should know that it would look better on better hardware. We simply check if the material renderer is able to draw at full quality on the current hardware. The IMaterialRenderer::getRenderCapability() returns 0 if this is the case. </p>
215<div class="fragment"><pre class="fragment"> video::IMaterialRenderer* renderer = Driver-&gt;getMaterialRenderer(type);
216
217 <span class="comment">// display some problem text when problem</span>
218 <span class="keywordflow">if</span> (!renderer || renderer-&gt;getRenderCapability() != 0)
219 ProblemText-&gt;setVisible(<span class="keyword">true</span>);
220 <span class="keywordflow">else</span>
221 ProblemText-&gt;setVisible(<span class="keyword">false</span>);
222 }
223
224<span class="keyword">private</span>:
225
226 gui::IGUIStaticText* ProblemText;
227 gui::IGUIListBox* ListBox;
228
229 scene::ISceneNode* Room;
230 scene::ISceneNode* Earth;
231 video::IVideoDriver* Driver;
232};
233</pre></div><p>Now for the real fun. We create an Irrlicht Device and start to setup the scene. </p>
234<div class="fragment"><pre class="fragment"><span class="keywordtype">int</span> main()
235{
236 <span class="comment">// ask user for driver</span>
237 <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();
238 <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>)
239 <span class="keywordflow">return</span> 1;
240
241 <span class="comment">// create device</span>
242
243 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,
244 core::dimension2d&lt;u32&gt;(640, 480));
245
246 <span class="keywordflow">if</span> (device == 0)
247 <span class="keywordflow">return</span> 1; <span class="comment">// could not create selected driver.</span>
248</pre></div><p>Before we start with the interesting stuff, we do some simple things: Store pointers to the most important parts of the engine (video driver, scene manager, gui environment) to safe us from typing too much, add an irrlicht engine logo to the window and a user controlled first person shooter style camera. Also, we let the engine know that it should store all textures in 32 bit. This necessary because for parallax mapping, we need 32 bit textures. </p>
249<div class="fragment"><pre class="fragment"> video::IVideoDriver* driver = device-&gt;getVideoDriver();
250 scene::ISceneManager* smgr = device-&gt;getSceneManager();
251 gui::IGUIEnvironment* env = device-&gt;getGUIEnvironment();
252
253 driver-&gt;setTextureCreationFlag(<a class="code" href="namespaceirr_1_1video.html#acaf6f7414534f7d62bff18c5bf11876fa20881e307a778c4a4fbb5327a60a93bb">video::ETCF_ALWAYS_32_BIT</a>, <span class="keyword">true</span>);
254
255 <span class="comment">// add irrlicht logo</span>
256 env-&gt;addImage(driver-&gt;getTexture(<span class="stringliteral">&quot;../../media/irrlichtlogo3.png&quot;</span>),
257 core::position2d&lt;s32&gt;(10,10));
258
259 <span class="comment">// add camera</span>
260 scene::ICameraSceneNode* camera = smgr-&gt;addCameraSceneNodeFPS();
261 camera-&gt;setPosition(<a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(-200,200,-200));
262
263 <span class="comment">// disable mouse cursor</span>
264 device-&gt;getCursorControl()-&gt;setVisible(<span class="keyword">false</span>);
265</pre></div><p>Because we want the whole scene to look a little bit scarier, we add some fog to it. This is done by a call to IVideoDriver::setFog(). There you can set various fog settings. In this example, we use pixel fog, because it will work well with the materials we'll use in this example. Please note that you will have to set the material flag EMF_FOG_ENABLE to 'true' in every scene node which should be affected by this fog. </p>
266<div class="fragment"><pre class="fragment"> driver-&gt;setFog(video::SColor(0,138,125,81), <a class="code" href="namespaceirr_1_1video.html#adf41b1a85e067f5988ba1eb8bb50f44ea998abcfd4824aaf15a95678bb444ef65">video::EFT_FOG_LINEAR</a>, 250, 1000, .003f, <span class="keyword">true</span>, <span class="keyword">false</span>);
267</pre></div><p>To be able to display something interesting, we load a mesh from a .3ds file which is a room I modeled with anim8or. It is the same room as from the specialFX example. Maybe you remember from that tutorial, I am no good modeler at all and so I totally messed up the texture mapping in this model, but we can simply repair it with the IMeshManipulator::makePlanarTextureMapping() method. </p>
268<div class="fragment"><pre class="fragment"> scene::IAnimatedMesh* roomMesh = smgr-&gt;getMesh(<span class="stringliteral">&quot;../../media/room.3ds&quot;</span>);
269 scene::ISceneNode* room = 0;
270 scene::ISceneNode* earth = 0;
271
272 <span class="keywordflow">if</span> (roomMesh)
273 {
274 <span class="comment">// The Room mesh doesn&#39;t have proper Texture Mapping on the</span>
275 <span class="comment">// floor, so we can recreate them on runtime</span>
276 smgr-&gt;getMeshManipulator()-&gt;makePlanarTextureMapping(
277 roomMesh-&gt;getMesh(0), 0.003f);
278</pre></div><p>Now for the first exciting thing: If we successfully loaded the mesh we need to apply textures to it. Because we want this room to be displayed with a very cool material, we have to do a little bit more than just set the textures. Instead of only loading a color map as usual, we also load a height map which is simply a grayscale texture. From this height map, we create a normal map which we will set as second texture of the room. If you already have a normal map, you could directly set it, but I simply didn't find a nice normal map for this texture. The normal map texture is being generated by the makeNormalMapTexture method of the VideoDriver. The second parameter specifies the height of the heightmap. If you set it to a bigger value, the map will look more rocky. </p>
279<div class="fragment"><pre class="fragment"> video::ITexture* normalMap =
280 driver-&gt;getTexture(<span class="stringliteral">&quot;../../media/rockwall_height.bmp&quot;</span>);
281
282 <span class="keywordflow">if</span> (normalMap)
283 driver-&gt;makeNormalMapTexture(normalMap, 9.0f);
284</pre></div><p>The Normal Map and the displacement map/height map in the alpha channel video::ITexture* normalMap = driver-&gt;getTexture("../../media/rockwall_NRM.tga"); </p>
285<div class="fragment"><pre class="fragment"></pre></div><p>But just setting color and normal map is not everything. The material we want to use needs some additional informations per vertex like tangents and binormals. Because we are too lazy to calculate that information now, we let Irrlicht do this for us. That's why we call IMeshManipulator::createMeshWithTangents(). It creates a mesh copy with tangents and binormals from another mesh. After we've done that, we simply create a standard mesh scene node with this mesh copy, set color and normal map and adjust some other material settings. Note that we set EMF_FOG_ENABLE to true to enable fog in the room. </p>
286<div class="fragment"><pre class="fragment"> scene::IMesh* tangentMesh = smgr-&gt;getMeshManipulator()-&gt;
287 createMeshWithTangents(roomMesh-&gt;getMesh(0));
288
289 room = smgr-&gt;addMeshSceneNode(tangentMesh);
290 room-&gt;setMaterialTexture(0,
291 driver-&gt;getTexture(<span class="stringliteral">&quot;../../media/rockwall.jpg&quot;</span>));
292 room-&gt;setMaterialTexture(1, normalMap);
293
294 <span class="comment">// Stones don&#39;t glitter..</span>
295 room-&gt;getMaterial(0).SpecularColor.set(0,0,0,0);
296 room-&gt;getMaterial(0).Shininess = 0.f;
297
298 room-&gt;setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#a8a3bc00ae8137535b9fbc5f40add70d3a5b898e76a9f5e5cfb9c27bee1fbc38be" title="Is fog enabled? Default: false.">video::EMF_FOG_ENABLE</a>, <span class="keyword">true</span>);
299 room-&gt;setMaterialType(<a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1a833aaad409476c3c4baf59e2d1096f4a" title="Just like EMT_NORMAL_MAP_SOLID, but uses parallax mapping.">video::EMT_PARALLAX_MAP_SOLID</a>);
300 <span class="comment">// adjust height for parallax effect</span>
301 room-&gt;getMaterial(0).MaterialTypeParam = 1.f / 64.f;
302
303 <span class="comment">// drop mesh because we created it with a create.. call.</span>
304 tangentMesh-&gt;drop();
305 }
306</pre></div><p>After we've created a room shaded by per pixel lighting, we add a sphere into it with the same material, but we'll make it transparent. In addition, because the sphere looks somehow like a familiar planet, we make it rotate. The procedure is similar as before. The difference is that we are loading the mesh from an .x file which already contains a color map so we do not need to load it manually. But the sphere is a little bit too small for our needs, so we scale it by the factor 50. </p>
307<div class="fragment"><pre class="fragment"> <span class="comment">// add earth sphere</span>
308
309 scene::IAnimatedMesh* earthMesh = smgr-&gt;getMesh(<span class="stringliteral">&quot;../../media/earth.x&quot;</span>);
310 <span class="keywordflow">if</span> (earthMesh)
311 {
312 <span class="comment">//perform various task with the mesh manipulator</span>
313 scene::IMeshManipulator *manipulator = smgr-&gt;getMeshManipulator();
314
315 <span class="comment">// create mesh copy with tangent informations from original earth.x mesh</span>
316 scene::IMesh* tangentSphereMesh =
317 manipulator-&gt;createMeshWithTangents(earthMesh-&gt;getMesh(0));
318
319 <span class="comment">// set the alpha value of all vertices to 200</span>
320 manipulator-&gt;setVertexColorAlpha(tangentSphereMesh, 200);
321
322 <span class="comment">// scale the mesh by factor 50</span>
323 <a class="code" href="namespaceirr_1_1core.html#a73fa92e638c5ca97efd72da307cc9b65" title="Typedef for f32 matrix.">core::matrix4</a> m;
324 m.setScale ( <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(50,50,50) );
325 manipulator-&gt;transform( tangentSphereMesh, m );
326
327 earth = smgr-&gt;addMeshSceneNode(tangentSphereMesh);
328
329 earth-&gt;setPosition(<a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(-70,130,45));
330
331 <span class="comment">// load heightmap, create normal map from it and set it</span>
332 video::ITexture* earthNormalMap = driver-&gt;getTexture(<span class="stringliteral">&quot;../../media/earthbump.jpg&quot;</span>);
333 <span class="keywordflow">if</span> (earthNormalMap)
334 {
335 driver-&gt;makeNormalMapTexture(earthNormalMap, 20.0f);
336 earth-&gt;setMaterialTexture(1, earthNormalMap);
337 earth-&gt;setMaterialType(<a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1a0d6f6973795d52d137955699537565db" title="A transparent (based on the vertex alpha value) normal map renderer.">video::EMT_NORMAL_MAP_TRANSPARENT_VERTEX_ALPHA</a>);
338 }
339
340 <span class="comment">// adjust material settings</span>
341 earth-&gt;setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#a8a3bc00ae8137535b9fbc5f40add70d3a5b898e76a9f5e5cfb9c27bee1fbc38be" title="Is fog enabled? Default: false.">video::EMF_FOG_ENABLE</a>, <span class="keyword">true</span>);
342
343 <span class="comment">// add rotation animator</span>
344 scene::ISceneNodeAnimator* anim =
345 smgr-&gt;createRotationAnimator(<a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(0,0.1f,0));
346 earth-&gt;addAnimator(anim);
347 anim-&gt;drop();
348
349 <span class="comment">// drop mesh because we created it with a create.. call.</span>
350 tangentSphereMesh-&gt;drop();
351 }
352</pre></div><p>Per pixel lighted materials only look cool when there are moving lights. So we add some. And because moving lights alone are so boring, we add billboards to them, and a whole particle system to one of them. We start with the first light which is red and has only the billboard attached. </p>
353<div class="fragment"><pre class="fragment"> <span class="comment">// add light 1 (more green)</span>
354 scene::ILightSceneNode* light1 =
355 smgr-&gt;addLightSceneNode(0, <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(0,0,0),
356 video::SColorf(0.5f, 1.0f, 0.5f, 0.0f), 800.0f);
357
358 light1-&gt;setDebugDataVisible ( <a class="code" href="namespaceirr_1_1scene.html#a52b664c4c988113735042b168fc32dbea19e56bb3d3b18134fa63e0529629b427" title="Show Bounding Boxes of SceneNode.">scene::EDS_BBOX</a> );
359
360
361 <span class="comment">// add fly circle animator to light 1</span>
362 scene::ISceneNodeAnimator* anim =
363 smgr-&gt;createFlyCircleAnimator (<a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(50,300,0),190.0f, -0.003f);
364 light1-&gt;addAnimator(anim);
365 anim-&gt;drop();
366
367 <span class="comment">// attach billboard to the light</span>
368 scene::IBillboardSceneNode* bill =
369 smgr-&gt;addBillboardSceneNode(light1, core::dimension2d&lt;f32&gt;(60, 60));
370
371 bill-&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>);
372 bill-&gt;setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#a8a3bc00ae8137535b9fbc5f40add70d3a4bc03b7b9dd19e577bf909313ea62510" title="May be written to the zbuffer or is it readonly. Default: true.">video::EMF_ZWRITE_ENABLE</a>, <span class="keyword">false</span>);
373 bill-&gt;setMaterialType(<a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1a1b5a814c4466aca2943ff056003a50d1" title="A transparent material.">video::EMT_TRANSPARENT_ADD_COLOR</a>);
374 bill-&gt;setMaterialTexture(0, driver-&gt;getTexture(<span class="stringliteral">&quot;../../media/particlegreen.jpg&quot;</span>));
375</pre></div><p>Now the same again, with the second light. The difference is that we add a particle system to it too. And because the light moves, the particles of the particlesystem will follow. If you want to know more about how particle systems are created in Irrlicht, take a look at the specialFx example. Maybe you will have noticed that we only add 2 lights, this has a simple reason: The low end version of this material was written in ps1.1 and vs1.1, which doesn't allow more lights. You could add a third light to the scene, but it won't be used to shade the walls. But of course, this will change in future versions of Irrlicht where higher versions of pixel/vertex shaders will be implemented too. </p>
376<div class="fragment"><pre class="fragment"> <span class="comment">// add light 2 (red)</span>
377 scene::ISceneNode* light2 =
378 smgr-&gt;addLightSceneNode(0, <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(0,0,0),
379 video::SColorf(1.0f, 0.2f, 0.2f, 0.0f), 800.0f);
380
381 <span class="comment">// add fly circle animator to light 2</span>
382 anim = smgr-&gt;createFlyCircleAnimator(<a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(0,150,0), 200.0f,
383 0.001f, <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(0.2f, 0.9f, 0.f));
384 light2-&gt;addAnimator(anim);
385 anim-&gt;drop();
386
387 <span class="comment">// attach billboard to light</span>
388 bill = smgr-&gt;addBillboardSceneNode(light2, core::dimension2d&lt;f32&gt;(120, 120));
389 bill-&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>);
390 bill-&gt;setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#a8a3bc00ae8137535b9fbc5f40add70d3a4bc03b7b9dd19e577bf909313ea62510" title="May be written to the zbuffer or is it readonly. Default: true.">video::EMF_ZWRITE_ENABLE</a>, <span class="keyword">false</span>);
391 bill-&gt;setMaterialType(<a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1a1b5a814c4466aca2943ff056003a50d1" title="A transparent material.">video::EMT_TRANSPARENT_ADD_COLOR</a>);
392 bill-&gt;setMaterialTexture(0, driver-&gt;getTexture(<span class="stringliteral">&quot;../../media/particlered.bmp&quot;</span>));
393
394 <span class="comment">// add particle system</span>
395 scene::IParticleSystemSceneNode* ps =
396 smgr-&gt;addParticleSystemSceneNode(<span class="keyword">false</span>, light2);
397
398 <span class="comment">// create and set emitter</span>
399 scene::IParticleEmitter* em = ps-&gt;createBoxEmitter(
400 core::aabbox3d&lt;f32&gt;(-3,0,-3,3,1,3),
401 <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(0.0f,0.03f,0.0f),
402 80,100,
403 video::SColor(10,255,255,255), video::SColor(10,255,255,255),
404 400,1100);
405 em-&gt;setMinStartSize(core::dimension2d&lt;f32&gt;(30.0f, 40.0f));
406 em-&gt;setMaxStartSize(core::dimension2d&lt;f32&gt;(30.0f, 40.0f));
407
408 ps-&gt;setEmitter(em);
409 em-&gt;drop();
410
411 <span class="comment">// create and set affector</span>
412 scene::IParticleAffector* paf = ps-&gt;createFadeOutParticleAffector();
413 ps-&gt;addAffector(paf);
414 paf-&gt;drop();
415
416 <span class="comment">// adjust some material settings</span>
417 ps-&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>);
418 ps-&gt;setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#a8a3bc00ae8137535b9fbc5f40add70d3a4bc03b7b9dd19e577bf909313ea62510" title="May be written to the zbuffer or is it readonly. Default: true.">video::EMF_ZWRITE_ENABLE</a>, <span class="keyword">false</span>);
419 ps-&gt;setMaterialTexture(0, driver-&gt;getTexture(<span class="stringliteral">&quot;../../media/fireball.bmp&quot;</span>));
420 ps-&gt;setMaterialType(<a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1a1b5a814c4466aca2943ff056003a50d1" title="A transparent material.">video::EMT_TRANSPARENT_ADD_COLOR</a>);
421
422 MyEventReceiver receiver(room, earth, env, driver);
423 device-&gt;setEventReceiver(&amp;receiver);
424</pre></div><p>Finally, draw everything. That's it. </p>
425<div class="fragment"><pre class="fragment"> <span class="keywordtype">int</span> lastFPS = -1;
426
427 <span class="keywordflow">while</span>(device-&gt;run())
428 <span class="keywordflow">if</span> (device-&gt;isWindowActive())
429 {
430 driver-&gt;beginScene(<span class="keyword">true</span>, <span class="keyword">true</span>, 0);
431
432 smgr-&gt;drawAll();
433 env-&gt;drawAll();
434
435 driver-&gt;endScene();
436
437 <span class="keywordtype">int</span> fps = driver-&gt;getFPS();
438
439 <span class="keywordflow">if</span> (lastFPS != fps)
440 {
441 <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">core::stringw</a> str = L<span class="stringliteral">&quot;Per pixel lighting example - Irrlicht Engine [&quot;</span>;
442 str += driver-&gt;getName();
443 str += <span class="stringliteral">&quot;] FPS:&quot;</span>;
444 str += fps;
445
446 device-&gt;setWindowCaption(str.c_str());
447 lastFPS = fps;
448 }
449 }
450
451 device-&gt;drop();
452
453 <span class="keywordflow">return</span> 0;
454}
455</pre></div> </div></div>
456</div>
457 <div id="nav-path" class="navpath">
458 <ul>
459<!-- window showing the filter options -->
460<div id="MSearchSelectWindow"
461 onmouseover="return searchBox.OnSearchSelectShow()"
462 onmouseout="return searchBox.OnSearchSelectHide()"
463 onkeydown="return searchBox.OnSearchSelectKey(event)">
464<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>
465
466<!-- iframe showing the search results (closed by default) -->
467<div id="MSearchResultsWindow">
468<iframe src="javascript:void(0)" frameborder="0"
469 name="MSearchResults" id="MSearchResults">
470</iframe>
471</div>
472
473
474 <li class="footer">
475<a href="http://irrlicht.sourceforge.net" target="_blank">Irrlicht
476Engine</a> Documentation &copy; 2003-2012 by Nikolaus Gebhardt. Generated on Tue Nov 6 2012 11:06:01 for Irrlicht 3D Engine by
477<a href="http://www.doxygen.org/index.html" target="_blank">Doxygen</a> 1.7.5.1 </li>
478 </ul>
479 </div>
480
481
482</body>
483</html>