aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/others/irrlicht-1.8.1/doc/html/example009.html
diff options
context:
space:
mode:
Diffstat (limited to 'src/others/irrlicht-1.8.1/doc/html/example009.html')
-rw-r--r--src/others/irrlicht-1.8.1/doc/html/example009.html1043
1 files changed, 1043 insertions, 0 deletions
diff --git a/src/others/irrlicht-1.8.1/doc/html/example009.html b/src/others/irrlicht-1.8.1/doc/html/example009.html
new file mode 100644
index 0000000..5b228eb
--- /dev/null
+++ b/src/others/irrlicht-1.8.1/doc/html/example009.html
@@ -0,0 +1,1043 @@
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 9: Mesh Viewer</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('example009.html','');
84</script>
85<div id="doc-content">
86<div class="header">
87 <div class="headertitle">
88<div class="title">Tutorial 9: Mesh Viewer </div> </div>
89</div>
90<div class="contents">
91<div class="textblock"><div class="image">
92<img src="009shot.jpg" alt="009shot.jpg"/>
93</div>
94 <p>This tutorial show how to create a more complex application with the engine. We construct a simple mesh viewer using the user interface API and the scene management of Irrlicht. The tutorial show how to create and use Buttons, Windows, Toolbars, Menus, ComboBoxes, Tabcontrols, Editboxes, Images, MessageBoxes, SkyBoxes, and how to parse XML files with the integrated XML reader of the engine.</p>
95<p>We start like in most other tutorials: Include all necessary header files, add a comment to let the engine be linked with the right .lib file in Visual Studio, and declare some global variables. We also add two 'using namespace' statements, so we do not need to write the whole names of all classes. In this tutorial, we use a lot stuff from the gui namespace. </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<span class="keyword">using namespace </span>gui;
101
102<span class="preprocessor">#ifdef _MSC_VER</span>
103<span class="preprocessor"></span><span class="preprocessor">#pragma comment(lib, &quot;Irrlicht.lib&quot;)</span>
104<span class="preprocessor">#endif</span>
105</pre></div><p>Some global variables used later on </p>
106<div class="fragment"><pre class="fragment">IrrlichtDevice *Device = 0;
107<a class="code" href="namespaceirr_1_1core.html#ade1071a878633f2f6d8a75c5d11fec19" title="Typedef for character strings.">core::stringc</a> StartUpModelFile;
108<a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">core::stringw</a> MessageText;
109<a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">core::stringw</a> Caption;
110scene::ISceneNode* Model = 0;
111scene::ISceneNode* SkyBox = 0;
112<span class="keywordtype">bool</span> Octree=<span class="keyword">false</span>;
113<span class="keywordtype">bool</span> UseLight=<span class="keyword">false</span>;
114
115scene::ICameraSceneNode* Camera[2] = {0, 0};
116
117<span class="comment">// Values used to identify individual GUI elements</span>
118<span class="keyword">enum</span>
119{
120 GUI_ID_DIALOG_ROOT_WINDOW = 0x10000,
121
122 GUI_ID_X_SCALE,
123 GUI_ID_Y_SCALE,
124 GUI_ID_Z_SCALE,
125
126 GUI_ID_OPEN_MODEL,
127 GUI_ID_SET_MODEL_ARCHIVE,
128 GUI_ID_LOAD_AS_OCTREE,
129
130 GUI_ID_SKY_BOX_VISIBLE,
131 GUI_ID_TOGGLE_DEBUG_INFO,
132
133 GUI_ID_DEBUG_OFF,
134 GUI_ID_DEBUG_BOUNDING_BOX,
135 GUI_ID_DEBUG_NORMALS,
136 GUI_ID_DEBUG_SKELETON,
137 GUI_ID_DEBUG_WIRE_OVERLAY,
138 GUI_ID_DEBUG_HALF_TRANSPARENT,
139 GUI_ID_DEBUG_BUFFERS_BOUNDING_BOXES,
140 GUI_ID_DEBUG_ALL,
141
142 GUI_ID_MODEL_MATERIAL_SOLID,
143 GUI_ID_MODEL_MATERIAL_TRANSPARENT,
144 GUI_ID_MODEL_MATERIAL_REFLECTION,
145
146 GUI_ID_CAMERA_MAYA,
147 GUI_ID_CAMERA_FIRST_PERSON,
148
149 GUI_ID_POSITION_TEXT,
150
151 GUI_ID_ABOUT,
152 GUI_ID_QUIT,
153
154 GUI_ID_TEXTUREFILTER,
155 GUI_ID_SKIN_TRANSPARENCY,
156 GUI_ID_SKIN_ANIMATION_FPS,
157
158 GUI_ID_BUTTON_SET_SCALE,
159 GUI_ID_BUTTON_SCALE_MUL10,
160 GUI_ID_BUTTON_SCALE_DIV10,
161 GUI_ID_BUTTON_OPEN_MODEL,
162 GUI_ID_BUTTON_SHOW_ABOUT,
163 GUI_ID_BUTTON_SHOW_TOOLBOX,
164 GUI_ID_BUTTON_SELECT_ARCHIVE,
165
166 GUI_ID_ANIMATION_INFO,
167
168 <span class="comment">// And some magic numbers</span>
169 MAX_FRAMERATE = 80,
170 DEFAULT_FRAMERATE = 30
171};
172</pre></div><p>Toggle between various cameras </p>
173<div class="fragment"><pre class="fragment"><span class="keywordtype">void</span> setActiveCamera(scene::ICameraSceneNode* newActive)
174{
175 <span class="keywordflow">if</span> (0 == Device)
176 <span class="keywordflow">return</span>;
177
178 scene::ICameraSceneNode * active = Device-&gt;getSceneManager()-&gt;getActiveCamera();
179 active-&gt;setInputReceiverEnabled(<span class="keyword">false</span>);
180
181 newActive-&gt;setInputReceiverEnabled(<span class="keyword">true</span>);
182 Device-&gt;getSceneManager()-&gt;setActiveCamera(newActive);
183}
184</pre></div><p>Set the skin transparency by changing the alpha values of all skin-colors </p>
185<div class="fragment"><pre class="fragment"><span class="keywordtype">void</span> setSkinTransparency(<a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> alpha, <a class="code" href="classirr_1_1gui_1_1_i_g_u_i_skin.html" title="A skin modifies the look of the GUI elements.">irr::gui::IGUISkin</a> * skin)
186{
187 <span class="keywordflow">for</span> (<a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> i=0; i&lt;<a class="code" href="namespaceirr_1_1gui.html#abd15860fde29833c48daff5f95d5467aaf340f49e2e0827c0f06fdf65098554af">irr::gui::EGDC_COUNT</a> ; ++i)
188 {
189 video::SColor col = skin-&gt;<a class="code" href="classirr_1_1gui_1_1_i_g_u_i_skin.html#ad1afa2e5e34c30e0cbfb85b1dee2dbe3" title="returns default color">getColor</a>((<a class="code" href="namespaceirr_1_1gui.html#abd15860fde29833c48daff5f95d5467a" title="Enumeration for skin colors.">EGUI_DEFAULT_COLOR</a>)i);
190 col.setAlpha(alpha);
191 skin-&gt;<a class="code" href="classirr_1_1gui_1_1_i_g_u_i_skin.html#ab9782296ba881872207a0915a81d7807" title="sets a default color">setColor</a>((<a class="code" href="namespaceirr_1_1gui.html#abd15860fde29833c48daff5f95d5467a" title="Enumeration for skin colors.">EGUI_DEFAULT_COLOR</a>)i, col);
192 }
193}
194</pre></div><p>Update the display of the model scaling </p>
195<div class="fragment"><pre class="fragment"><span class="keywordtype">void</span> updateScaleInfo(scene::ISceneNode* model)
196{
197 IGUIElement* toolboxWnd = Device-&gt;getGUIEnvironment()-&gt;getRootGUIElement()-&gt;getElementFromId(GUI_ID_DIALOG_ROOT_WINDOW, <span class="keyword">true</span>);
198 <span class="keywordflow">if</span> (!toolboxWnd)
199 <span class="keywordflow">return</span>;
200 <span class="keywordflow">if</span> (!model)
201 {
202 toolboxWnd-&gt;getElementFromId(GUI_ID_X_SCALE, <span class="keyword">true</span>)-&gt;setText( L<span class="stringliteral">&quot;-&quot;</span> );
203 toolboxWnd-&gt;getElementFromId(GUI_ID_Y_SCALE, <span class="keyword">true</span>)-&gt;setText( L<span class="stringliteral">&quot;-&quot;</span> );
204 toolboxWnd-&gt;getElementFromId(GUI_ID_Z_SCALE, <span class="keyword">true</span>)-&gt;setText( L<span class="stringliteral">&quot;-&quot;</span> );
205 }
206 <span class="keywordflow">else</span>
207 {
208 <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a> scale = model-&gt;getScale();
209 toolboxWnd-&gt;getElementFromId(GUI_ID_X_SCALE, <span class="keyword">true</span>)-&gt;setText( <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">core::stringw</a>(scale.X).c_str() );
210 toolboxWnd-&gt;getElementFromId(GUI_ID_Y_SCALE, <span class="keyword">true</span>)-&gt;setText( <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">core::stringw</a>(scale.Y).c_str() );
211 toolboxWnd-&gt;getElementFromId(GUI_ID_Z_SCALE, <span class="keyword">true</span>)-&gt;setText( <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">core::stringw</a>(scale.Z).c_str() );
212 }
213}
214</pre></div><p>Function showAboutText() displays a messagebox with a caption and a message text. The texts will be stored in the MessageText and Caption variables at startup. </p>
215<div class="fragment"><pre class="fragment"><span class="keywordtype">void</span> showAboutText()
216{
217 <span class="comment">// create modal message box with the text</span>
218 <span class="comment">// loaded from the xml file.</span>
219 Device-&gt;getGUIEnvironment()-&gt;addMessageBox(
220 Caption.c_str(), MessageText.c_str());
221}
222</pre></div><p>Function loadModel() loads a model and displays it using an addAnimatedMeshSceneNode and the scene manager. Nothing difficult. It also displays a short message box, if the model could not be loaded. </p>
223<div class="fragment"><pre class="fragment"><span class="keywordtype">void</span> loadModel(<span class="keyword">const</span> <a class="code" href="namespaceirr.html#a9395eaea339bcb546b319e9c96bf7410" title="8 bit character variable.">c8</a>* fn)
224{
225 <span class="comment">// modify the name if it a .pk3 file</span>
226
227 <a class="code" href="namespaceirr_1_1io.html#ab1bdc45edb3f94d8319c02bc0f840ee1" title="Type used for all file system related strings.">io::path</a> filename(fn);
228
229 <a class="code" href="namespaceirr_1_1io.html#ab1bdc45edb3f94d8319c02bc0f840ee1" title="Type used for all file system related strings.">io::path</a> extension;
230 <a class="code" href="namespaceirr_1_1core.html#abebbe8b229dc865ebeb9bb0fd367d6ea" title="get the filename extension from a file path">core::getFileNameExtension</a>(extension, filename);
231 extension.make_lower();
232
233 <span class="comment">// if a texture is loaded apply it to the current model..</span>
234 <span class="keywordflow">if</span> (extension == <span class="stringliteral">&quot;.jpg&quot;</span> || extension == <span class="stringliteral">&quot;.pcx&quot;</span> ||
235 extension == <span class="stringliteral">&quot;.png&quot;</span> || extension == <span class="stringliteral">&quot;.ppm&quot;</span> ||
236 extension == <span class="stringliteral">&quot;.pgm&quot;</span> || extension == <span class="stringliteral">&quot;.pbm&quot;</span> ||
237 extension == <span class="stringliteral">&quot;.psd&quot;</span> || extension == <span class="stringliteral">&quot;.tga&quot;</span> ||
238 extension == <span class="stringliteral">&quot;.bmp&quot;</span> || extension == <span class="stringliteral">&quot;.wal&quot;</span> ||
239 extension == <span class="stringliteral">&quot;.rgb&quot;</span> || extension == <span class="stringliteral">&quot;.rgba&quot;</span>)
240 {
241 video::ITexture * texture =
242 Device-&gt;getVideoDriver()-&gt;getTexture( filename );
243 <span class="keywordflow">if</span> ( texture &amp;&amp; Model )
244 {
245 <span class="comment">// always reload texture</span>
246 Device-&gt;getVideoDriver()-&gt;removeTexture(texture);
247 texture = Device-&gt;getVideoDriver()-&gt;getTexture( filename );
248
249 Model-&gt;setMaterialTexture(0, texture);
250 }
251 <span class="keywordflow">return</span>;
252 }
253 <span class="comment">// if a archive is loaded add it to the FileArchive..</span>
254 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (extension == <span class="stringliteral">&quot;.pk3&quot;</span> || extension == <span class="stringliteral">&quot;.zip&quot;</span> || extension == <span class="stringliteral">&quot;.pak&quot;</span> || extension == <span class="stringliteral">&quot;.npk&quot;</span>)
255 {
256 Device-&gt;getFileSystem()-&gt;addFileArchive(filename.c_str());
257 <span class="keywordflow">return</span>;
258 }
259
260 <span class="comment">// load a model into the engine</span>
261
262 <span class="keywordflow">if</span> (Model)
263 Model-&gt;remove();
264
265 Model = 0;
266
267 <span class="keywordflow">if</span> (extension==<span class="stringliteral">&quot;.irr&quot;</span>)
268 {
269 core::array&lt;scene::ISceneNode*&gt; outNodes;
270 Device-&gt;getSceneManager()-&gt;loadScene(filename);
271 Device-&gt;getSceneManager()-&gt;getSceneNodesFromType(<a class="code" href="namespaceirr_1_1scene.html#acad3d7ef92a9807d391ba29120f3b7bda073d7fe9dfd49f24cb13bfae56d8d3b6" title="Animated Mesh Scene Node.">scene::ESNT_ANIMATED_MESH</a>, outNodes);
272 <span class="keywordflow">if</span> (outNodes.size())
273 Model = outNodes[0];
274 <span class="keywordflow">return</span>;
275 }
276
277 scene::IAnimatedMesh* m = Device-&gt;getSceneManager()-&gt;getMesh( filename.c_str() );
278
279 <span class="keywordflow">if</span> (!m)
280 {
281 <span class="comment">// model could not be loaded</span>
282
283 <span class="keywordflow">if</span> (StartUpModelFile != filename)
284 Device-&gt;getGUIEnvironment()-&gt;addMessageBox(
285 Caption.c_str(), L<span class="stringliteral">&quot;The model could not be loaded. &quot;</span> \
286 L<span class="stringliteral">&quot;Maybe it is not a supported file format.&quot;</span>);
287 <span class="keywordflow">return</span>;
288 }
289
290 <span class="comment">// set default material properties</span>
291
292 <span class="keywordflow">if</span> (Octree)
293 Model = Device-&gt;getSceneManager()-&gt;addOctreeSceneNode(m-&gt;getMesh(0));
294 <span class="keywordflow">else</span>
295 {
296 scene::IAnimatedMeshSceneNode* animModel = Device-&gt;getSceneManager()-&gt;addAnimatedMeshSceneNode(m);
297 animModel-&gt;setAnimationSpeed(30);
298 Model = animModel;
299 }
300 Model-&gt;setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#a8a3bc00ae8137535b9fbc5f40add70d3acea597a2692b8415486a464a7f954d34" title="Will this material be lighted? Default: true.">video::EMF_LIGHTING</a>, UseLight);
301 Model-&gt;setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#a8a3bc00ae8137535b9fbc5f40add70d3a3efe2d4921909a842adfc44dacc74520" title="Normalizes normals. Default: false.">video::EMF_NORMALIZE_NORMALS</a>, UseLight);
302<span class="comment">// Model-&gt;setMaterialFlag(video::EMF_BACK_FACE_CULLING, false);</span>
303 Model-&gt;setDebugDataVisible(<a class="code" href="namespaceirr_1_1scene.html#a52b664c4c988113735042b168fc32dbea25111b15f03bee9a99498737286916dc" title="No Debug Data ( Default )">scene::EDS_OFF</a>);
304
305 <span class="comment">// we need to uncheck the menu entries. would be cool to fake a menu event, but</span>
306 <span class="comment">// that&#39;s not so simple. so we do it brute force</span>
307 gui::IGUIContextMenu* menu = (gui::IGUIContextMenu*)Device-&gt;getGUIEnvironment()-&gt;getRootGUIElement()-&gt;getElementFromId(GUI_ID_TOGGLE_DEBUG_INFO, <span class="keyword">true</span>);
308 <span class="keywordflow">if</span> (menu)
309 <span class="keywordflow">for</span>(<span class="keywordtype">int</span> item = 1; item &lt; 6; ++item)
310 menu-&gt;setItemChecked(item, <span class="keyword">false</span>);
311 updateScaleInfo(Model);
312}
313</pre></div><p>Function createToolBox() creates a toolbox window. In this simple mesh viewer, this toolbox only contains a tab control with three edit boxes for changing the scale of the displayed model. </p>
314<div class="fragment"><pre class="fragment"><span class="keywordtype">void</span> createToolBox()
315{
316 <span class="comment">// remove tool box if already there</span>
317 IGUIEnvironment* env = Device-&gt;getGUIEnvironment();
318 IGUIElement* root = env-&gt;getRootGUIElement();
319 IGUIElement* e = root-&gt;getElementFromId(GUI_ID_DIALOG_ROOT_WINDOW, <span class="keyword">true</span>);
320 <span class="keywordflow">if</span> (e)
321 e-&gt;remove();
322
323 <span class="comment">// create the toolbox window</span>
324 IGUIWindow* wnd = env-&gt;addWindow(core::rect&lt;s32&gt;(600,45,800,480),
325 <span class="keyword">false</span>, L<span class="stringliteral">&quot;Toolset&quot;</span>, 0, GUI_ID_DIALOG_ROOT_WINDOW);
326
327 <span class="comment">// create tab control and tabs</span>
328 IGUITabControl* tab = env-&gt;addTabControl(
329 core::rect&lt;s32&gt;(2,20,800-602,480-7), wnd, <span class="keyword">true</span>, <span class="keyword">true</span>);
330
331 IGUITab* t1 = tab-&gt;addTab(L<span class="stringliteral">&quot;Config&quot;</span>);
332
333 <span class="comment">// add some edit boxes and a button to tab one</span>
334 env-&gt;addStaticText(L<span class="stringliteral">&quot;Scale:&quot;</span>,
335 core::rect&lt;s32&gt;(10,20,60,45), <span class="keyword">false</span>, <span class="keyword">false</span>, t1);
336 env-&gt;addStaticText(L<span class="stringliteral">&quot;X:&quot;</span>, core::rect&lt;s32&gt;(22,48,40,66), <span class="keyword">false</span>, <span class="keyword">false</span>, t1);
337 env-&gt;addEditBox(L<span class="stringliteral">&quot;1.0&quot;</span>, core::rect&lt;s32&gt;(40,46,130,66), <span class="keyword">true</span>, t1, GUI_ID_X_SCALE);
338 env-&gt;addStaticText(L<span class="stringliteral">&quot;Y:&quot;</span>, core::rect&lt;s32&gt;(22,82,40,96), <span class="keyword">false</span>, <span class="keyword">false</span>, t1);
339 env-&gt;addEditBox(L<span class="stringliteral">&quot;1.0&quot;</span>, core::rect&lt;s32&gt;(40,76,130,96), <span class="keyword">true</span>, t1, GUI_ID_Y_SCALE);
340 env-&gt;addStaticText(L<span class="stringliteral">&quot;Z:&quot;</span>, core::rect&lt;s32&gt;(22,108,40,126), <span class="keyword">false</span>, <span class="keyword">false</span>, t1);
341 env-&gt;addEditBox(L<span class="stringliteral">&quot;1.0&quot;</span>, core::rect&lt;s32&gt;(40,106,130,126), <span class="keyword">true</span>, t1, GUI_ID_Z_SCALE);
342
343 env-&gt;addButton(core::rect&lt;s32&gt;(10,134,85,165), t1, GUI_ID_BUTTON_SET_SCALE, L<span class="stringliteral">&quot;Set&quot;</span>);
344
345 <span class="comment">// quick scale buttons</span>
346 env-&gt;addButton(core::rect&lt;s32&gt;(65,20,95,40), t1, GUI_ID_BUTTON_SCALE_MUL10, L<span class="stringliteral">&quot;* 10&quot;</span>);
347 env-&gt;addButton(core::rect&lt;s32&gt;(100,20,130,40), t1, GUI_ID_BUTTON_SCALE_DIV10, L<span class="stringliteral">&quot;* 0.1&quot;</span>);
348
349 updateScaleInfo(Model);
350
351 <span class="comment">// add transparency control</span>
352 env-&gt;addStaticText(L<span class="stringliteral">&quot;GUI Transparency Control:&quot;</span>,
353 core::rect&lt;s32&gt;(10,200,150,225), <span class="keyword">true</span>, <span class="keyword">false</span>, t1);
354 IGUIScrollBar* scrollbar = env-&gt;addScrollBar(<span class="keyword">true</span>,
355 core::rect&lt;s32&gt;(10,225,150,240), t1, GUI_ID_SKIN_TRANSPARENCY);
356 scrollbar-&gt;setMax(255);
357 scrollbar-&gt;setPos(255);
358
359 <span class="comment">// add framerate control</span>
360 env-&gt;addStaticText(L<span class="stringliteral">&quot;:&quot;</span>, core::rect&lt;s32&gt;(10,240,150,265), <span class="keyword">true</span>, <span class="keyword">false</span>, t1);
361 env-&gt;addStaticText(L<span class="stringliteral">&quot;Framerate:&quot;</span>,
362 core::rect&lt;s32&gt;(12,240,75,265), <span class="keyword">false</span>, <span class="keyword">false</span>, t1);
363 <span class="comment">// current frame info</span>
364 env-&gt;addStaticText(L<span class="stringliteral">&quot;&quot;</span>, core::rect&lt;s32&gt;(75,240,200,265), <span class="keyword">false</span>, <span class="keyword">false</span>, t1,
365 GUI_ID_ANIMATION_INFO);
366 scrollbar = env-&gt;addScrollBar(<span class="keyword">true</span>,
367 core::rect&lt;s32&gt;(10,265,150,280), t1, GUI_ID_SKIN_ANIMATION_FPS);
368 scrollbar-&gt;setMax(MAX_FRAMERATE);
369 scrollbar-&gt;setMin(-MAX_FRAMERATE);
370 scrollbar-&gt;setPos(DEFAULT_FRAMERATE);
371 scrollbar-&gt;setSmallStep(1);
372}
373</pre></div><p>Function updateToolBox() is called each frame to update dynamic information in the toolbox. </p>
374<div class="fragment"><pre class="fragment"><span class="keywordtype">void</span> updateToolBox()
375{
376 IGUIEnvironment* env = Device-&gt;getGUIEnvironment();
377 IGUIElement* root = env-&gt;getRootGUIElement();
378 IGUIElement* dlg = root-&gt;getElementFromId(GUI_ID_DIALOG_ROOT_WINDOW, <span class="keyword">true</span>);
379 <span class="keywordflow">if</span> (!dlg )
380 <span class="keywordflow">return</span>;
381
382 <span class="comment">// update the info we have about the animation of the model</span>
383 IGUIStaticText * aniInfo = (IGUIStaticText *)(dlg-&gt;getElementFromId(GUI_ID_ANIMATION_INFO, <span class="keyword">true</span>));
384 <span class="keywordflow">if</span> (aniInfo)
385 {
386 <span class="keywordflow">if</span> ( Model &amp;&amp; <a class="code" href="namespaceirr_1_1scene.html#acad3d7ef92a9807d391ba29120f3b7bda073d7fe9dfd49f24cb13bfae56d8d3b6" title="Animated Mesh Scene Node.">scene::ESNT_ANIMATED_MESH</a> == Model-&gt;getType() )
387 {
388 scene::IAnimatedMeshSceneNode* animatedModel = (scene::IAnimatedMeshSceneNode*)Model;
389
390 <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">core::stringw</a> str( (<a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a>)<a class="code" href="namespaceirr_1_1core.html#a894a901069c34298987761c5f3d74f1f">core::round_</a>(animatedModel-&gt;getAnimationSpeed()) );
391 str += L<span class="stringliteral">&quot; Frame: &quot;</span>;
392 str += <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">core::stringw</a>((<a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a>)animatedModel-&gt;getFrameNr());
393 aniInfo-&gt;setText(str.c_str());
394 }
395 <span class="keywordflow">else</span>
396 aniInfo-&gt;setText(L<span class="stringliteral">&quot;&quot;</span>);
397 }
398}
399
400<span class="keywordtype">void</span> onKillFocus()
401{
402 <span class="comment">// Avoid that the FPS-camera continues moving when the user presses alt-tab while </span>
403 <span class="comment">// moving the camera. </span>
404 <span class="keyword">const</span> core::list&lt;scene::ISceneNodeAnimator*&gt;&amp; animators = Camera[1]-&gt;getAnimators();
405 core::list&lt;irr::scene::ISceneNodeAnimator*&gt;::ConstIterator iter = animators.begin();
406 <span class="keywordflow">while</span> ( iter != animators.end() )
407 {
408 <span class="keywordflow">if</span> ( (*iter)-&gt;getType() == <a class="code" href="namespaceirr_1_1scene.html#a327a1e43872705cf8f3f3342fb307d19ae40c836272ace5bf243baaca72dba55c" title="FPS camera animator.">scene::ESNAT_CAMERA_FPS</a> )
409 {
410 <span class="comment">// we send a key-down event for all keys used by this animator</span>
411 scene::ISceneNodeAnimatorCameraFPS * fpsAnimator = <span class="keyword">static_cast&lt;</span>scene::ISceneNodeAnimatorCameraFPS*<span class="keyword">&gt;</span>(*iter);
412 <span class="keyword">const</span> core::array&lt;SKeyMap&gt;&amp; keyMap = fpsAnimator-&gt;getKeyMap();
413 <span class="keywordflow">for</span> ( <a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">irr::u32</a> i=0; i&lt; keyMap.size(); ++i )
414 {
415 <a class="code" href="structirr_1_1_s_event.html" title="SEvents hold information about an event. See irr::IEventReceiver for details on event handling...">irr::SEvent</a> event;
416 <span class="keyword">event</span>.<a class="code" href="structirr_1_1_s_event.html#a8b48c016d5c20a9b0967b1ce0fb3ef15">EventType</a> = <a class="code" href="namespaceirr.html#ac9eed96e06e85ce3c86fcbbbe9e48a0ca6f90390f3147a1693e5e2e3422d6ca09" title="A key input event.">EET_KEY_INPUT_EVENT</a>;
417 <span class="keyword">event</span>.KeyInput.Key = keyMap[i].KeyCode;
418 <span class="keyword">event</span>.KeyInput.PressedDown = <span class="keyword">false</span>;
419 fpsAnimator-&gt;OnEvent(event);
420 }
421 }
422 ++iter;
423 }
424}
425</pre></div><p>Function hasModalDialog() checks if we currently have a modal dialog open. </p>
426<div class="fragment"><pre class="fragment"><span class="keywordtype">bool</span> hasModalDialog()
427{
428 <span class="keywordflow">if</span> ( !Device )
429 <span class="keywordflow">return</span> <span class="keyword">false</span>;
430 IGUIEnvironment* env = Device-&gt;getGUIEnvironment();
431 IGUIElement * focused = env-&gt;getFocus();
432 <span class="keywordflow">while</span> ( focused )
433 {
434 <span class="keywordflow">if</span> ( focused-&gt;isVisible() &amp;&amp; focused-&gt;hasType(<a class="code" href="namespaceirr_1_1gui.html#ae4d66df0ecf4117cdbcf9f22404bd254aabc2c9519ef201dce8bd898d2566e53b" title="A modal screen.">EGUIET_MODAL_SCREEN</a>) )
435 <span class="keywordflow">return</span> <span class="keyword">true</span>;
436 focused = focused-&gt;getParent();
437 }
438 <span class="keywordflow">return</span> <span class="keyword">false</span>;
439}
440</pre></div><p>To get all the events sent by the GUI Elements, we need to create an event receiver. This one is really simple. If an event occurs, it checks the id of the caller and the event type, and starts an action based on these values. For example, if a menu item with id GUI_ID_OPEN_MODEL was selected, it opens a file-open-dialog. </p>
441<div class="fragment"><pre class="fragment"><span class="keyword">class </span>MyEventReceiver : <span class="keyword">public</span> IEventReceiver
442{
443<span class="keyword">public</span>:
444 <span class="keyword">virtual</span> <span class="keywordtype">bool</span> OnEvent(<span class="keyword">const</span> SEvent&amp; event)
445 {
446 <span class="comment">// Escape swaps Camera Input</span>
447 <span class="keywordflow">if</span> (event.EventType == <a class="code" href="namespaceirr.html#ac9eed96e06e85ce3c86fcbbbe9e48a0ca6f90390f3147a1693e5e2e3422d6ca09" title="A key input event.">EET_KEY_INPUT_EVENT</a> &amp;&amp;
448 event.KeyInput.PressedDown == <span class="keyword">false</span>)
449 {
450 <span class="keywordflow">if</span> ( OnKeyUp(event.KeyInput.Key) )
451 <span class="keywordflow">return</span> <span class="keyword">true</span>;
452 }
453
454 <span class="keywordflow">if</span> (event.EventType == <a class="code" href="namespaceirr.html#ac9eed96e06e85ce3c86fcbbbe9e48a0cae85bb44dd09a29c879d64a05047fc1d2" title="An event of the graphical user interface.">EET_GUI_EVENT</a>)
455 {
456 <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> <span class="keywordtype">id</span> = <span class="keyword">event</span>.GUIEvent.Caller-&gt;getID();
457 IGUIEnvironment* env = Device-&gt;getGUIEnvironment();
458
459 <span class="keywordflow">switch</span>(event.GUIEvent.EventType)
460 {
461 <span class="keywordflow">case</span> <a class="code" href="namespaceirr_1_1gui.html#aeac71ad17341a4b6e9026ae11d576808a90e8bebdd49f2a2e451b1105a87ee7ef" title="A menu item was selected in a (context) menu.">EGET_MENU_ITEM_SELECTED</a>:
462 <span class="comment">// a menu item was clicked</span>
463 OnMenuItemSelected( (IGUIContextMenu*)event.GUIEvent.Caller );
464 <span class="keywordflow">break</span>;
465
466 <span class="keywordflow">case</span> <a class="code" href="namespaceirr_1_1gui.html#aeac71ad17341a4b6e9026ae11d576808a5b6504cf6b541d5ad95407c384632873" title="A file has been selected in the file dialog.">EGET_FILE_SELECTED</a>:
467 {
468 <span class="comment">// load the model file, selected in the file open dialog</span>
469 IGUIFileOpenDialog* dialog =
470 (IGUIFileOpenDialog*)event.GUIEvent.Caller;
471 loadModel(<a class="code" href="namespaceirr_1_1core.html#ade1071a878633f2f6d8a75c5d11fec19" title="Typedef for character strings.">core::stringc</a>(dialog-&gt;getFileName()).c_str());
472 }
473 <span class="keywordflow">break</span>;
474
475 <span class="keywordflow">case</span> <a class="code" href="namespaceirr_1_1gui.html#aeac71ad17341a4b6e9026ae11d576808a2eea536494edcde2bb2608bda9d352b2" title="A scrollbar has changed its position.">EGET_SCROLL_BAR_CHANGED</a>:
476
477 <span class="comment">// control skin transparency</span>
478 <span class="keywordflow">if</span> (<span class="keywordtype">id</span> == GUI_ID_SKIN_TRANSPARENCY)
479 {
480 <span class="keyword">const</span> <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> pos = ((IGUIScrollBar*)event.GUIEvent.Caller)-&gt;getPos();
481 setSkinTransparency(pos, env-&gt;getSkin());
482 }
483 <span class="comment">// control animation speed</span>
484 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (<span class="keywordtype">id</span> == GUI_ID_SKIN_ANIMATION_FPS)
485 {
486 <span class="keyword">const</span> <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> pos = ((IGUIScrollBar*)event.GUIEvent.Caller)-&gt;getPos();
487 <span class="keywordflow">if</span> (<a class="code" href="namespaceirr_1_1scene.html#acad3d7ef92a9807d391ba29120f3b7bda073d7fe9dfd49f24cb13bfae56d8d3b6" title="Animated Mesh Scene Node.">scene::ESNT_ANIMATED_MESH</a> == Model-&gt;getType())
488 ((scene::IAnimatedMeshSceneNode*)Model)-&gt;setAnimationSpeed((<a class="code" href="namespaceirr.html#a0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a>)pos);
489 }
490 <span class="keywordflow">break</span>;
491
492 <span class="keywordflow">case</span> <a class="code" href="namespaceirr_1_1gui.html#aeac71ad17341a4b6e9026ae11d576808aef7f9081622a71160e161c80eb07d436" title="The selection in a combo box has been changed.">EGET_COMBO_BOX_CHANGED</a>:
493
494 <span class="comment">// control anti-aliasing/filtering</span>
495 <span class="keywordflow">if</span> (<span class="keywordtype">id</span> == GUI_ID_TEXTUREFILTER)
496 {
497 OnTextureFilterSelected( (IGUIComboBox*)event.GUIEvent.Caller );
498 }
499 <span class="keywordflow">break</span>;
500
501 <span class="keywordflow">case</span> <a class="code" href="namespaceirr_1_1gui.html#aeac71ad17341a4b6e9026ae11d576808a308ee345c92444931f83e48354072d98" title="A button was clicked.">EGET_BUTTON_CLICKED</a>:
502
503 <span class="keywordflow">switch</span>(<span class="keywordtype">id</span>)
504 {
505 <span class="keywordflow">case</span> GUI_ID_BUTTON_SET_SCALE:
506 {
507 <span class="comment">// set scale</span>
508 gui::IGUIElement* root = env-&gt;getRootGUIElement();
509 <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a> scale;
510 <a class="code" href="namespaceirr_1_1core.html#ade1071a878633f2f6d8a75c5d11fec19" title="Typedef for character strings.">core::stringc</a> s;
511
512 s = root-&gt;getElementFromId(GUI_ID_X_SCALE, <span class="keyword">true</span>)-&gt;getText();
513 scale.X = (<a class="code" href="namespaceirr.html#a0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a>)atof(s.c_str());
514 s = root-&gt;getElementFromId(GUI_ID_Y_SCALE, <span class="keyword">true</span>)-&gt;getText();
515 scale.Y = (<a class="code" href="namespaceirr.html#a0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a>)atof(s.c_str());
516 s = root-&gt;getElementFromId(GUI_ID_Z_SCALE, <span class="keyword">true</span>)-&gt;getText();
517 scale.Z = (<a class="code" href="namespaceirr.html#a0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a>)atof(s.c_str());
518
519 <span class="keywordflow">if</span> (Model)
520 Model-&gt;setScale(scale);
521 updateScaleInfo(Model);
522 }
523 <span class="keywordflow">break</span>;
524 <span class="keywordflow">case</span> GUI_ID_BUTTON_SCALE_MUL10:
525 <span class="keywordflow">if</span> (Model)
526 Model-&gt;setScale(Model-&gt;getScale()*10.f);
527 updateScaleInfo(Model);
528 <span class="keywordflow">break</span>;
529 <span class="keywordflow">case</span> GUI_ID_BUTTON_SCALE_DIV10:
530 <span class="keywordflow">if</span> (Model)
531 Model-&gt;setScale(Model-&gt;getScale()*0.1f);
532 updateScaleInfo(Model);
533 <span class="keywordflow">break</span>;
534 <span class="keywordflow">case</span> GUI_ID_BUTTON_OPEN_MODEL:
535 env-&gt;addFileOpenDialog(L<span class="stringliteral">&quot;Please select a model file to open&quot;</span>);
536 <span class="keywordflow">break</span>;
537 <span class="keywordflow">case</span> GUI_ID_BUTTON_SHOW_ABOUT:
538 showAboutText();
539 <span class="keywordflow">break</span>;
540 <span class="keywordflow">case</span> GUI_ID_BUTTON_SHOW_TOOLBOX:
541 createToolBox();
542 <span class="keywordflow">break</span>;
543 <span class="keywordflow">case</span> GUI_ID_BUTTON_SELECT_ARCHIVE:
544 env-&gt;addFileOpenDialog(L<span class="stringliteral">&quot;Please select your game archive/directory&quot;</span>);
545 <span class="keywordflow">break</span>;
546 }
547
548 <span class="keywordflow">break</span>;
549 <span class="keywordflow">default</span>:
550 <span class="keywordflow">break</span>;
551 }
552 }
553
554 <span class="keywordflow">return</span> <span class="keyword">false</span>;
555 }
556</pre></div><p>Handle key-up events </p>
557<div class="fragment"><pre class="fragment"> <span class="keywordtype">bool</span> OnKeyUp(<a class="code" href="namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3">irr::EKEY_CODE</a> keyCode)
558 {
559 <span class="comment">// Don&#39;t handle keys if we have a modal dialog open as it would lead </span>
560 <span class="comment">// to unexpected application behaviour for the user.</span>
561 <span class="keywordflow">if</span> ( hasModalDialog() )
562 <span class="keywordflow">return</span> <span class="keyword">false</span>;
563
564 <span class="keywordflow">if</span> (keyCode == <a class="code" href="namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3aab32bfc194f119e5d5b9b39527bbcd61">irr::KEY_ESCAPE</a>)
565 {
566 <span class="keywordflow">if</span> (Device)
567 {
568 scene::ICameraSceneNode * camera =
569 Device-&gt;getSceneManager()-&gt;getActiveCamera();
570 <span class="keywordflow">if</span> (camera)
571 {
572 camera-&gt;setInputReceiverEnabled( !camera-&gt;isInputReceiverEnabled() );
573 }
574 <span class="keywordflow">return</span> <span class="keyword">true</span>;
575 }
576 }
577 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (keyCode == <a class="code" href="namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3a5427274e34fd5587155fe8b3b12d96a8">irr::KEY_F1</a>)
578 {
579 <span class="keywordflow">if</span> (Device)
580 {
581 IGUIElement* elem = Device-&gt;getGUIEnvironment()-&gt;getRootGUIElement()-&gt;getElementFromId(GUI_ID_POSITION_TEXT);
582 <span class="keywordflow">if</span> (elem)
583 elem-&gt;setVisible(!elem-&gt;isVisible());
584 }
585 }
586 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (keyCode == <a class="code" href="namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3a864770d5fa3f9713dc7a37f66f6b84fc">irr::KEY_KEY_M</a>)
587 {
588 <span class="keywordflow">if</span> (Device)
589 Device-&gt;minimizeWindow();
590 }
591 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (keyCode == <a class="code" href="namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3ae1f51392abd7c04d8129d2c85dbd391c">irr::KEY_KEY_L</a>)
592 {
593 UseLight=!UseLight;
594 <span class="keywordflow">if</span> (Model)
595 {
596 Model-&gt;setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#a8a3bc00ae8137535b9fbc5f40add70d3acea597a2692b8415486a464a7f954d34" title="Will this material be lighted? Default: true.">video::EMF_LIGHTING</a>, UseLight);
597 Model-&gt;setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#a8a3bc00ae8137535b9fbc5f40add70d3a3efe2d4921909a842adfc44dacc74520" title="Normalizes normals. Default: false.">video::EMF_NORMALIZE_NORMALS</a>, UseLight);
598 }
599 }
600 <span class="keywordflow">return</span> <span class="keyword">false</span>;
601 }
602</pre></div><p>Handle "menu item clicked" events. </p>
603<div class="fragment"><pre class="fragment"> <span class="keywordtype">void</span> OnMenuItemSelected( IGUIContextMenu* menu )
604 {
605 <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> <span class="keywordtype">id</span> = menu-&gt;getItemCommandId(menu-&gt;getSelectedItem());
606 IGUIEnvironment* env = Device-&gt;getGUIEnvironment();
607
608 <span class="keywordflow">switch</span>(<span class="keywordtype">id</span>)
609 {
610 <span class="keywordflow">case</span> GUI_ID_OPEN_MODEL: <span class="comment">// FilOnButtonSetScalinge -&gt; Open Model</span>
611 env-&gt;addFileOpenDialog(L<span class="stringliteral">&quot;Please select a model file to open&quot;</span>);
612 <span class="keywordflow">break</span>;
613 <span class="keywordflow">case</span> GUI_ID_SET_MODEL_ARCHIVE: <span class="comment">// File -&gt; Set Model Archive</span>
614 env-&gt;addFileOpenDialog(L<span class="stringliteral">&quot;Please select your game archive/directory&quot;</span>);
615 <span class="keywordflow">break</span>;
616 <span class="keywordflow">case</span> GUI_ID_LOAD_AS_OCTREE: <span class="comment">// File -&gt; LoadAsOctree</span>
617 Octree = !Octree;
618 menu-&gt;setItemChecked(menu-&gt;getSelectedItem(), Octree);
619 <span class="keywordflow">break</span>;
620 <span class="keywordflow">case</span> GUI_ID_QUIT: <span class="comment">// File -&gt; Quit</span>
621 Device-&gt;closeDevice();
622 <span class="keywordflow">break</span>;
623 <span class="keywordflow">case</span> GUI_ID_SKY_BOX_VISIBLE: <span class="comment">// View -&gt; Skybox</span>
624 menu-&gt;setItemChecked(menu-&gt;getSelectedItem(), !menu-&gt;isItemChecked(menu-&gt;getSelectedItem()));
625 SkyBox-&gt;setVisible(!SkyBox-&gt;isVisible());
626 <span class="keywordflow">break</span>;
627 <span class="keywordflow">case</span> GUI_ID_DEBUG_OFF: <span class="comment">// View -&gt; Debug Information</span>
628 menu-&gt;setItemChecked(menu-&gt;getSelectedItem()+1, <span class="keyword">false</span>);
629 menu-&gt;setItemChecked(menu-&gt;getSelectedItem()+2, <span class="keyword">false</span>);
630 menu-&gt;setItemChecked(menu-&gt;getSelectedItem()+3, <span class="keyword">false</span>);
631 menu-&gt;setItemChecked(menu-&gt;getSelectedItem()+4, <span class="keyword">false</span>);
632 menu-&gt;setItemChecked(menu-&gt;getSelectedItem()+5, <span class="keyword">false</span>);
633 menu-&gt;setItemChecked(menu-&gt;getSelectedItem()+6, <span class="keyword">false</span>);
634 <span class="keywordflow">if</span> (Model)
635 Model-&gt;setDebugDataVisible(<a class="code" href="namespaceirr_1_1scene.html#a52b664c4c988113735042b168fc32dbea25111b15f03bee9a99498737286916dc" title="No Debug Data ( Default )">scene::EDS_OFF</a>);
636 <span class="keywordflow">break</span>;
637 <span class="keywordflow">case</span> GUI_ID_DEBUG_BOUNDING_BOX: <span class="comment">// View -&gt; Debug Information</span>
638 menu-&gt;setItemChecked(menu-&gt;getSelectedItem(), !menu-&gt;isItemChecked(menu-&gt;getSelectedItem()));
639 <span class="keywordflow">if</span> (Model)
640 Model-&gt;setDebugDataVisible((<a class="code" href="namespaceirr_1_1scene.html#a52b664c4c988113735042b168fc32dbe" title="An enumeration for all types of debug data for built-in scene nodes (flags)">scene::E_DEBUG_SCENE_TYPE</a>)(Model-&gt;isDebugDataVisible()^<a class="code" href="namespaceirr_1_1scene.html#a52b664c4c988113735042b168fc32dbea19e56bb3d3b18134fa63e0529629b427" title="Show Bounding Boxes of SceneNode.">scene::EDS_BBOX</a>));
641 <span class="keywordflow">break</span>;
642 <span class="keywordflow">case</span> GUI_ID_DEBUG_NORMALS: <span class="comment">// View -&gt; Debug Information</span>
643 menu-&gt;setItemChecked(menu-&gt;getSelectedItem(), !menu-&gt;isItemChecked(menu-&gt;getSelectedItem()));
644 <span class="keywordflow">if</span> (Model)
645 Model-&gt;setDebugDataVisible((<a class="code" href="namespaceirr_1_1scene.html#a52b664c4c988113735042b168fc32dbe" title="An enumeration for all types of debug data for built-in scene nodes (flags)">scene::E_DEBUG_SCENE_TYPE</a>)(Model-&gt;isDebugDataVisible()^<a class="code" href="namespaceirr_1_1scene.html#a52b664c4c988113735042b168fc32dbea2713e470ee18ec9bfe40fdfb502f8b05" title="Show Vertex Normals.">scene::EDS_NORMALS</a>));
646 <span class="keywordflow">break</span>;
647 <span class="keywordflow">case</span> GUI_ID_DEBUG_SKELETON: <span class="comment">// View -&gt; Debug Information</span>
648 menu-&gt;setItemChecked(menu-&gt;getSelectedItem(), !menu-&gt;isItemChecked(menu-&gt;getSelectedItem()));
649 <span class="keywordflow">if</span> (Model)
650 Model-&gt;setDebugDataVisible((<a class="code" href="namespaceirr_1_1scene.html#a52b664c4c988113735042b168fc32dbe" title="An enumeration for all types of debug data for built-in scene nodes (flags)">scene::E_DEBUG_SCENE_TYPE</a>)(Model-&gt;isDebugDataVisible()^<a class="code" href="namespaceirr_1_1scene.html#a52b664c4c988113735042b168fc32dbeaa7664e189b8641ac54cf27f70f6d8144" title="Shows Skeleton/Tags.">scene::EDS_SKELETON</a>));
651 <span class="keywordflow">break</span>;
652 <span class="keywordflow">case</span> GUI_ID_DEBUG_WIRE_OVERLAY: <span class="comment">// View -&gt; Debug Information</span>
653 menu-&gt;setItemChecked(menu-&gt;getSelectedItem(), !menu-&gt;isItemChecked(menu-&gt;getSelectedItem()));
654 <span class="keywordflow">if</span> (Model)
655 Model-&gt;setDebugDataVisible((<a class="code" href="namespaceirr_1_1scene.html#a52b664c4c988113735042b168fc32dbe" title="An enumeration for all types of debug data for built-in scene nodes (flags)">scene::E_DEBUG_SCENE_TYPE</a>)(Model-&gt;isDebugDataVisible()^<a class="code" href="namespaceirr_1_1scene.html#a52b664c4c988113735042b168fc32dbea349b086537ac770f09935af4e31d3f3e" title="Overlays Mesh Wireframe.">scene::EDS_MESH_WIRE_OVERLAY</a>));
656 <span class="keywordflow">break</span>;
657 <span class="keywordflow">case</span> GUI_ID_DEBUG_HALF_TRANSPARENT: <span class="comment">// View -&gt; Debug Information</span>
658 menu-&gt;setItemChecked(menu-&gt;getSelectedItem(), !menu-&gt;isItemChecked(menu-&gt;getSelectedItem()));
659 <span class="keywordflow">if</span> (Model)
660 Model-&gt;setDebugDataVisible((<a class="code" href="namespaceirr_1_1scene.html#a52b664c4c988113735042b168fc32dbe" title="An enumeration for all types of debug data for built-in scene nodes (flags)">scene::E_DEBUG_SCENE_TYPE</a>)(Model-&gt;isDebugDataVisible()^<a class="code" href="namespaceirr_1_1scene.html#a52b664c4c988113735042b168fc32dbea1def9e1b7d86e286b07a4b7179e6ed85" title="Temporary use transparency Material Type.">scene::EDS_HALF_TRANSPARENCY</a>));
661 <span class="keywordflow">break</span>;
662 <span class="keywordflow">case</span> GUI_ID_DEBUG_BUFFERS_BOUNDING_BOXES: <span class="comment">// View -&gt; Debug Information</span>
663 menu-&gt;setItemChecked(menu-&gt;getSelectedItem(), !menu-&gt;isItemChecked(menu-&gt;getSelectedItem()));
664 <span class="keywordflow">if</span> (Model)
665 Model-&gt;setDebugDataVisible((<a class="code" href="namespaceirr_1_1scene.html#a52b664c4c988113735042b168fc32dbe" title="An enumeration for all types of debug data for built-in scene nodes (flags)">scene::E_DEBUG_SCENE_TYPE</a>)(Model-&gt;isDebugDataVisible()^<a class="code" href="namespaceirr_1_1scene.html#a52b664c4c988113735042b168fc32dbea0179a3df80ac09143dfffed0bd9e99d1" title="Show Bounding Boxes of all MeshBuffers.">scene::EDS_BBOX_BUFFERS</a>));
666 <span class="keywordflow">break</span>;
667 <span class="keywordflow">case</span> GUI_ID_DEBUG_ALL: <span class="comment">// View -&gt; Debug Information</span>
668 menu-&gt;setItemChecked(menu-&gt;getSelectedItem()-1, <span class="keyword">true</span>);
669 menu-&gt;setItemChecked(menu-&gt;getSelectedItem()-2, <span class="keyword">true</span>);
670 menu-&gt;setItemChecked(menu-&gt;getSelectedItem()-3, <span class="keyword">true</span>);
671 menu-&gt;setItemChecked(menu-&gt;getSelectedItem()-4, <span class="keyword">true</span>);
672 menu-&gt;setItemChecked(menu-&gt;getSelectedItem()-5, <span class="keyword">true</span>);
673 menu-&gt;setItemChecked(menu-&gt;getSelectedItem()-6, <span class="keyword">true</span>);
674 <span class="keywordflow">if</span> (Model)
675 Model-&gt;setDebugDataVisible(<a class="code" href="namespaceirr_1_1scene.html#a52b664c4c988113735042b168fc32dbea24ffe5e6e99d589b3c80181e7c7dd4e2" title="Show all debug infos.">scene::EDS_FULL</a>);
676 <span class="keywordflow">break</span>;
677 <span class="keywordflow">case</span> GUI_ID_ABOUT: <span class="comment">// Help-&gt;About</span>
678 showAboutText();
679 <span class="keywordflow">break</span>;
680 <span class="keywordflow">case</span> GUI_ID_MODEL_MATERIAL_SOLID: <span class="comment">// View -&gt; Material -&gt; Solid</span>
681 <span class="keywordflow">if</span> (Model)
682 Model-&gt;setMaterialType(<a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1a9bc471b9c18c9e2d20496004d2a2e803" title="Standard solid material.">video::EMT_SOLID</a>);
683 <span class="keywordflow">break</span>;
684 <span class="keywordflow">case</span> GUI_ID_MODEL_MATERIAL_TRANSPARENT: <span class="comment">// View -&gt; Material -&gt; Transparent</span>
685 <span class="keywordflow">if</span> (Model)
686 Model-&gt;setMaterialType(<a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1a1b5a814c4466aca2943ff056003a50d1" title="A transparent material.">video::EMT_TRANSPARENT_ADD_COLOR</a>);
687 <span class="keywordflow">break</span>;
688 <span class="keywordflow">case</span> GUI_ID_MODEL_MATERIAL_REFLECTION: <span class="comment">// View -&gt; Material -&gt; Reflection</span>
689 <span class="keywordflow">if</span> (Model)
690 Model-&gt;setMaterialType(<a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1a42a8b6f5c933864ca104b3d46692c43b" title="Look like a reflection of the environment around it.">video::EMT_SPHERE_MAP</a>);
691 <span class="keywordflow">break</span>;
692
693 <span class="keywordflow">case</span> GUI_ID_CAMERA_MAYA:
694 setActiveCamera(Camera[0]);
695 <span class="keywordflow">break</span>;
696 <span class="keywordflow">case</span> GUI_ID_CAMERA_FIRST_PERSON:
697 setActiveCamera(Camera[1]);
698 <span class="keywordflow">break</span>;
699 }
700 }
701</pre></div><p>Handle the event that one of the texture-filters was selected in the corresponding combobox. </p>
702<div class="fragment"><pre class="fragment"> <span class="keywordtype">void</span> OnTextureFilterSelected( IGUIComboBox* combo )
703 {
704 <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> pos = combo-&gt;getSelected();
705 <span class="keywordflow">switch</span> (pos)
706 {
707 <span class="keywordflow">case</span> 0:
708 <span class="keywordflow">if</span> (Model)
709 {
710 Model-&gt;setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#a8a3bc00ae8137535b9fbc5f40add70d3afbf2b289d416e70466e4ab05e97b4934" title="Is bilinear filtering enabled? Default: true.">video::EMF_BILINEAR_FILTER</a>, <span class="keyword">false</span>);
711 Model-&gt;setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#a8a3bc00ae8137535b9fbc5f40add70d3a7a2ed21d879b182fbc767a4c20d72eef" title="Is trilinear filtering enabled? Default: false.">video::EMF_TRILINEAR_FILTER</a>, <span class="keyword">false</span>);
712 Model-&gt;setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#a8a3bc00ae8137535b9fbc5f40add70d3a941c0756b9dc3f987a183a401c6fd4ad" title="Is anisotropic filtering? Default: false.">video::EMF_ANISOTROPIC_FILTER</a>, <span class="keyword">false</span>);
713 }
714 <span class="keywordflow">break</span>;
715 <span class="keywordflow">case</span> 1:
716 <span class="keywordflow">if</span> (Model)
717 {
718 Model-&gt;setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#a8a3bc00ae8137535b9fbc5f40add70d3afbf2b289d416e70466e4ab05e97b4934" title="Is bilinear filtering enabled? Default: true.">video::EMF_BILINEAR_FILTER</a>, <span class="keyword">true</span>);
719 Model-&gt;setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#a8a3bc00ae8137535b9fbc5f40add70d3a7a2ed21d879b182fbc767a4c20d72eef" title="Is trilinear filtering enabled? Default: false.">video::EMF_TRILINEAR_FILTER</a>, <span class="keyword">false</span>);
720 }
721 <span class="keywordflow">break</span>;
722 <span class="keywordflow">case</span> 2:
723 <span class="keywordflow">if</span> (Model)
724 {
725 Model-&gt;setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#a8a3bc00ae8137535b9fbc5f40add70d3afbf2b289d416e70466e4ab05e97b4934" title="Is bilinear filtering enabled? Default: true.">video::EMF_BILINEAR_FILTER</a>, <span class="keyword">false</span>);
726 Model-&gt;setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#a8a3bc00ae8137535b9fbc5f40add70d3a7a2ed21d879b182fbc767a4c20d72eef" title="Is trilinear filtering enabled? Default: false.">video::EMF_TRILINEAR_FILTER</a>, <span class="keyword">true</span>);
727 }
728 <span class="keywordflow">break</span>;
729 <span class="keywordflow">case</span> 3:
730 <span class="keywordflow">if</span> (Model)
731 {
732 Model-&gt;setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#a8a3bc00ae8137535b9fbc5f40add70d3a941c0756b9dc3f987a183a401c6fd4ad" title="Is anisotropic filtering? Default: false.">video::EMF_ANISOTROPIC_FILTER</a>, <span class="keyword">true</span>);
733 }
734 <span class="keywordflow">break</span>;
735 <span class="keywordflow">case</span> 4:
736 <span class="keywordflow">if</span> (Model)
737 {
738 Model-&gt;setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#a8a3bc00ae8137535b9fbc5f40add70d3a941c0756b9dc3f987a183a401c6fd4ad" title="Is anisotropic filtering? Default: false.">video::EMF_ANISOTROPIC_FILTER</a>, <span class="keyword">false</span>);
739 }
740 <span class="keywordflow">break</span>;
741 }
742 }
743};
744</pre></div><p>Most of the hard work is done. We only need to create the Irrlicht Engine device and all the buttons, menus and toolbars. We start up the engine as usual, using <a class="el" href="namespaceirr.html#abaf4d8719cc26b0d30813abf85e47c76" title="Creates an Irrlicht device. The Irrlicht device is the root object for using the engine.">createDevice()</a>. To make our application catch events, we set our eventreceiver as parameter. As you can see, there is also a call to IrrlichtDevice::setResizeable(). This makes the render window resizeable, which is quite useful for a mesh viewer. </p>
745<div class="fragment"><pre class="fragment"><span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span>* argv[])
746{
747 <span class="comment">// ask user for driver</span>
748 <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();
749 <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>)
750 <span class="keywordflow">return</span> 1;
751
752 <span class="comment">// create device and exit if creation failed</span>
753 MyEventReceiver receiver;
754 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, core::dimension2d&lt;u32&gt;(800, 600),
755 16, <span class="keyword">false</span>, <span class="keyword">false</span>, <span class="keyword">false</span>, &amp;receiver);
756
757 <span class="keywordflow">if</span> (Device == 0)
758 <span class="keywordflow">return</span> 1; <span class="comment">// could not create selected driver.</span>
759
760 Device-&gt;setResizable(<span class="keyword">true</span>);
761
762 Device-&gt;setWindowCaption(L<span class="stringliteral">&quot;Irrlicht Engine - Loading...&quot;</span>);
763
764 video::IVideoDriver* driver = Device-&gt;getVideoDriver();
765 IGUIEnvironment* env = Device-&gt;getGUIEnvironment();
766 scene::ISceneManager* smgr = Device-&gt;getSceneManager();
767 smgr-&gt;getParameters()-&gt;setAttribute(<a class="code" href="namespaceirr_1_1scene.html#a157681b3ef101a801ce278e6f21de946" title="Name of the parameter specifying the COLLADA mesh loading mode.">scene::COLLADA_CREATE_SCENE_INSTANCES</a>, <span class="keyword">true</span>);
768
769 driver-&gt;setTextureCreationFlag(<a class="code" href="namespaceirr_1_1video.html#acaf6f7414534f7d62bff18c5bf11876fa20881e307a778c4a4fbb5327a60a93bb">video::ETCF_ALWAYS_32_BIT</a>, <span class="keyword">true</span>);
770
771 smgr-&gt;addLightSceneNode(0, <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(200,200,200),
772 video::SColorf(1.0f,1.0f,1.0f),2000);
773 smgr-&gt;setAmbientLight(video::SColorf(0.3f,0.3f,0.3f));
774 <span class="comment">// add our media directory as &quot;search path&quot;</span>
775 Device-&gt;getFileSystem()-&gt;addFileArchive(<span class="stringliteral">&quot;../../media/&quot;</span>);
776</pre></div><p>The next step is to read the configuration file. It is stored in the xml format and looks a little bit like this:</p>
777<div class="fragment"><pre class="fragment">
778 &lt;?xml version="1.0"?&gt;
779 &lt;config&gt;
780 &lt;startUpModel file="some filename" /&gt;
781 &lt;messageText caption="Irrlicht Engine Mesh Viewer"&gt;
782 Hello!
783 &lt;/messageText&gt;
784 &lt;/config&gt;
785 </pre></div><p>We need the data stored in there to be written into the global variables StartUpModelFile, MessageText and Caption. This is now done using the Irrlicht Engine integrated XML parser: </p>
786<div class="fragment"><pre class="fragment"> <span class="comment">// read configuration from xml file</span>
787
788 <a class="code" href="namespaceirr_1_1io.html#a9dc6291fb7e4c73155a3e3c8339f9bff" title="An xml reader for wide characters, derived from IReferenceCounted.">io::IXMLReader</a>* xml = Device-&gt;getFileSystem()-&gt;createXMLReader( L<span class="stringliteral">&quot;config.xml&quot;</span>);
789
790 <span class="keywordflow">while</span>(xml &amp;&amp; xml-&gt;read())
791 {
792 <span class="keywordflow">switch</span>(xml-&gt;getNodeType())
793 {
794 <span class="keywordflow">case</span> <a class="code" href="namespaceirr_1_1io.html#a86a02676c9cbb822e04d60c81b4f33eda0edf973f8ca0f6097f69369539d432a4">io::EXN_TEXT</a>:
795 <span class="comment">// in this xml file, the only text which occurs is the</span>
796 <span class="comment">// messageText</span>
797 MessageText = xml-&gt;getNodeData();
798 <span class="keywordflow">break</span>;
799 <span class="keywordflow">case</span> <a class="code" href="namespaceirr_1_1io.html#a86a02676c9cbb822e04d60c81b4f33eda9df4f5baccc23a0ad1f6fa64d8de2fc0" title="An xml element such as &lt;foo&gt;.">io::EXN_ELEMENT</a>:
800 {
801 <span class="keywordflow">if</span> (<a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">core::stringw</a>(<span class="stringliteral">&quot;startUpModel&quot;</span>) == xml-&gt;getNodeName())
802 StartUpModelFile = xml-&gt;getAttributeValue(L<span class="stringliteral">&quot;file&quot;</span>);
803 <span class="keywordflow">else</span>
804 <span class="keywordflow">if</span> (<a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">core::stringw</a>(<span class="stringliteral">&quot;messageText&quot;</span>) == xml-&gt;getNodeName())
805 Caption = xml-&gt;getAttributeValue(L<span class="stringliteral">&quot;caption&quot;</span>);
806 }
807 <span class="keywordflow">break</span>;
808 <span class="keywordflow">default</span>:
809 <span class="keywordflow">break</span>;
810 }
811 }
812
813 <span class="keywordflow">if</span> (xml)
814 xml-&gt;drop(); <span class="comment">// don&#39;t forget to delete the xml reader</span>
815
816 <span class="keywordflow">if</span> (argc &gt; 1)
817 StartUpModelFile = argv[1];
818</pre></div><p>That wasn't difficult. Now we'll set a nicer font and create the Menu. It is possible to create submenus for every menu item. The call menu-&gt;addItem(L"File", -1, true, true); for example adds a new menu Item with the name "File" and the id -1. The following parameter says that the menu item should be enabled, and the last one says, that there should be a submenu. The submenu can now be accessed with menu-&gt;getSubMenu(0), because the "File" entry is the menu item with index 0. </p>
819<div class="fragment"><pre class="fragment"> <span class="comment">// set a nicer font</span>
820
821 IGUISkin* skin = env-&gt;getSkin();
822 IGUIFont* font = env-&gt;<a class="code" href="classirr_1_1gui_1_1_i_g_u_i_skin.html#ab1b2623d04688c4dfe106ca407171d6e" title="returns the default font">getFont</a>(<span class="stringliteral">&quot;fonthaettenschweiler.bmp&quot;</span>);
823 <span class="keywordflow">if</span> (font)
824 skin-&gt;setFont(font);
825
826 <span class="comment">// create menu</span>
827 gui::IGUIContextMenu* menu = env-&gt;addMenu();
828 menu-&gt;addItem(L<span class="stringliteral">&quot;File&quot;</span>, -1, <span class="keyword">true</span>, <span class="keyword">true</span>);
829 menu-&gt;addItem(L<span class="stringliteral">&quot;View&quot;</span>, -1, <span class="keyword">true</span>, <span class="keyword">true</span>);
830 menu-&gt;addItem(L<span class="stringliteral">&quot;Camera&quot;</span>, -1, <span class="keyword">true</span>, <span class="keyword">true</span>);
831 menu-&gt;addItem(L<span class="stringliteral">&quot;Help&quot;</span>, -1, <span class="keyword">true</span>, <span class="keyword">true</span>);
832
833 gui::IGUIContextMenu* submenu;
834 submenu = menu-&gt;getSubMenu(0);
835 submenu-&gt;addItem(L<span class="stringliteral">&quot;Open Model File &amp; Texture...&quot;</span>, GUI_ID_OPEN_MODEL);
836 submenu-&gt;addItem(L<span class="stringliteral">&quot;Set Model Archive...&quot;</span>, GUI_ID_SET_MODEL_ARCHIVE);
837 submenu-&gt;addItem(L<span class="stringliteral">&quot;Load as Octree&quot;</span>, GUI_ID_LOAD_AS_OCTREE);
838 submenu-&gt;addSeparator();
839 submenu-&gt;addItem(L<span class="stringliteral">&quot;Quit&quot;</span>, GUI_ID_QUIT);
840
841 submenu = menu-&gt;getSubMenu(1);
842 submenu-&gt;addItem(L<span class="stringliteral">&quot;sky box visible&quot;</span>, GUI_ID_SKY_BOX_VISIBLE, <span class="keyword">true</span>, <span class="keyword">false</span>, <span class="keyword">true</span>);
843 submenu-&gt;addItem(L<span class="stringliteral">&quot;toggle model debug information&quot;</span>, GUI_ID_TOGGLE_DEBUG_INFO, <span class="keyword">true</span>, <span class="keyword">true</span>);
844 submenu-&gt;addItem(L<span class="stringliteral">&quot;model material&quot;</span>, -1, <span class="keyword">true</span>, <span class="keyword">true</span> );
845
846 submenu = submenu-&gt;getSubMenu(1);
847 submenu-&gt;addItem(L<span class="stringliteral">&quot;Off&quot;</span>, GUI_ID_DEBUG_OFF);
848 submenu-&gt;addItem(L<span class="stringliteral">&quot;Bounding Box&quot;</span>, GUI_ID_DEBUG_BOUNDING_BOX);
849 submenu-&gt;addItem(L<span class="stringliteral">&quot;Normals&quot;</span>, GUI_ID_DEBUG_NORMALS);
850 submenu-&gt;addItem(L<span class="stringliteral">&quot;Skeleton&quot;</span>, GUI_ID_DEBUG_SKELETON);
851 submenu-&gt;addItem(L<span class="stringliteral">&quot;Wire overlay&quot;</span>, GUI_ID_DEBUG_WIRE_OVERLAY);
852 submenu-&gt;addItem(L<span class="stringliteral">&quot;Half-Transparent&quot;</span>, GUI_ID_DEBUG_HALF_TRANSPARENT);
853 submenu-&gt;addItem(L<span class="stringliteral">&quot;Buffers bounding boxes&quot;</span>, GUI_ID_DEBUG_BUFFERS_BOUNDING_BOXES);
854 submenu-&gt;addItem(L<span class="stringliteral">&quot;All&quot;</span>, GUI_ID_DEBUG_ALL);
855
856 submenu = menu-&gt;getSubMenu(1)-&gt;getSubMenu(2);
857 submenu-&gt;addItem(L<span class="stringliteral">&quot;Solid&quot;</span>, GUI_ID_MODEL_MATERIAL_SOLID);
858 submenu-&gt;addItem(L<span class="stringliteral">&quot;Transparent&quot;</span>, GUI_ID_MODEL_MATERIAL_TRANSPARENT);
859 submenu-&gt;addItem(L<span class="stringliteral">&quot;Reflection&quot;</span>, GUI_ID_MODEL_MATERIAL_REFLECTION);
860
861 submenu = menu-&gt;getSubMenu(2);
862 submenu-&gt;addItem(L<span class="stringliteral">&quot;Maya Style&quot;</span>, GUI_ID_CAMERA_MAYA);
863 submenu-&gt;addItem(L<span class="stringliteral">&quot;First Person&quot;</span>, GUI_ID_CAMERA_FIRST_PERSON);
864
865 submenu = menu-&gt;getSubMenu(3);
866 submenu-&gt;addItem(L<span class="stringliteral">&quot;About&quot;</span>, GUI_ID_ABOUT);
867</pre></div><p>Below the menu we want a toolbar, onto which we can place colored buttons and important looking stuff like a senseless combobox. </p>
868<div class="fragment"><pre class="fragment"> <span class="comment">// create toolbar</span>
869
870 gui::IGUIToolBar* bar = env-&gt;addToolBar();
871
872 video::ITexture* image = driver-&gt;getTexture(<span class="stringliteral">&quot;open.png&quot;</span>);
873 bar-&gt;addButton(GUI_ID_BUTTON_OPEN_MODEL, 0, L<span class="stringliteral">&quot;Open a model&quot;</span>,image, 0, <span class="keyword">false</span>, <span class="keyword">true</span>);
874
875 image = driver-&gt;getTexture(<span class="stringliteral">&quot;tools.png&quot;</span>);
876 bar-&gt;addButton(GUI_ID_BUTTON_SHOW_TOOLBOX, 0, L<span class="stringliteral">&quot;Open Toolset&quot;</span>,image, 0, <span class="keyword">false</span>, <span class="keyword">true</span>);
877
878 image = driver-&gt;getTexture(<span class="stringliteral">&quot;zip.png&quot;</span>);
879 bar-&gt;addButton(GUI_ID_BUTTON_SELECT_ARCHIVE, 0, L<span class="stringliteral">&quot;Set Model Archive&quot;</span>,image, 0, <span class="keyword">false</span>, <span class="keyword">true</span>);
880
881 image = driver-&gt;getTexture(<span class="stringliteral">&quot;help.png&quot;</span>);
882 bar-&gt;addButton(GUI_ID_BUTTON_SHOW_ABOUT, 0, L<span class="stringliteral">&quot;Open Help&quot;</span>, image, 0, <span class="keyword">false</span>, <span class="keyword">true</span>);
883
884 <span class="comment">// create a combobox for texture filters</span>
885
886 gui::IGUIComboBox* box = env-&gt;addComboBox(core::rect&lt;s32&gt;(250,4,350,23), bar, GUI_ID_TEXTUREFILTER);
887 box-&gt;addItem(L<span class="stringliteral">&quot;No filtering&quot;</span>);
888 box-&gt;addItem(L<span class="stringliteral">&quot;Bilinear&quot;</span>);
889 box-&gt;addItem(L<span class="stringliteral">&quot;Trilinear&quot;</span>);
890 box-&gt;addItem(L<span class="stringliteral">&quot;Anisotropic&quot;</span>);
891 box-&gt;addItem(L<span class="stringliteral">&quot;Isotropic&quot;</span>);
892</pre></div><p>To make the editor look a little bit better, we disable transparent gui elements, and add an Irrlicht Engine logo. In addition, a text showing the current frames per second value is created and the window caption is changed. </p>
893<div class="fragment"><pre class="fragment"> <span class="comment">// disable alpha</span>
894
895 <span class="keywordflow">for</span> (<a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> i=0; i&lt;<a class="code" href="namespaceirr_1_1gui.html#abd15860fde29833c48daff5f95d5467aaf340f49e2e0827c0f06fdf65098554af">gui::EGDC_COUNT</a> ; ++i)
896 {
897 video::SColor col = env-&gt;getSkin()-&gt;getColor((<a class="code" href="namespaceirr_1_1gui.html#abd15860fde29833c48daff5f95d5467a" title="Enumeration for skin colors.">gui::EGUI_DEFAULT_COLOR</a>)i);
898 col.setAlpha(255);
899 env-&gt;getSkin()-&gt;setColor((<a class="code" href="namespaceirr_1_1gui.html#abd15860fde29833c48daff5f95d5467a" title="Enumeration for skin colors.">gui::EGUI_DEFAULT_COLOR</a>)i, col);
900 }
901
902 <span class="comment">// add a tabcontrol</span>
903
904 createToolBox();
905
906 <span class="comment">// create fps text</span>
907
908 IGUIStaticText* fpstext = env-&gt;addStaticText(L<span class="stringliteral">&quot;&quot;</span>,
909 core::rect&lt;s32&gt;(400,4,570,23), <span class="keyword">true</span>, <span class="keyword">false</span>, bar);
910
911 IGUIStaticText* postext = env-&gt;addStaticText(L<span class="stringliteral">&quot;&quot;</span>,
912 core::rect&lt;s32&gt;(10,50,470,80),<span class="keyword">false</span>, <span class="keyword">false</span>, 0, GUI_ID_POSITION_TEXT);
913 postext-&gt;setVisible(<span class="keyword">false</span>);
914
915 <span class="comment">// set window caption</span>
916
917 Caption += <span class="stringliteral">&quot; - [&quot;</span>;
918 Caption += driver-&gt;getName();
919 Caption += <span class="stringliteral">&quot;]&quot;</span>;
920 Device-&gt;setWindowCaption(Caption.c_str());
921</pre></div><p>That's nearly the whole application. We simply show the about message box at start up, and load the first model. To make everything look better, a skybox is created and a user controlled camera, to make the application a little bit more interactive. Finally, everything is drawn in a standard drawing loop. </p>
922<div class="fragment"><pre class="fragment"> <span class="comment">// show about message box and load default model</span>
923 <span class="keywordflow">if</span> (argc==1)
924 showAboutText();
925 loadModel(StartUpModelFile.c_str());
926
927 <span class="comment">// add skybox</span>
928
929 SkyBox = smgr-&gt;addSkyBoxSceneNode(
930 driver-&gt;getTexture(<span class="stringliteral">&quot;irrlicht2_up.jpg&quot;</span>),
931 driver-&gt;getTexture(<span class="stringliteral">&quot;irrlicht2_dn.jpg&quot;</span>),
932 driver-&gt;getTexture(<span class="stringliteral">&quot;irrlicht2_lf.jpg&quot;</span>),
933 driver-&gt;getTexture(<span class="stringliteral">&quot;irrlicht2_rt.jpg&quot;</span>),
934 driver-&gt;getTexture(<span class="stringliteral">&quot;irrlicht2_ft.jpg&quot;</span>),
935 driver-&gt;getTexture(<span class="stringliteral">&quot;irrlicht2_bk.jpg&quot;</span>));
936
937 <span class="comment">// add a camera scene node</span>
938 Camera[0] = smgr-&gt;addCameraSceneNodeMaya();
939 Camera[0]-&gt;setFarValue(20000.f);
940 <span class="comment">// Maya cameras reposition themselves relative to their target, so target the location</span>
941 <span class="comment">// where the mesh scene node is placed.</span>
942 Camera[0]-&gt;setTarget(<a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(0,30,0));
943
944 Camera[1] = smgr-&gt;addCameraSceneNodeFPS();
945 Camera[1]-&gt;setFarValue(20000.f);
946 Camera[1]-&gt;setPosition(<a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(0,0,-70));
947 Camera[1]-&gt;setTarget(<a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(0,30,0));
948
949 setActiveCamera(Camera[0]);
950
951 <span class="comment">// load the irrlicht engine logo</span>
952 IGUIImage *img =
953 env-&gt;addImage(driver-&gt;getTexture(<span class="stringliteral">&quot;irrlichtlogo2.png&quot;</span>),
954 core::position2d&lt;s32&gt;(10, driver-&gt;getScreenSize().Height - 128));
955
956 <span class="comment">// lock the logo&#39;s edges to the bottom left corner of the screen</span>
957 img-&gt;setAlignment(<a class="code" href="namespaceirr_1_1gui.html#a19eb5fb40e67f108cb16aba922ddaa2da4bb8a01452727274e18047a872da1809" title="Aligned to parent&#39;s top or left side (default)">EGUIA_UPPERLEFT</a>, <a class="code" href="namespaceirr_1_1gui.html#a19eb5fb40e67f108cb16aba922ddaa2da4bb8a01452727274e18047a872da1809" title="Aligned to parent&#39;s top or left side (default)">EGUIA_UPPERLEFT</a>,
958 <a class="code" href="namespaceirr_1_1gui.html#a19eb5fb40e67f108cb16aba922ddaa2da48b4d042b2d6cd63b876cef62c9cfb97" title="Aligned to parent&#39;s bottom or right side.">EGUIA_LOWERRIGHT</a>, <a class="code" href="namespaceirr_1_1gui.html#a19eb5fb40e67f108cb16aba922ddaa2da48b4d042b2d6cd63b876cef62c9cfb97" title="Aligned to parent&#39;s bottom or right side.">EGUIA_LOWERRIGHT</a>);
959
960 <span class="comment">// remember state so we notice when the window does lose the focus</span>
961 <span class="keywordtype">bool</span> hasFocus = Device-&gt;isWindowFocused();
962
963 <span class="comment">// draw everything</span>
964
965 <span class="keywordflow">while</span>(Device-&gt;run() &amp;&amp; driver)
966 {
967 <span class="comment">// Catch focus changes (workaround until Irrlicht has events for this)</span>
968 <span class="keywordtype">bool</span> focused = Device-&gt;isWindowFocused();
969 <span class="keywordflow">if</span> ( hasFocus &amp;&amp; !focused )
970 onKillFocus();
971 hasFocus = focused;
972
973 <span class="keywordflow">if</span> (Device-&gt;isWindowActive())
974 {
975 driver-&gt;beginScene(<span class="keyword">true</span>, <span class="keyword">true</span>, video::SColor(150,50,50,50));
976
977 smgr-&gt;drawAll();
978 env-&gt;drawAll();
979
980 driver-&gt;endScene();
981
982 <span class="comment">// update information about current frame-rate</span>
983 <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">core::stringw</a> str(L<span class="stringliteral">&quot;FPS: &quot;</span>);
984 str.append(<a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">core::stringw</a>(driver-&gt;getFPS()));
985 str += L<span class="stringliteral">&quot; Tris: &quot;</span>;
986 str.append(<a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">core::stringw</a>(driver-&gt;getPrimitiveCountDrawn()));
987 fpstext-&gt;setText(str.c_str());
988
989 <span class="comment">// update information about the active camera</span>
990 scene::ICameraSceneNode* cam = Device-&gt;getSceneManager()-&gt;getActiveCamera();
991 str = L<span class="stringliteral">&quot;Pos: &quot;</span>;
992 str.append(<a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">core::stringw</a>(cam-&gt;getPosition().X));
993 str += L<span class="stringliteral">&quot; &quot;</span>;
994 str.append(<a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">core::stringw</a>(cam-&gt;getPosition().Y));
995 str += L<span class="stringliteral">&quot; &quot;</span>;
996 str.append(<a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">core::stringw</a>(cam-&gt;getPosition().Z));
997 str += L<span class="stringliteral">&quot; Tgt: &quot;</span>;
998 str.append(<a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">core::stringw</a>(cam-&gt;getTarget().X));
999 str += L<span class="stringliteral">&quot; &quot;</span>;
1000 str.append(<a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">core::stringw</a>(cam-&gt;getTarget().Y));
1001 str += L<span class="stringliteral">&quot; &quot;</span>;
1002 str.append(<a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">core::stringw</a>(cam-&gt;getTarget().Z));
1003 postext-&gt;setText(str.c_str());
1004
1005 <span class="comment">// update the tool dialog</span>
1006 updateToolBox();
1007 }
1008 <span class="keywordflow">else</span>
1009 Device-&gt;yield();
1010 }
1011
1012 Device-&gt;drop();
1013 <span class="keywordflow">return</span> 0;
1014}
1015</pre></div> </div></div>
1016</div>
1017 <div id="nav-path" class="navpath">
1018 <ul>
1019<!-- window showing the filter options -->
1020<div id="MSearchSelectWindow"
1021 onmouseover="return searchBox.OnSearchSelectShow()"
1022 onmouseout="return searchBox.OnSearchSelectHide()"
1023 onkeydown="return searchBox.OnSearchSelectKey(event)">
1024<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>
1025
1026<!-- iframe showing the search results (closed by default) -->
1027<div id="MSearchResultsWindow">
1028<iframe src="javascript:void(0)" frameborder="0"
1029 name="MSearchResults" id="MSearchResults">
1030</iframe>
1031</div>
1032
1033
1034 <li class="footer">
1035<a href="http://irrlicht.sourceforge.net" target="_blank">Irrlicht
1036Engine</a> Documentation &copy; 2003-2012 by Nikolaus Gebhardt. Generated on Sun Nov 17 2013 20:18:41 for Irrlicht 3D Engine by
1037<a href="http://www.doxygen.org/index.html" target="_blank">Doxygen</a> 1.7.5.1 </li>
1038 </ul>
1039 </div>
1040
1041
1042</body>
1043</html>