tutorial.html 80 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
  5. <meta http-equiv="X-UA-Compatible" content="IE=9"/>
  6. <meta name="generator" content="Doxygen 1.8.13"/>
  7. <meta name="viewport" content="width=device-width, initial-scale=1"/>
  8. <title>Tutorial 9: Mesh Viewer</title>
  9. <html xmlns="http://www.w3.org/1999/xhtml">
  10. <!-- Wanted to avoid copying .css to each folder, so copied default .css from doxyen in here, kicked out most stuff we don't need for examples and modified some a little bit.
  11. Target was having a single html in each example folder which is created from the main.cpp files and needs no files besides some images below media folder.
  12. Feel free to improve :)
  13. -->
  14. <style>
  15. body, table, div, p, dl {
  16. font: 400 14px/22px;
  17. }
  18. body {
  19. background-color: #F0F0F0;
  20. color: black;
  21. margin-left: 5%;
  22. margin-right: 5%;
  23. }
  24. p.reference, p.definition {
  25. font: 400 14px/22px;
  26. }
  27. .title {
  28. font: 400 14px/28px;
  29. font-size: 150%;
  30. font-weight: bold;
  31. margin: 10px 2px;
  32. }
  33. h1, h2, h3, h4, h5, h6 {
  34. -webkit-transition: text-shadow 0.5s linear;
  35. -moz-transition: text-shadow 0.5s linear;
  36. -ms-transition: text-shadow 0.5s linear;
  37. -o-transition: text-shadow 0.5s linear;
  38. transition: text-shadow 0.5s linear;
  39. margin-right: 15px;
  40. }
  41. caption {
  42. font-weight: bold;
  43. }
  44. h3.version {
  45. font-size: 90%;
  46. text-align: center;
  47. }
  48. a {
  49. color: #3D578C;
  50. font-weight: normal;
  51. text-decoration: none;
  52. }
  53. .contents a:visited {
  54. color: #4665A2;
  55. }
  56. a:hover {
  57. text-decoration: underline;
  58. }
  59. a.el {
  60. font-weight: bold;
  61. }
  62. a.code, a.code:visited, a.line, a.line:visited {
  63. color: #4665A2;
  64. }
  65. a.codeRef, a.codeRef:visited, a.lineRef, a.lineRef:visited {
  66. color: #4665A2;
  67. }
  68. pre.fragment {
  69. border: 1px solid #C4CFE5;
  70. background-color: #FBFCFD;
  71. padding: 4px 6px;
  72. margin: 4px 8px 4px 2px;
  73. overflow: auto;
  74. word-wrap: break-word;
  75. font-size: 9pt;
  76. line-height: 125%;
  77. font-family: monospace, fixed;
  78. font-size: 105%;
  79. }
  80. div.fragment {
  81. padding: 0px;
  82. margin: 4px 8px 4px 2px;
  83. background-color: #FBFCFD;
  84. border: 1px solid #C4CFE5;
  85. }
  86. div.line {
  87. font-family: monospace, fixed;
  88. font-size: 13px;
  89. min-height: 13px;
  90. line-height: 1.0;
  91. text-wrap: unrestricted;
  92. white-space: -moz-pre-wrap; /* Moz */
  93. white-space: -pre-wrap; /* Opera 4-6 */
  94. white-space: -o-pre-wrap; /* Opera 7 */
  95. white-space: pre-wrap; /* CSS3 */
  96. word-wrap: break-word; /* IE 5.5+ */
  97. text-indent: -53px;
  98. padding-left: 53px;
  99. padding-bottom: 0px;
  100. margin: 0px;
  101. -webkit-transition-property: background-color, box-shadow;
  102. -webkit-transition-duration: 0.5s;
  103. -moz-transition-property: background-color, box-shadow;
  104. -moz-transition-duration: 0.5s;
  105. -ms-transition-property: background-color, box-shadow;
  106. -ms-transition-duration: 0.5s;
  107. -o-transition-property: background-color, box-shadow;
  108. -o-transition-duration: 0.5s;
  109. transition-property: background-color, box-shadow;
  110. transition-duration: 0.5s;
  111. }
  112. div.contents {
  113. margin-top: 10px;
  114. margin-left: 12px;
  115. margin-right: 8px;
  116. }
  117. div.center {
  118. text-align: center;
  119. margin-top: 0px;
  120. margin-bottom: 0px;
  121. padding: 0px;
  122. }
  123. div.center img {
  124. border: 0px;
  125. }
  126. span.keyword {
  127. color: #008000
  128. }
  129. span.keywordtype {
  130. color: #604020
  131. }
  132. span.keywordflow {
  133. color: #e08000
  134. }
  135. span.comment {
  136. color: #800000
  137. }
  138. span.preprocessor {
  139. color: #806020
  140. }
  141. span.stringliteral {
  142. color: #002080
  143. }
  144. span.charliteral {
  145. color: #008080
  146. }
  147. blockquote {
  148. background-color: #F7F8FB;
  149. border-left: 2px solid #9CAFD4;
  150. margin: 0 24px 0 4px;
  151. padding: 0 12px 0 16px;
  152. }
  153. hr {
  154. height: 0px;
  155. border: none;
  156. border-top: 1px solid #4A6AAA;
  157. }
  158. address {
  159. font-style: normal;
  160. color: #2A3D61;
  161. }
  162. div.header {
  163. background-image:url('nav_h.png');
  164. background-repeat:repeat-x;
  165. background-color: #F9FAFC;
  166. margin: 0px;
  167. border-bottom: 1px solid #C4CFE5;
  168. }
  169. div.headertitle {
  170. padding: 5px 5px 5px 10px;
  171. }
  172. .image {
  173. text-align: center;
  174. }
  175. .caption {
  176. font-weight: bold;
  177. }
  178. div.zoom {
  179. border: 1px solid #90A5CE;
  180. }
  181. tr.heading h2 {
  182. margin-top: 12px;
  183. margin-bottom: 4px;
  184. }
  185. </style>
  186. </head>
  187. <div id="top"><!-- do not remove this div, it is closed by doxygen! -->
  188. <!--END TITLEAREA-->
  189. <!-- end header part -->
  190. <!-- Generated by Doxygen 1.8.13 -->
  191. </div><!-- top -->
  192. <div class="header">
  193. <div class="headertitle">
  194. <div class="title">Tutorial 9: Mesh Viewer </div> </div>
  195. </div><!--header-->
  196. <div class="contents">
  197. <div class="textblock"><div class="image">
  198. <img src="../../media/example_screenshots/009shot.jpg" alt="009shot.jpg"/>
  199. </div>
  200. <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>
  201. <p>We start like in most other tutorials: Include all necessary header files, add a comment to let the engine be linked with the correct .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 of stuff from the gui namespace. </p><div class="fragment"><div class="line"><span class="preprocessor">#include &lt;irrlicht.h&gt;</span></div><div class="line"><span class="preprocessor">#include &quot;driverChoice.h&quot;</span></div><div class="line"><span class="preprocessor">#include &quot;exampleHelper.h&quot;</span></div><div class="line"></div><div class="line"><span class="keyword">using namespace </span>irr;</div><div class="line"><span class="keyword">using namespace </span>gui;</div><div class="line"></div><div class="line"><span class="preprocessor">#ifdef _MSC_VER</span></div><div class="line"><span class="preprocessor">#pragma comment(lib, &quot;Irrlicht.lib&quot;)</span></div><div class="line"><span class="preprocessor">#endif</span></div></div><!-- fragment --><p> Some global variables used later on </p><div class="fragment"><div class="line">IrrlichtDevice *Device = 0;</div><div class="line">io::path StartUpModelFile;</div><div class="line">core::stringw MessageText;</div><div class="line">core::stringw Caption;</div><div class="line">scene::ISceneNode* Model = 0;</div><div class="line">scene::ISceneNode* SkyBox = 0;</div><div class="line"><span class="keywordtype">bool</span> Octree=<span class="keyword">false</span>;</div><div class="line"><span class="keywordtype">bool</span> UseLight=<span class="keyword">false</span>;</div><div class="line"></div><div class="line">scene::ICameraSceneNode* Camera[2] = {0, 0};</div><div class="line"></div><div class="line"><span class="comment">// Values used to identify individual GUI elements</span></div><div class="line"><span class="keyword">enum</span></div><div class="line">{</div><div class="line"> GUI_ID_DIALOG_ROOT_WINDOW = 0x10000,</div><div class="line"></div><div class="line"> GUI_ID_X_SCALE,</div><div class="line"> GUI_ID_Y_SCALE,</div><div class="line"> GUI_ID_Z_SCALE,</div><div class="line"></div><div class="line"> GUI_ID_OPEN_MODEL,</div><div class="line"> GUI_ID_SET_MODEL_ARCHIVE,</div><div class="line"> GUI_ID_LOAD_AS_OCTREE,</div><div class="line"></div><div class="line"> GUI_ID_SKY_BOX_VISIBLE,</div><div class="line"> GUI_ID_TOGGLE_DEBUG_INFO,</div><div class="line"></div><div class="line"> GUI_ID_DEBUG_OFF,</div><div class="line"> GUI_ID_DEBUG_BOUNDING_BOX,</div><div class="line"> GUI_ID_DEBUG_NORMALS,</div><div class="line"> GUI_ID_DEBUG_SKELETON,</div><div class="line"> GUI_ID_DEBUG_WIRE_OVERLAY,</div><div class="line"> GUI_ID_DEBUG_HALF_TRANSPARENT,</div><div class="line"> GUI_ID_DEBUG_BUFFERS_BOUNDING_BOXES,</div><div class="line"> GUI_ID_DEBUG_ALL,</div><div class="line"></div><div class="line"> GUI_ID_MODEL_MATERIAL_SOLID,</div><div class="line"> GUI_ID_MODEL_MATERIAL_TRANSPARENT,</div><div class="line"> GUI_ID_MODEL_MATERIAL_REFLECTION,</div><div class="line"></div><div class="line"> GUI_ID_CAMERA_MAYA,</div><div class="line"> GUI_ID_CAMERA_FIRST_PERSON,</div><div class="line"></div><div class="line"> GUI_ID_POSITION_TEXT,</div><div class="line"></div><div class="line"> GUI_ID_ABOUT,</div><div class="line"> GUI_ID_QUIT,</div><div class="line"></div><div class="line"> GUI_ID_TEXTUREFILTER,</div><div class="line"> GUI_ID_SKIN_TRANSPARENCY,</div><div class="line"> GUI_ID_SKIN_ANIMATION_FPS,</div><div class="line"></div><div class="line"> GUI_ID_BUTTON_SET_SCALE,</div><div class="line"> GUI_ID_BUTTON_SCALE_MUL10,</div><div class="line"> GUI_ID_BUTTON_SCALE_DIV10,</div><div class="line"> GUI_ID_BUTTON_OPEN_MODEL,</div><div class="line"> GUI_ID_BUTTON_SHOW_ABOUT,</div><div class="line"> GUI_ID_BUTTON_SHOW_TOOLBOX,</div><div class="line"> GUI_ID_BUTTON_SELECT_ARCHIVE,</div><div class="line"></div><div class="line"> GUI_ID_ANIMATION_INFO,</div><div class="line"></div><div class="line"> <span class="comment">// And some magic numbers</span></div><div class="line"> MAX_FRAMERATE = 80,</div><div class="line"> DEFAULT_FRAMERATE = 30</div><div class="line">};</div></div><!-- fragment --><p> Toggle between various cameras </p><div class="fragment"><div class="line"><span class="keywordtype">void</span> setActiveCamera(scene::ICameraSceneNode* newActive)</div><div class="line">{</div><div class="line"> <span class="keywordflow">if</span> (0 == Device)</div><div class="line"> <span class="keywordflow">return</span>;</div><div class="line"></div><div class="line"> scene::ICameraSceneNode * active = Device-&gt;getSceneManager()-&gt;getActiveCamera();</div><div class="line"> active-&gt;setInputReceiverEnabled(<span class="keyword">false</span>);</div><div class="line"></div><div class="line"> newActive-&gt;setInputReceiverEnabled(<span class="keyword">true</span>);</div><div class="line"> Device-&gt;getSceneManager()-&gt;setActiveCamera(newActive);</div><div class="line">}</div></div><!-- fragment --><p> Set the skin transparency by changing the alpha values of all skin-colors </p><div class="fragment"><div class="line"><span class="keywordtype">void</span> setSkinTransparency(s32 alpha, irr::gui::IGUISkin * skin)</div><div class="line">{</div><div class="line"> <span class="keywordflow">for</span> (s32 i=0; i&lt;irr::gui::EGDC_COUNT ; ++i)</div><div class="line"> {</div><div class="line"> video::SColor col = skin-&gt;getColor((EGUI_DEFAULT_COLOR)i);</div><div class="line"> col.setAlpha(alpha);</div><div class="line"> skin-&gt;setColor((EGUI_DEFAULT_COLOR)i, col);</div><div class="line"> }</div><div class="line">}</div></div><!-- fragment --><p> Update the display of the model scaling </p><div class="fragment"><div class="line"><span class="keywordtype">void</span> updateScaleInfo(scene::ISceneNode* model)</div><div class="line">{</div><div class="line"> IGUIElement* toolboxWnd = Device-&gt;getGUIEnvironment()-&gt;getRootGUIElement()-&gt;getElementFromId(GUI_ID_DIALOG_ROOT_WINDOW, <span class="keyword">true</span>);</div><div class="line"> <span class="keywordflow">if</span> (!toolboxWnd)</div><div class="line"> <span class="keywordflow">return</span>;</div><div class="line"> <span class="keywordflow">if</span> (!model)</div><div class="line"> {</div><div class="line"> toolboxWnd-&gt;getElementFromId(GUI_ID_X_SCALE, <span class="keyword">true</span>)-&gt;setText( L<span class="stringliteral">&quot;-&quot;</span> );</div><div class="line"> toolboxWnd-&gt;getElementFromId(GUI_ID_Y_SCALE, <span class="keyword">true</span>)-&gt;setText( L<span class="stringliteral">&quot;-&quot;</span> );</div><div class="line"> toolboxWnd-&gt;getElementFromId(GUI_ID_Z_SCALE, <span class="keyword">true</span>)-&gt;setText( L<span class="stringliteral">&quot;-&quot;</span> );</div><div class="line"> }</div><div class="line"> <span class="keywordflow">else</span></div><div class="line"> {</div><div class="line"> core::vector3df scale = model-&gt;getScale();</div><div class="line"> toolboxWnd-&gt;getElementFromId(GUI_ID_X_SCALE, <span class="keyword">true</span>)-&gt;setText( core::stringw(scale.X).c_str() );</div><div class="line"> toolboxWnd-&gt;getElementFromId(GUI_ID_Y_SCALE, <span class="keyword">true</span>)-&gt;setText( core::stringw(scale.Y).c_str() );</div><div class="line"> toolboxWnd-&gt;getElementFromId(GUI_ID_Z_SCALE, <span class="keyword">true</span>)-&gt;setText( core::stringw(scale.Z).c_str() );</div><div class="line"> }</div><div class="line">}</div></div><!-- fragment --><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><div class="fragment"><div class="line"><span class="keywordtype">void</span> showAboutText()</div><div class="line">{</div><div class="line"> <span class="comment">// create modal message box with the text</span></div><div class="line"> <span class="comment">// loaded from the xml file.</span></div><div class="line"> Device-&gt;getGUIEnvironment()-&gt;addMessageBox(</div><div class="line"> Caption.c_str(), MessageText.c_str());</div><div class="line">}</div></div><!-- fragment --><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><div class="fragment"><div class="line"><span class="keywordtype">void</span> loadModel(<span class="keyword">const</span> io::path&amp; filename)</div><div class="line">{</div><div class="line"> io::path extension;</div><div class="line"> core::getFileNameExtension(extension, filename);</div><div class="line"> extension.make_lower();</div><div class="line"></div><div class="line"> <span class="comment">// if a texture is loaded apply it to the current model..</span></div><div class="line"> <span class="keywordflow">if</span> (extension == <span class="stringliteral">&quot;.jpg&quot;</span> || extension == <span class="stringliteral">&quot;.pcx&quot;</span> ||</div><div class="line"> extension == <span class="stringliteral">&quot;.png&quot;</span> || extension == <span class="stringliteral">&quot;.ppm&quot;</span> ||</div><div class="line"> extension == <span class="stringliteral">&quot;.pgm&quot;</span> || extension == <span class="stringliteral">&quot;.pbm&quot;</span> ||</div><div class="line"> extension == <span class="stringliteral">&quot;.psd&quot;</span> || extension == <span class="stringliteral">&quot;.tga&quot;</span> ||</div><div class="line"> extension == <span class="stringliteral">&quot;.bmp&quot;</span> || extension == <span class="stringliteral">&quot;.wal&quot;</span> ||</div><div class="line"> extension == <span class="stringliteral">&quot;.rgb&quot;</span> || extension == <span class="stringliteral">&quot;.rgba&quot;</span>)</div><div class="line"> {</div><div class="line"> <span class="comment">// Ensure reloading texture by clearing old one out of cache</span></div><div class="line"> video::ITexture * texture = Device-&gt;getVideoDriver()-&gt;findTexture( filename );</div><div class="line"> <span class="keywordflow">if</span> ( texture )</div><div class="line"> Device-&gt;getVideoDriver()-&gt;removeTexture(texture);</div><div class="line"></div><div class="line"> <span class="comment">// Load the new one and put int on the model</span></div><div class="line"> texture = Device-&gt;getVideoDriver()-&gt;getTexture( filename );</div><div class="line"> <span class="keywordflow">if</span> ( texture &amp;&amp; Model )</div><div class="line"> {</div><div class="line"> Model-&gt;setMaterialTexture(0, texture);</div><div class="line"> }</div><div class="line"> <span class="keywordflow">return</span>;</div><div class="line"> }</div><div class="line"> <span class="comment">// if a archive is loaded add it to the FileArchive..</span></div><div class="line"> <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>)</div><div class="line"> {</div><div class="line"> Device-&gt;getFileSystem()-&gt;addFileArchive(filename.c_str());</div><div class="line"> <span class="keywordflow">return</span>;</div><div class="line"> }</div><div class="line"></div><div class="line"> <span class="comment">// Remove old model</span></div><div class="line"></div><div class="line"> <span class="keywordflow">if</span> (Model)</div><div class="line"> {</div><div class="line"> Model-&gt;remove();</div><div class="line"> Model = 0;</div><div class="line"> }</div><div class="line"></div><div class="line"> <span class="comment">// .irr is a scene format, so load as scene and set Model pointer to first object in the scene</span></div><div class="line"></div><div class="line"> <span class="keywordflow">if</span> (extension==<span class="stringliteral">&quot;.irr&quot;</span>)</div><div class="line"> {</div><div class="line"> core::array&lt;scene::ISceneNode*&gt; outNodes;</div><div class="line"> Device-&gt;getSceneManager()-&gt;loadScene(filename);</div><div class="line"> Device-&gt;getSceneManager()-&gt;getSceneNodesFromType(scene::ESNT_ANIMATED_MESH, outNodes);</div><div class="line"> <span class="keywordflow">if</span> (outNodes.size())</div><div class="line"> Model = outNodes[0];</div><div class="line"> <span class="keywordflow">return</span>;</div><div class="line"> }</div><div class="line"></div><div class="line"> <span class="comment">// load a model into the engine. Also log the time it takes to load it.</span></div><div class="line"></div><div class="line"> u32 then = Device-&gt;getTimer()-&gt;getRealTime();</div><div class="line"> scene::IAnimatedMesh* mesh = Device-&gt;getSceneManager()-&gt;getMesh( filename.c_str() );</div><div class="line"> Device-&gt;getLogger()-&gt;log(<span class="stringliteral">&quot;Loading time (ms): &quot;</span>, core::stringc(Device-&gt;getTimer()-&gt;getRealTime() - then).c_str());</div><div class="line"></div><div class="line"> <span class="keywordflow">if</span> (!mesh)</div><div class="line"> {</div><div class="line"> <span class="comment">// model could not be loaded</span></div><div class="line"></div><div class="line"> <span class="keywordflow">if</span> (StartUpModelFile != filename)</div><div class="line"> Device-&gt;getGUIEnvironment()-&gt;addMessageBox(</div><div class="line"> Caption.c_str(), L<span class="stringliteral">&quot;The model could not be loaded. &quot;</span> \</div><div class="line"> L<span class="stringliteral">&quot;Maybe it is not a supported file format.&quot;</span>);</div><div class="line"> <span class="keywordflow">return</span>;</div><div class="line"> }</div><div class="line"></div><div class="line"> <span class="comment">// set default material properties</span></div><div class="line"></div><div class="line"> <span class="keywordflow">if</span> (Octree)</div><div class="line"> Model = Device-&gt;getSceneManager()-&gt;addOctreeSceneNode(mesh-&gt;getMesh(0));</div><div class="line"> <span class="keywordflow">else</span></div><div class="line"> {</div><div class="line"> scene::IAnimatedMeshSceneNode* animModel = Device-&gt;getSceneManager()-&gt;addAnimatedMeshSceneNode(mesh);</div><div class="line"> Model = animModel;</div><div class="line"> }</div><div class="line"> Model-&gt;setMaterialFlag(video::EMF_LIGHTING, UseLight);</div><div class="line"> Model-&gt;setMaterialFlag(video::EMF_NORMALIZE_NORMALS, UseLight);</div><div class="line"><span class="comment">// Model-&gt;setMaterialFlag(video::EMF_BACK_FACE_CULLING, false);</span></div><div class="line"> Model-&gt;setDebugDataVisible(scene::EDS_OFF);</div><div class="line"></div><div class="line"> <span class="comment">// we need to uncheck the menu entries. would be cool to fake a menu event, but</span></div><div class="line"> <span class="comment">// that&#39;s not so simple. so we do it brute force</span></div><div class="line"> gui::IGUIContextMenu* menu = (gui::IGUIContextMenu*)Device-&gt;getGUIEnvironment()-&gt;getRootGUIElement()-&gt;getElementFromId(GUI_ID_TOGGLE_DEBUG_INFO, <span class="keyword">true</span>);</div><div class="line"> <span class="keywordflow">if</span> (menu)</div><div class="line"> <span class="keywordflow">for</span>(<span class="keywordtype">int</span> item = 1; item &lt; 6; ++item)</div><div class="line"> menu-&gt;setItemChecked(item, <span class="keyword">false</span>);</div><div class="line"> updateScaleInfo(Model);</div><div class="line">}</div></div><!-- fragment --><p> Function createToolBox() creates a toolbox window. In this simple mesh viewer, this toolbox only contains a controls to change the scale and animation speed of the model and a control to set the transparency of the GUI-elements. </p><div class="fragment"><div class="line"><span class="keywordtype">void</span> createToolBox()</div><div class="line">{</div><div class="line"> <span class="comment">// remove tool box if already there</span></div><div class="line"> IGUIEnvironment* env = Device-&gt;getGUIEnvironment();</div><div class="line"> IGUIElement* root = env-&gt;getRootGUIElement();</div><div class="line"> IGUIElement* e = root-&gt;getElementFromId(GUI_ID_DIALOG_ROOT_WINDOW, <span class="keyword">true</span>);</div><div class="line"> <span class="keywordflow">if</span> (e)</div><div class="line"> e-&gt;remove();</div><div class="line"></div><div class="line"> <span class="comment">// create the toolbox window</span></div><div class="line"> IGUIWindow* wnd = env-&gt;addWindow(core::rect&lt;s32&gt;(600,45,800,480),</div><div class="line"> <span class="keyword">false</span>, L<span class="stringliteral">&quot;Toolset&quot;</span>, 0, GUI_ID_DIALOG_ROOT_WINDOW);</div><div class="line"></div><div class="line"> <span class="comment">// create tab control and tabs</span></div><div class="line"> IGUITabControl* tab = env-&gt;addTabControl(</div><div class="line"> core::rect&lt;s32&gt;(2,20,800-602,480-7), wnd, <span class="keyword">true</span>, <span class="keyword">true</span>);</div><div class="line"></div><div class="line"> IGUITab* t1 = tab-&gt;addTab(L<span class="stringliteral">&quot;Config&quot;</span>);</div><div class="line"></div><div class="line"> <span class="comment">// add some edit boxes and a button to tab one</span></div><div class="line"> env-&gt;addStaticText(L<span class="stringliteral">&quot;Scale:&quot;</span>,</div><div class="line"> core::rect&lt;s32&gt;(10,20,60,45), <span class="keyword">false</span>, <span class="keyword">false</span>, t1);</div><div class="line"> 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);</div><div class="line"> 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);</div><div class="line"> 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);</div><div class="line"> 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);</div><div class="line"> 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);</div><div class="line"> 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);</div><div class="line"></div><div class="line"> 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>);</div><div class="line"></div><div class="line"> <span class="comment">// quick scale buttons</span></div><div class="line"> 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>);</div><div class="line"> 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>);</div><div class="line"></div><div class="line"> updateScaleInfo(Model);</div><div class="line"></div><div class="line"> <span class="comment">// add transparency control</span></div><div class="line"> env-&gt;addStaticText(L<span class="stringliteral">&quot;GUI Transparency Control:&quot;</span>,</div><div class="line"> core::rect&lt;s32&gt;(10,200,150,225), <span class="keyword">true</span>, <span class="keyword">false</span>, t1);</div><div class="line"> IGUIScrollBar* scrollbar = env-&gt;addScrollBar(<span class="keyword">true</span>,</div><div class="line"> core::rect&lt;s32&gt;(10,225,150,240), t1, GUI_ID_SKIN_TRANSPARENCY);</div><div class="line"> scrollbar-&gt;setMax(255);</div><div class="line"> scrollbar-&gt;setPos(255);</div><div class="line"></div><div class="line"> <span class="comment">// add framerate control</span></div><div class="line"> 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);</div><div class="line"> env-&gt;addStaticText(L<span class="stringliteral">&quot;Framerate:&quot;</span>,</div><div class="line"> core::rect&lt;s32&gt;(12,240,75,265), <span class="keyword">false</span>, <span class="keyword">false</span>, t1);</div><div class="line"> <span class="comment">// current frame info</span></div><div class="line"> 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,</div><div class="line"> GUI_ID_ANIMATION_INFO);</div><div class="line"> scrollbar = env-&gt;addScrollBar(<span class="keyword">true</span>,</div><div class="line"> core::rect&lt;s32&gt;(10,265,150,280), t1, GUI_ID_SKIN_ANIMATION_FPS);</div><div class="line"> scrollbar-&gt;setMax(MAX_FRAMERATE);</div><div class="line"> scrollbar-&gt;setMin(-MAX_FRAMERATE);</div><div class="line"> scrollbar-&gt;setPos(DEFAULT_FRAMERATE);</div><div class="line"> scrollbar-&gt;setSmallStep(1);</div><div class="line">}</div></div><!-- fragment --><p> Function updateToolBox() is called each frame to update dynamic information in the toolbox. </p><div class="fragment"><div class="line"><span class="keywordtype">void</span> updateToolBox()</div><div class="line">{</div><div class="line"> IGUIEnvironment* env = Device-&gt;getGUIEnvironment();</div><div class="line"> IGUIElement* root = env-&gt;getRootGUIElement();</div><div class="line"> IGUIElement* dlg = root-&gt;getElementFromId(GUI_ID_DIALOG_ROOT_WINDOW, <span class="keyword">true</span>);</div><div class="line"> <span class="keywordflow">if</span> (!dlg )</div><div class="line"> <span class="keywordflow">return</span>;</div><div class="line"></div><div class="line"> <span class="comment">// update the info we have about the animation of the model</span></div><div class="line"> IGUIStaticText * aniInfo = (IGUIStaticText *)(dlg-&gt;getElementFromId(GUI_ID_ANIMATION_INFO, <span class="keyword">true</span>));</div><div class="line"> <span class="keywordflow">if</span> (aniInfo)</div><div class="line"> {</div><div class="line"> <span class="keywordflow">if</span> ( Model &amp;&amp; scene::ESNT_ANIMATED_MESH == Model-&gt;getType() )</div><div class="line"> {</div><div class="line"> scene::IAnimatedMeshSceneNode* animatedModel = (scene::IAnimatedMeshSceneNode*)Model;</div><div class="line"></div><div class="line"> core::stringw str( (s32)core::round_(animatedModel-&gt;getAnimationSpeed()) );</div><div class="line"> str += L<span class="stringliteral">&quot; Frame: &quot;</span>;</div><div class="line"> str += core::stringw((s32)animatedModel-&gt;getFrameNr());</div><div class="line"> aniInfo-&gt;setText(str.c_str());</div><div class="line"> }</div><div class="line"> <span class="keywordflow">else</span></div><div class="line"> aniInfo-&gt;setText(L<span class="stringliteral">&quot;&quot;</span>);</div><div class="line"> }</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keywordtype">void</span> onKillFocus()</div><div class="line">{</div><div class="line"> <span class="comment">// Avoid that the FPS-camera continues moving when the user presses alt-tab while</span></div><div class="line"> <span class="comment">// moving the camera.</span></div><div class="line"> <span class="keyword">const</span> core::list&lt;scene::ISceneNodeAnimator*&gt;&amp; animators = Camera[1]-&gt;getAnimators();</div><div class="line"> core::list&lt;irr::scene::ISceneNodeAnimator*&gt;::ConstIterator iter = animators.begin();</div><div class="line"> <span class="keywordflow">while</span> ( iter != animators.end() )</div><div class="line"> {</div><div class="line"> <span class="keywordflow">if</span> ( (*iter)-&gt;getType() == scene::ESNAT_CAMERA_FPS )</div><div class="line"> {</div><div class="line"> <span class="comment">// we send a key-down event for all keys used by this animator</span></div><div class="line"> scene::ISceneNodeAnimatorCameraFPS * fpsAnimator = <span class="keyword">static_cast&lt;</span>scene::ISceneNodeAnimatorCameraFPS*<span class="keyword">&gt;</span>(*iter);</div><div class="line"> <span class="keyword">const</span> core::array&lt;SKeyMap&gt;&amp; keyMap = fpsAnimator-&gt;getKeyMap();</div><div class="line"> <span class="keywordflow">for</span> ( irr::u32 i=0; i&lt; keyMap.size(); ++i )</div><div class="line"> {</div><div class="line"> irr::SEvent event;</div><div class="line"> <span class="keyword">event</span>.EventType = EET_KEY_INPUT_EVENT;</div><div class="line"> <span class="keyword">event</span>.KeyInput.Key = keyMap[i].KeyCode;</div><div class="line"> <span class="keyword">event</span>.KeyInput.PressedDown = <span class="keyword">false</span>;</div><div class="line"> fpsAnimator-&gt;OnEvent(event);</div><div class="line"> }</div><div class="line"> }</div><div class="line"> ++iter;</div><div class="line"> }</div><div class="line">}</div></div><!-- fragment --><p> Function hasModalDialog() checks if we currently have a modal dialog open. </p><div class="fragment"><div class="line"><span class="keywordtype">bool</span> hasModalDialog()</div><div class="line">{</div><div class="line"> <span class="keywordflow">if</span> ( !Device )</div><div class="line"> <span class="keywordflow">return</span> <span class="keyword">false</span>;</div><div class="line"> IGUIEnvironment* env = Device-&gt;getGUIEnvironment();</div><div class="line"> IGUIElement * focused = env-&gt;getFocus();</div><div class="line"> <span class="keywordflow">while</span> ( focused )</div><div class="line"> {</div><div class="line"> <span class="keywordflow">if</span> ( focused-&gt;isVisible() &amp;&amp; focused-&gt;hasType(EGUIET_MODAL_SCREEN) )</div><div class="line"> <span class="keywordflow">return</span> <span class="keyword">true</span>;</div><div class="line"> focused = focused-&gt;getParent();</div><div class="line"> }</div><div class="line"> <span class="keywordflow">return</span> <span class="keyword">false</span>;</div><div class="line">}</div></div><!-- fragment --><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><div class="fragment"><div class="line"><span class="keyword">class </span>MyEventReceiver : <span class="keyword">public</span> IEventReceiver</div><div class="line">{</div><div class="line"><span class="keyword">public</span>:</div><div class="line"> <span class="keyword">virtual</span> <span class="keywordtype">bool</span> OnEvent(<span class="keyword">const</span> SEvent&amp; event)</div><div class="line"> {</div><div class="line"> <span class="comment">// Key events</span></div><div class="line"> <span class="keywordflow">if</span> (event.EventType == EET_KEY_INPUT_EVENT &amp;&amp;</div><div class="line"> event.KeyInput.PressedDown == <span class="keyword">false</span>)</div><div class="line"> {</div><div class="line"> <span class="keywordflow">if</span> ( OnKeyUp(event.KeyInput.Key) )</div><div class="line"> <span class="keywordflow">return</span> <span class="keyword">true</span>;</div><div class="line"> }</div><div class="line"></div><div class="line"> <span class="comment">// GUI events</span></div><div class="line"> <span class="keywordflow">if</span> (event.EventType == EET_GUI_EVENT)</div><div class="line"> {</div><div class="line"> s32 <span class="keywordtype">id</span> = <span class="keyword">event</span>.GUIEvent.Caller-&gt;getID();</div><div class="line"> IGUIEnvironment* env = Device-&gt;getGUIEnvironment();</div><div class="line"></div><div class="line"> <span class="keywordflow">switch</span>(event.GUIEvent.EventType)</div><div class="line"> {</div><div class="line"> <span class="keywordflow">case</span> EGET_MENU_ITEM_SELECTED:</div><div class="line"> <span class="comment">// a menu item was clicked</span></div><div class="line"> OnMenuItemSelected( (IGUIContextMenu*)event.GUIEvent.Caller );</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"></div><div class="line"> <span class="keywordflow">case</span> EGET_FILE_SELECTED:</div><div class="line"> {</div><div class="line"> <span class="comment">// load the model file, selected in the file open dialog</span></div><div class="line"> IGUIFileOpenDialog* dialog =</div><div class="line"> (IGUIFileOpenDialog*)event.GUIEvent.Caller;</div><div class="line"> loadModel(dialog-&gt;getFileNameP());</div><div class="line"> }</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"></div><div class="line"> <span class="keywordflow">case</span> EGET_SCROLL_BAR_CHANGED:</div><div class="line"></div><div class="line"> <span class="comment">// control skin transparency</span></div><div class="line"> <span class="keywordflow">if</span> (<span class="keywordtype">id</span> == GUI_ID_SKIN_TRANSPARENCY)</div><div class="line"> {</div><div class="line"> <span class="keyword">const</span> s32 pos = ((IGUIScrollBar*)event.GUIEvent.Caller)-&gt;getPos();</div><div class="line"> setSkinTransparency(pos, env-&gt;getSkin());</div><div class="line"> }</div><div class="line"> <span class="comment">// control animation speed</span></div><div class="line"> <span class="keywordflow">else</span> <span class="keywordflow">if</span> (<span class="keywordtype">id</span> == GUI_ID_SKIN_ANIMATION_FPS)</div><div class="line"> {</div><div class="line"> <span class="keyword">const</span> s32 pos = ((IGUIScrollBar*)event.GUIEvent.Caller)-&gt;getPos();</div><div class="line"> <span class="keywordflow">if</span> (scene::ESNT_ANIMATED_MESH == Model-&gt;getType())</div><div class="line"> ((scene::IAnimatedMeshSceneNode*)Model)-&gt;setAnimationSpeed((f32)pos);</div><div class="line"> }</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"></div><div class="line"> <span class="keywordflow">case</span> EGET_COMBO_BOX_CHANGED:</div><div class="line"></div><div class="line"> <span class="comment">// control anti-aliasing/filtering</span></div><div class="line"> <span class="keywordflow">if</span> (<span class="keywordtype">id</span> == GUI_ID_TEXTUREFILTER)</div><div class="line"> {</div><div class="line"> OnTextureFilterSelected( (IGUIComboBox*)event.GUIEvent.Caller );</div><div class="line"> }</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"></div><div class="line"> <span class="keywordflow">case</span> EGET_BUTTON_CLICKED:</div><div class="line"></div><div class="line"> <span class="keywordflow">switch</span>(<span class="keywordtype">id</span>)</div><div class="line"> {</div><div class="line"> <span class="keywordflow">case</span> GUI_ID_BUTTON_SET_SCALE:</div><div class="line"> {</div><div class="line"> <span class="comment">// set model scale</span></div><div class="line"> gui::IGUIElement* root = env-&gt;getRootGUIElement();</div><div class="line"> core::vector3df scale;</div><div class="line"> core::stringc s;</div><div class="line"></div><div class="line"> s = root-&gt;getElementFromId(GUI_ID_X_SCALE, <span class="keyword">true</span>)-&gt;getText();</div><div class="line"> scale.X = (f32)atof(s.c_str());</div><div class="line"> s = root-&gt;getElementFromId(GUI_ID_Y_SCALE, <span class="keyword">true</span>)-&gt;getText();</div><div class="line"> scale.Y = (f32)atof(s.c_str());</div><div class="line"> s = root-&gt;getElementFromId(GUI_ID_Z_SCALE, <span class="keyword">true</span>)-&gt;getText();</div><div class="line"> scale.Z = (f32)atof(s.c_str());</div><div class="line"></div><div class="line"> <span class="keywordflow">if</span> (Model)</div><div class="line"> Model-&gt;setScale(scale);</div><div class="line"> updateScaleInfo(Model);</div><div class="line"> }</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"> <span class="keywordflow">case</span> GUI_ID_BUTTON_SCALE_MUL10:</div><div class="line"> <span class="keywordflow">if</span> (Model)</div><div class="line"> Model-&gt;setScale(Model-&gt;getScale()*10.f);</div><div class="line"> updateScaleInfo(Model);</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"> <span class="keywordflow">case</span> GUI_ID_BUTTON_SCALE_DIV10:</div><div class="line"> <span class="keywordflow">if</span> (Model)</div><div class="line"> Model-&gt;setScale(Model-&gt;getScale()*0.1f);</div><div class="line"> updateScaleInfo(Model);</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"> <span class="keywordflow">case</span> GUI_ID_BUTTON_OPEN_MODEL:</div><div class="line"> env-&gt;addFileOpenDialog(L<span class="stringliteral">&quot;Please select a model file to open&quot;</span>);</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"> <span class="keywordflow">case</span> GUI_ID_BUTTON_SHOW_ABOUT:</div><div class="line"> showAboutText();</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"> <span class="keywordflow">case</span> GUI_ID_BUTTON_SHOW_TOOLBOX:</div><div class="line"> createToolBox();</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"> <span class="keywordflow">case</span> GUI_ID_BUTTON_SELECT_ARCHIVE:</div><div class="line"> env-&gt;addFileOpenDialog(L<span class="stringliteral">&quot;Please select your game archive/directory&quot;</span>);</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"> }</div><div class="line"></div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"> <span class="keywordflow">default</span>:</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"> }</div><div class="line"> }</div><div class="line"></div><div class="line"> <span class="keywordflow">return</span> <span class="keyword">false</span>;</div><div class="line"> }</div></div><!-- fragment --><p> Handle key-up events </p><div class="fragment"><div class="line"><span class="keywordtype">bool</span> OnKeyUp(irr::EKEY_CODE keyCode)</div><div class="line">{</div><div class="line"> <span class="comment">// Don&#39;t handle keys if we have a modal dialog open as it would lead</span></div><div class="line"> <span class="comment">// to unexpected application behaviour for the user.</span></div><div class="line"> <span class="keywordflow">if</span> ( hasModalDialog() )</div><div class="line"> <span class="keywordflow">return</span> <span class="keyword">false</span>;</div><div class="line"></div><div class="line"> <span class="comment">// Escape swaps Camera Input</span></div><div class="line"> <span class="keywordflow">if</span> (keyCode == irr::KEY_ESCAPE)</div><div class="line"> {</div><div class="line"> <span class="keywordflow">if</span> (Device)</div><div class="line"> {</div><div class="line"> scene::ICameraSceneNode * camera =</div><div class="line"> Device-&gt;getSceneManager()-&gt;getActiveCamera();</div><div class="line"> <span class="keywordflow">if</span> (camera)</div><div class="line"> {</div><div class="line"> camera-&gt;setInputReceiverEnabled( !camera-&gt;isInputReceiverEnabled() );</div><div class="line"> }</div><div class="line"> <span class="keywordflow">return</span> <span class="keyword">true</span>;</div><div class="line"> }</div><div class="line"> }</div><div class="line"> <span class="keywordflow">else</span> <span class="keywordflow">if</span> (keyCode == irr::KEY_F1)</div><div class="line"> {</div><div class="line"> <span class="comment">// Swap display of position information about the camera</span></div><div class="line"> <span class="keywordflow">if</span> (Device)</div><div class="line"> {</div><div class="line"> IGUIElement* elem = Device-&gt;getGUIEnvironment()-&gt;getRootGUIElement()-&gt;getElementFromId(GUI_ID_POSITION_TEXT);</div><div class="line"> <span class="keywordflow">if</span> (elem)</div><div class="line"> elem-&gt;setVisible(!elem-&gt;isVisible());</div><div class="line"> }</div><div class="line"> }</div><div class="line"> <span class="keywordflow">else</span> <span class="keywordflow">if</span> (keyCode == irr::KEY_KEY_M)</div><div class="line"> {</div><div class="line"> <span class="keywordflow">if</span> (Device)</div><div class="line"> Device-&gt;minimizeWindow();</div><div class="line"> }</div><div class="line"> <span class="keywordflow">else</span> <span class="keywordflow">if</span> (keyCode == irr::KEY_KEY_L)</div><div class="line"> {</div><div class="line"> UseLight=!UseLight;</div><div class="line"> <span class="keywordflow">if</span> (Model)</div><div class="line"> {</div><div class="line"> Model-&gt;setMaterialFlag(video::EMF_LIGHTING, UseLight);</div><div class="line"> Model-&gt;setMaterialFlag(video::EMF_NORMALIZE_NORMALS, UseLight);</div><div class="line"> }</div><div class="line"> }</div><div class="line"> <span class="keywordflow">return</span> <span class="keyword">false</span>;</div><div class="line">}</div></div><!-- fragment --><p> Handle "menu item clicked" events. </p><div class="fragment"><div class="line"><span class="keywordtype">void</span> OnMenuItemSelected( IGUIContextMenu* menu )</div><div class="line">{</div><div class="line"> s32 <span class="keywordtype">id</span> = menu-&gt;getItemCommandId(menu-&gt;getSelectedItem());</div><div class="line"> IGUIEnvironment* env = Device-&gt;getGUIEnvironment();</div><div class="line"></div><div class="line"> <span class="keywordflow">switch</span>(<span class="keywordtype">id</span>)</div><div class="line"> {</div><div class="line"> <span class="keywordflow">case</span> GUI_ID_OPEN_MODEL: <span class="comment">// File -&gt; Open Model File &amp; Texture</span></div><div class="line"> env-&gt;addFileOpenDialog(L<span class="stringliteral">&quot;Please select a model file to open&quot;</span>);</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"> <span class="keywordflow">case</span> GUI_ID_SET_MODEL_ARCHIVE: <span class="comment">// File -&gt; Set Model Archive</span></div><div class="line"> env-&gt;addFileOpenDialog(L<span class="stringliteral">&quot;Please select your game archive/directory&quot;</span>);</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"> <span class="keywordflow">case</span> GUI_ID_LOAD_AS_OCTREE: <span class="comment">// File -&gt; LoadAsOctree</span></div><div class="line"> Octree = !Octree;</div><div class="line"> menu-&gt;setItemChecked(menu-&gt;getSelectedItem(), Octree);</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"> <span class="keywordflow">case</span> GUI_ID_QUIT: <span class="comment">// File -&gt; Quit</span></div><div class="line"> Device-&gt;closeDevice();</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"> <span class="keywordflow">case</span> GUI_ID_SKY_BOX_VISIBLE: <span class="comment">// View -&gt; Skybox</span></div><div class="line"> menu-&gt;setItemChecked(menu-&gt;getSelectedItem(), !menu-&gt;isItemChecked(menu-&gt;getSelectedItem()));</div><div class="line"> SkyBox-&gt;setVisible(!SkyBox-&gt;isVisible());</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"> <span class="keywordflow">case</span> GUI_ID_DEBUG_OFF: <span class="comment">// View -&gt; Debug Information</span></div><div class="line"> menu-&gt;setItemChecked(menu-&gt;getSelectedItem()+1, <span class="keyword">false</span>);</div><div class="line"> menu-&gt;setItemChecked(menu-&gt;getSelectedItem()+2, <span class="keyword">false</span>);</div><div class="line"> menu-&gt;setItemChecked(menu-&gt;getSelectedItem()+3, <span class="keyword">false</span>);</div><div class="line"> menu-&gt;setItemChecked(menu-&gt;getSelectedItem()+4, <span class="keyword">false</span>);</div><div class="line"> menu-&gt;setItemChecked(menu-&gt;getSelectedItem()+5, <span class="keyword">false</span>);</div><div class="line"> menu-&gt;setItemChecked(menu-&gt;getSelectedItem()+6, <span class="keyword">false</span>);</div><div class="line"> <span class="keywordflow">if</span> (Model)</div><div class="line"> Model-&gt;setDebugDataVisible(scene::EDS_OFF);</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"> <span class="keywordflow">case</span> GUI_ID_DEBUG_BOUNDING_BOX: <span class="comment">// View -&gt; Debug Information</span></div><div class="line"> menu-&gt;setItemChecked(menu-&gt;getSelectedItem(), !menu-&gt;isItemChecked(menu-&gt;getSelectedItem()));</div><div class="line"> <span class="keywordflow">if</span> (Model)</div><div class="line"> Model-&gt;setDebugDataVisible((scene::E_DEBUG_SCENE_TYPE)(Model-&gt;isDebugDataVisible()^scene::EDS_BBOX));</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"> <span class="keywordflow">case</span> GUI_ID_DEBUG_NORMALS: <span class="comment">// View -&gt; Debug Information</span></div><div class="line"> menu-&gt;setItemChecked(menu-&gt;getSelectedItem(), !menu-&gt;isItemChecked(menu-&gt;getSelectedItem()));</div><div class="line"> <span class="keywordflow">if</span> (Model)</div><div class="line"> Model-&gt;setDebugDataVisible((scene::E_DEBUG_SCENE_TYPE)(Model-&gt;isDebugDataVisible()^scene::EDS_NORMALS));</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"> <span class="keywordflow">case</span> GUI_ID_DEBUG_SKELETON: <span class="comment">// View -&gt; Debug Information</span></div><div class="line"> menu-&gt;setItemChecked(menu-&gt;getSelectedItem(), !menu-&gt;isItemChecked(menu-&gt;getSelectedItem()));</div><div class="line"> <span class="keywordflow">if</span> (Model)</div><div class="line"> Model-&gt;setDebugDataVisible((scene::E_DEBUG_SCENE_TYPE)(Model-&gt;isDebugDataVisible()^scene::EDS_SKELETON));</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"> <span class="keywordflow">case</span> GUI_ID_DEBUG_WIRE_OVERLAY: <span class="comment">// View -&gt; Debug Information</span></div><div class="line"> menu-&gt;setItemChecked(menu-&gt;getSelectedItem(), !menu-&gt;isItemChecked(menu-&gt;getSelectedItem()));</div><div class="line"> <span class="keywordflow">if</span> (Model)</div><div class="line"> Model-&gt;setDebugDataVisible((scene::E_DEBUG_SCENE_TYPE)(Model-&gt;isDebugDataVisible()^scene::EDS_MESH_WIRE_OVERLAY));</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"> <span class="keywordflow">case</span> GUI_ID_DEBUG_HALF_TRANSPARENT: <span class="comment">// View -&gt; Debug Information</span></div><div class="line"> menu-&gt;setItemChecked(menu-&gt;getSelectedItem(), !menu-&gt;isItemChecked(menu-&gt;getSelectedItem()));</div><div class="line"> <span class="keywordflow">if</span> (Model)</div><div class="line"> Model-&gt;setDebugDataVisible((scene::E_DEBUG_SCENE_TYPE)(Model-&gt;isDebugDataVisible()^scene::EDS_HALF_TRANSPARENCY));</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"> <span class="keywordflow">case</span> GUI_ID_DEBUG_BUFFERS_BOUNDING_BOXES: <span class="comment">// View -&gt; Debug Information</span></div><div class="line"> menu-&gt;setItemChecked(menu-&gt;getSelectedItem(), !menu-&gt;isItemChecked(menu-&gt;getSelectedItem()));</div><div class="line"> <span class="keywordflow">if</span> (Model)</div><div class="line"> Model-&gt;setDebugDataVisible((scene::E_DEBUG_SCENE_TYPE)(Model-&gt;isDebugDataVisible()^scene::EDS_BBOX_BUFFERS));</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"> <span class="keywordflow">case</span> GUI_ID_DEBUG_ALL: <span class="comment">// View -&gt; Debug Information</span></div><div class="line"> menu-&gt;setItemChecked(menu-&gt;getSelectedItem()-1, <span class="keyword">true</span>);</div><div class="line"> menu-&gt;setItemChecked(menu-&gt;getSelectedItem()-2, <span class="keyword">true</span>);</div><div class="line"> menu-&gt;setItemChecked(menu-&gt;getSelectedItem()-3, <span class="keyword">true</span>);</div><div class="line"> menu-&gt;setItemChecked(menu-&gt;getSelectedItem()-4, <span class="keyword">true</span>);</div><div class="line"> menu-&gt;setItemChecked(menu-&gt;getSelectedItem()-5, <span class="keyword">true</span>);</div><div class="line"> menu-&gt;setItemChecked(menu-&gt;getSelectedItem()-6, <span class="keyword">true</span>);</div><div class="line"> <span class="keywordflow">if</span> (Model)</div><div class="line"> Model-&gt;setDebugDataVisible(scene::EDS_FULL);</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"> <span class="keywordflow">case</span> GUI_ID_ABOUT: <span class="comment">// Help-&gt;About</span></div><div class="line"> showAboutText();</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"> <span class="keywordflow">case</span> GUI_ID_MODEL_MATERIAL_SOLID: <span class="comment">// View -&gt; Material -&gt; Solid</span></div><div class="line"> <span class="keywordflow">if</span> (Model)</div><div class="line"> Model-&gt;setMaterialType(video::EMT_SOLID);</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"> <span class="keywordflow">case</span> GUI_ID_MODEL_MATERIAL_TRANSPARENT: <span class="comment">// View -&gt; Material -&gt; Transparent</span></div><div class="line"> <span class="keywordflow">if</span> (Model)</div><div class="line"> Model-&gt;setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR);</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"> <span class="keywordflow">case</span> GUI_ID_MODEL_MATERIAL_REFLECTION: <span class="comment">// View -&gt; Material -&gt; Reflection</span></div><div class="line"> <span class="keywordflow">if</span> (Model)</div><div class="line"> Model-&gt;setMaterialType(video::EMT_SPHERE_MAP);</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"></div><div class="line"> <span class="keywordflow">case</span> GUI_ID_CAMERA_MAYA:</div><div class="line"> setActiveCamera(Camera[0]);</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"> <span class="keywordflow">case</span> GUI_ID_CAMERA_FIRST_PERSON:</div><div class="line"> setActiveCamera(Camera[1]);</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"> }</div><div class="line">}</div></div><!-- fragment --><p> Handle the event that one of the texture-filters was selected in the corresponding combobox. </p><div class="fragment"><div class="line"> <span class="keywordtype">void</span> OnTextureFilterSelected( IGUIComboBox* combo )</div><div class="line"> {</div><div class="line"> s32 pos = combo-&gt;getSelected();</div><div class="line"> <span class="keywordflow">switch</span> (pos)</div><div class="line"> {</div><div class="line"> <span class="keywordflow">case</span> 0:</div><div class="line"> <span class="keywordflow">if</span> (Model)</div><div class="line"> {</div><div class="line"> Model-&gt;setMaterialFlag(video::EMF_BILINEAR_FILTER, <span class="keyword">false</span>);</div><div class="line"> Model-&gt;setMaterialFlag(video::EMF_TRILINEAR_FILTER, <span class="keyword">false</span>);</div><div class="line"> Model-&gt;setMaterialFlag(video::EMF_ANISOTROPIC_FILTER, <span class="keyword">false</span>);</div><div class="line"> }</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"> <span class="keywordflow">case</span> 1:</div><div class="line"> <span class="keywordflow">if</span> (Model)</div><div class="line"> {</div><div class="line"> Model-&gt;setMaterialFlag(video::EMF_BILINEAR_FILTER, <span class="keyword">true</span>);</div><div class="line"> Model-&gt;setMaterialFlag(video::EMF_TRILINEAR_FILTER, <span class="keyword">false</span>);</div><div class="line"> }</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"> <span class="keywordflow">case</span> 2:</div><div class="line"> <span class="keywordflow">if</span> (Model)</div><div class="line"> {</div><div class="line"> Model-&gt;setMaterialFlag(video::EMF_BILINEAR_FILTER, <span class="keyword">false</span>);</div><div class="line"> Model-&gt;setMaterialFlag(video::EMF_TRILINEAR_FILTER, <span class="keyword">true</span>);</div><div class="line"> }</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"> <span class="keywordflow">case</span> 3:</div><div class="line"> <span class="keywordflow">if</span> (Model)</div><div class="line"> {</div><div class="line"> Model-&gt;setMaterialFlag(video::EMF_ANISOTROPIC_FILTER, <span class="keyword">true</span>);</div><div class="line"> }</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"> <span class="keywordflow">case</span> 4:</div><div class="line"> <span class="keywordflow">if</span> (Model)</div><div class="line"> {</div><div class="line"> Model-&gt;setMaterialFlag(video::EMF_ANISOTROPIC_FILTER, <span class="keyword">false</span>);</div><div class="line"> }</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"> }</div><div class="line"> }</div><div class="line">};</div></div><!-- fragment --><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 createDevice(). 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><div class="fragment"><div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span>* argv[])</div><div class="line">{</div><div class="line"> <span class="comment">// ask user for driver</span></div><div class="line"> video::E_DRIVER_TYPE driverType=driverChoiceConsole();</div><div class="line"> <span class="keywordflow">if</span> (driverType==video::EDT_COUNT)</div><div class="line"> <span class="keywordflow">return</span> 1;</div><div class="line"></div><div class="line"> <span class="comment">// create device and exit if creation failed</span></div><div class="line"> MyEventReceiver receiver;</div><div class="line"> Device = createDevice(driverType, core::dimension2d&lt;u32&gt;(800, 600),</div><div class="line"> 16, <span class="keyword">false</span>, <span class="keyword">false</span>, <span class="keyword">false</span>, &amp;receiver);</div><div class="line"></div><div class="line"> <span class="keywordflow">if</span> (Device == 0)</div><div class="line"> <span class="keywordflow">return</span> 1; <span class="comment">// could not create selected driver.</span></div><div class="line"></div><div class="line"> Device-&gt;setResizable(<span class="keyword">true</span>);</div><div class="line"></div><div class="line"> Device-&gt;setWindowCaption(L<span class="stringliteral">&quot;Irrlicht Engine - Loading...&quot;</span>);</div><div class="line"></div><div class="line"> video::IVideoDriver* driver = Device-&gt;getVideoDriver();</div><div class="line"> IGUIEnvironment* env = Device-&gt;getGUIEnvironment();</div><div class="line"> scene::ISceneManager* smgr = Device-&gt;getSceneManager();</div><div class="line"> smgr-&gt;getParameters()-&gt;setAttribute(scene::COLLADA_CREATE_SCENE_INSTANCES, <span class="keyword">true</span>);</div><div class="line"></div><div class="line"> driver-&gt;setTextureCreationFlag(video::ETCF_ALWAYS_32_BIT, <span class="keyword">true</span>);</div><div class="line"></div><div class="line"> smgr-&gt;addLightSceneNode(0, core::vector3df(200,200,200),</div><div class="line"> video::SColorf(1.0f,1.0f,1.0f),2000);</div><div class="line"> smgr-&gt;setAmbientLight(video::SColorf(0.3f,0.3f,0.3f));</div><div class="line"> <span class="comment">// add our media directory as &quot;search path&quot;</span></div><div class="line"> Device-&gt;getFileSystem()-&gt;addFileArchive(getExampleMediaPath());</div></div><!-- fragment --><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>
  202. <pre class="fragment"> &lt;?xml version="1.0"?&gt;
  203. &lt;config&gt;
  204. &lt;startUpModel file="some filename" /&gt;
  205. &lt;messageText caption="Irrlicht Engine Mesh Viewer"&gt;
  206. Hello!
  207. &lt;/messageText&gt;
  208. &lt;/config&gt;</pre><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><div class="fragment"><div class="line"><span class="comment">// read configuration from xml file</span></div><div class="line"></div><div class="line">io::IXMLReader* xml = Device-&gt;getFileSystem()-&gt;createXMLReader( L<span class="stringliteral">&quot;config.xml&quot;</span>);</div><div class="line"></div><div class="line"><span class="keywordflow">while</span>(xml &amp;&amp; xml-&gt;read())</div><div class="line">{</div><div class="line"> <span class="keywordflow">switch</span>(xml-&gt;getNodeType())</div><div class="line"> {</div><div class="line"> <span class="keywordflow">case</span> io::EXN_TEXT:</div><div class="line"> <span class="comment">// in this xml file, the only text which occurs is the</span></div><div class="line"> <span class="comment">// messageText</span></div><div class="line"> MessageText = xml-&gt;getNodeData();</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"> <span class="keywordflow">case</span> io::EXN_ELEMENT:</div><div class="line"> {</div><div class="line"> <span class="keywordflow">if</span> (core::stringw(<span class="stringliteral">&quot;startUpModel&quot;</span>) == xml-&gt;getNodeName())</div><div class="line"> StartUpModelFile = xml-&gt;getAttributeValue(L<span class="stringliteral">&quot;file&quot;</span>);</div><div class="line"> <span class="keywordflow">else</span></div><div class="line"> <span class="keywordflow">if</span> (core::stringw(<span class="stringliteral">&quot;messageText&quot;</span>) == xml-&gt;getNodeName())</div><div class="line"> Caption = xml-&gt;getAttributeValue(L<span class="stringliteral">&quot;caption&quot;</span>);</div><div class="line"> }</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"> <span class="keywordflow">default</span>:</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"> }</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keywordflow">if</span> (xml)</div><div class="line"> xml-&gt;drop(); <span class="comment">// don&#39;t forget to delete the xml reader</span></div><div class="line"></div><div class="line"><span class="comment">// We can pass a model to load per command line parameter</span></div><div class="line"><span class="keywordflow">if</span> (argc &gt; 1)</div><div class="line"> StartUpModelFile = argv[1];</div><div class="line"></div><div class="line"><span class="comment">// set a nicer font</span></div><div class="line">IGUISkin* skin = env-&gt;getSkin();</div><div class="line">IGUIFont* font = env-&gt;getFont(<span class="stringliteral">&quot;fonthaettenschweiler.bmp&quot;</span>);</div><div class="line"><span class="keywordflow">if</span> (font)</div><div class="line"> skin-&gt;setFont(font);</div></div><!-- fragment --><p> Now 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><div class="fragment"><div class="line">gui::IGUIContextMenu* menu = env-&gt;addMenu();</div><div class="line">menu-&gt;addItem(L<span class="stringliteral">&quot;File&quot;</span>, -1, <span class="keyword">true</span>, <span class="keyword">true</span>);</div><div class="line">menu-&gt;addItem(L<span class="stringliteral">&quot;View&quot;</span>, -1, <span class="keyword">true</span>, <span class="keyword">true</span>);</div><div class="line">menu-&gt;addItem(L<span class="stringliteral">&quot;Camera&quot;</span>, -1, <span class="keyword">true</span>, <span class="keyword">true</span>);</div><div class="line">menu-&gt;addItem(L<span class="stringliteral">&quot;Help&quot;</span>, -1, <span class="keyword">true</span>, <span class="keyword">true</span>);</div><div class="line"></div><div class="line">gui::IGUIContextMenu* submenu;</div><div class="line">submenu = menu-&gt;getSubMenu(0);</div><div class="line">submenu-&gt;addItem(L<span class="stringliteral">&quot;Open Model File &amp; Texture...&quot;</span>, GUI_ID_OPEN_MODEL);</div><div class="line">submenu-&gt;addItem(L<span class="stringliteral">&quot;Set Model Archive...&quot;</span>, GUI_ID_SET_MODEL_ARCHIVE);</div><div class="line">submenu-&gt;addItem(L<span class="stringliteral">&quot;Load as Octree&quot;</span>, GUI_ID_LOAD_AS_OCTREE);</div><div class="line">submenu-&gt;addSeparator();</div><div class="line">submenu-&gt;addItem(L<span class="stringliteral">&quot;Quit&quot;</span>, GUI_ID_QUIT);</div><div class="line"></div><div class="line">submenu = menu-&gt;getSubMenu(1);</div><div class="line">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>);</div><div class="line">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>);</div><div class="line">submenu-&gt;addItem(L<span class="stringliteral">&quot;model material&quot;</span>, -1, <span class="keyword">true</span>, <span class="keyword">true</span> );</div><div class="line"></div><div class="line">submenu = submenu-&gt;getSubMenu(1);</div><div class="line">submenu-&gt;addItem(L<span class="stringliteral">&quot;Off&quot;</span>, GUI_ID_DEBUG_OFF);</div><div class="line">submenu-&gt;addItem(L<span class="stringliteral">&quot;Bounding Box&quot;</span>, GUI_ID_DEBUG_BOUNDING_BOX);</div><div class="line">submenu-&gt;addItem(L<span class="stringliteral">&quot;Normals&quot;</span>, GUI_ID_DEBUG_NORMALS);</div><div class="line">submenu-&gt;addItem(L<span class="stringliteral">&quot;Skeleton&quot;</span>, GUI_ID_DEBUG_SKELETON);</div><div class="line">submenu-&gt;addItem(L<span class="stringliteral">&quot;Wire overlay&quot;</span>, GUI_ID_DEBUG_WIRE_OVERLAY);</div><div class="line">submenu-&gt;addItem(L<span class="stringliteral">&quot;Half-Transparent&quot;</span>, GUI_ID_DEBUG_HALF_TRANSPARENT);</div><div class="line">submenu-&gt;addItem(L<span class="stringliteral">&quot;Buffers bounding boxes&quot;</span>, GUI_ID_DEBUG_BUFFERS_BOUNDING_BOXES);</div><div class="line">submenu-&gt;addItem(L<span class="stringliteral">&quot;All&quot;</span>, GUI_ID_DEBUG_ALL);</div><div class="line"></div><div class="line">submenu = menu-&gt;getSubMenu(1)-&gt;getSubMenu(2);</div><div class="line">submenu-&gt;addItem(L<span class="stringliteral">&quot;Solid&quot;</span>, GUI_ID_MODEL_MATERIAL_SOLID);</div><div class="line">submenu-&gt;addItem(L<span class="stringliteral">&quot;Transparent&quot;</span>, GUI_ID_MODEL_MATERIAL_TRANSPARENT);</div><div class="line">submenu-&gt;addItem(L<span class="stringliteral">&quot;Reflection&quot;</span>, GUI_ID_MODEL_MATERIAL_REFLECTION);</div><div class="line"></div><div class="line">submenu = menu-&gt;getSubMenu(2);</div><div class="line">submenu-&gt;addItem(L<span class="stringliteral">&quot;Maya Style&quot;</span>, GUI_ID_CAMERA_MAYA);</div><div class="line">submenu-&gt;addItem(L<span class="stringliteral">&quot;First Person&quot;</span>, GUI_ID_CAMERA_FIRST_PERSON);</div><div class="line"></div><div class="line">submenu = menu-&gt;getSubMenu(3);</div><div class="line">submenu-&gt;addItem(L<span class="stringliteral">&quot;About&quot;</span>, GUI_ID_ABOUT);</div></div><!-- fragment --><p> Below the menu we want a toolbar, onto which we can place colored buttons and important looking stuff like a senseless combobox. </p><div class="fragment"><div class="line"><span class="comment">// create toolbar</span></div><div class="line"></div><div class="line">gui::IGUIToolBar* bar = env-&gt;addToolBar();</div><div class="line"></div><div class="line">video::ITexture* image = driver-&gt;getTexture(<span class="stringliteral">&quot;open.png&quot;</span>);</div><div class="line">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>);</div><div class="line"></div><div class="line">image = driver-&gt;getTexture(<span class="stringliteral">&quot;tools.png&quot;</span>);</div><div class="line">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>);</div><div class="line"></div><div class="line">image = driver-&gt;getTexture(<span class="stringliteral">&quot;zip.png&quot;</span>);</div><div class="line">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>);</div><div class="line"></div><div class="line">image = driver-&gt;getTexture(<span class="stringliteral">&quot;help.png&quot;</span>);</div><div class="line">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>);</div><div class="line"></div><div class="line"><span class="comment">// create a combobox for texture filters</span></div><div class="line"></div><div class="line">gui::IGUIComboBox* box = env-&gt;addComboBox(core::rect&lt;s32&gt;(250,4,350,23), bar, GUI_ID_TEXTUREFILTER);</div><div class="line">box-&gt;addItem(L<span class="stringliteral">&quot;No filtering&quot;</span>);</div><div class="line">box-&gt;addItem(L<span class="stringliteral">&quot;Bilinear&quot;</span>);</div><div class="line">box-&gt;addItem(L<span class="stringliteral">&quot;Trilinear&quot;</span>);</div><div class="line">box-&gt;addItem(L<span class="stringliteral">&quot;Anisotropic&quot;</span>);</div><div class="line">box-&gt;addItem(L<span class="stringliteral">&quot;Isotropic&quot;</span>);</div></div><!-- fragment --><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><div class="fragment"><div class="line"><span class="comment">// disable alpha</span></div><div class="line"></div><div class="line"><span class="keywordflow">for</span> (s32 i=0; i&lt;gui::EGDC_COUNT ; ++i)</div><div class="line">{</div><div class="line"> video::SColor col = env-&gt;getSkin()-&gt;getColor((gui::EGUI_DEFAULT_COLOR)i);</div><div class="line"> col.setAlpha(255);</div><div class="line"> env-&gt;getSkin()-&gt;setColor((gui::EGUI_DEFAULT_COLOR)i, col);</div><div class="line">}</div><div class="line"></div><div class="line"><span class="comment">// add a tabcontrol</span></div><div class="line"></div><div class="line">createToolBox();</div><div class="line"></div><div class="line"><span class="comment">// create fps text</span></div><div class="line"></div><div class="line">IGUIStaticText* fpstext = env-&gt;addStaticText(L<span class="stringliteral">&quot;&quot;</span>,</div><div class="line"> core::rect&lt;s32&gt;(400,4,570,23), <span class="keyword">true</span>, <span class="keyword">false</span>, bar);</div><div class="line"></div><div class="line">IGUIStaticText* postext = env-&gt;addStaticText(L<span class="stringliteral">&quot;&quot;</span>,</div><div class="line"> core::rect&lt;s32&gt;(10,50,470,80),<span class="keyword">false</span>, <span class="keyword">false</span>, 0, GUI_ID_POSITION_TEXT);</div><div class="line">postext-&gt;setVisible(<span class="keyword">false</span>);</div><div class="line"></div><div class="line"><span class="comment">// set window caption</span></div><div class="line">Caption += <span class="stringliteral">&quot; - [&quot;</span>;</div><div class="line">Caption += driver-&gt;getName();</div><div class="line">Caption += <span class="stringliteral">&quot;]&quot;</span>;</div><div class="line">Device-&gt;setWindowCaption(Caption.c_str());</div></div><!-- fragment --><p> Now we show the about message box at start up, and load the first model. To make everything look better a skybox is created. We also add a user controlled camera, to make the application more interactive. Finally, everything is drawn in a standard drawing loop. </p><div class="fragment"><div class="line"> <span class="comment">// show about message box and load default model</span></div><div class="line"> <span class="keywordflow">if</span> (argc==1)</div><div class="line"> showAboutText();</div><div class="line"> loadModel(StartUpModelFile.c_str());</div><div class="line"></div><div class="line"> <span class="comment">// add skybox</span></div><div class="line"> SkyBox = smgr-&gt;addSkyBoxSceneNode(</div><div class="line"> driver-&gt;getTexture(<span class="stringliteral">&quot;irrlicht2_up.jpg&quot;</span>),</div><div class="line"> driver-&gt;getTexture(<span class="stringliteral">&quot;irrlicht2_dn.jpg&quot;</span>),</div><div class="line"> driver-&gt;getTexture(<span class="stringliteral">&quot;irrlicht2_lf.jpg&quot;</span>),</div><div class="line"> driver-&gt;getTexture(<span class="stringliteral">&quot;irrlicht2_rt.jpg&quot;</span>),</div><div class="line"> driver-&gt;getTexture(<span class="stringliteral">&quot;irrlicht2_ft.jpg&quot;</span>),</div><div class="line"> driver-&gt;getTexture(<span class="stringliteral">&quot;irrlicht2_bk.jpg&quot;</span>));</div><div class="line"></div><div class="line"> <span class="comment">// add a camera scene node</span></div><div class="line"> Camera[0] = smgr-&gt;addCameraSceneNodeMaya();</div><div class="line"> Camera[0]-&gt;setFarValue(20000.f);</div><div class="line"> <span class="comment">// Maya cameras reposition themselves relative to their target, so target the location</span></div><div class="line"> <span class="comment">// where the mesh scene node is placed.</span></div><div class="line"> Camera[0]-&gt;setTarget(core::vector3df(0,30,0));</div><div class="line"></div><div class="line"> Camera[1] = smgr-&gt;addCameraSceneNodeFPS();</div><div class="line"> Camera[1]-&gt;setFarValue(20000.f);</div><div class="line"> Camera[1]-&gt;setPosition(core::vector3df(0,0,-70));</div><div class="line"> Camera[1]-&gt;setTarget(core::vector3df(0,30,0));</div><div class="line"></div><div class="line"> setActiveCamera(Camera[0]);</div><div class="line"></div><div class="line"> <span class="comment">// load the irrlicht engine logo</span></div><div class="line"> IGUIImage *img =</div><div class="line"> env-&gt;addImage(driver-&gt;getTexture(<span class="stringliteral">&quot;irrlichtlogo3.png&quot;</span>),</div><div class="line"> core::position2d&lt;s32&gt;(10, driver-&gt;getScreenSize().Height - 128));</div><div class="line"></div><div class="line"> <span class="comment">// lock the logo&#39;s edges to the bottom left corner of the screen</span></div><div class="line"> img-&gt;setAlignment(EGUIA_UPPERLEFT, EGUIA_UPPERLEFT,</div><div class="line"> EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT);</div><div class="line"></div><div class="line"> <span class="comment">// remember state so we notice when the window does lose the focus</span></div><div class="line"> <span class="keywordtype">bool</span> hasFocus = Device-&gt;isWindowFocused();</div><div class="line"></div><div class="line"> <span class="comment">// draw everything</span></div><div class="line"> <span class="keywordflow">while</span>(Device-&gt;run() &amp;&amp; driver)</div><div class="line"> {</div><div class="line"> <span class="comment">// Catch focus changes (workaround until Irrlicht has events for this)</span></div><div class="line"> <span class="keywordtype">bool</span> focused = Device-&gt;isWindowFocused();</div><div class="line"> <span class="keywordflow">if</span> ( hasFocus &amp;&amp; !focused )</div><div class="line"> onKillFocus();</div><div class="line"> hasFocus = focused;</div><div class="line"></div><div class="line"> <span class="keywordflow">if</span> (Device-&gt;isWindowActive())</div><div class="line"> {</div><div class="line"> driver-&gt;beginScene(video::ECBF_COLOR | video::ECBF_DEPTH, video::SColor(150,50,50,50));</div><div class="line"></div><div class="line"> smgr-&gt;drawAll();</div><div class="line"> env-&gt;drawAll();</div><div class="line"></div><div class="line"> driver-&gt;endScene();</div><div class="line"></div><div class="line"> <span class="comment">// update information about current frame-rate</span></div><div class="line"> core::stringw str(L<span class="stringliteral">&quot;FPS: &quot;</span>);</div><div class="line"> str.append(core::stringw(driver-&gt;getFPS()));</div><div class="line"> str += L<span class="stringliteral">&quot; Tris: &quot;</span>;</div><div class="line"> str.append(core::stringw(driver-&gt;getPrimitiveCountDrawn()));</div><div class="line"> fpstext-&gt;setText(str.c_str());</div><div class="line"></div><div class="line"> <span class="comment">// update information about the active camera</span></div><div class="line"> scene::ICameraSceneNode* cam = Device-&gt;getSceneManager()-&gt;getActiveCamera();</div><div class="line"> str = L<span class="stringliteral">&quot;Pos: &quot;</span>;</div><div class="line"> str.append(core::stringw(cam-&gt;getPosition().X));</div><div class="line"> str += L<span class="stringliteral">&quot; &quot;</span>;</div><div class="line"> str.append(core::stringw(cam-&gt;getPosition().Y));</div><div class="line"> str += L<span class="stringliteral">&quot; &quot;</span>;</div><div class="line"> str.append(core::stringw(cam-&gt;getPosition().Z));</div><div class="line"> str += L<span class="stringliteral">&quot; Tgt: &quot;</span>;</div><div class="line"> str.append(core::stringw(cam-&gt;getTarget().X));</div><div class="line"> str += L<span class="stringliteral">&quot; &quot;</span>;</div><div class="line"> str.append(core::stringw(cam-&gt;getTarget().Y));</div><div class="line"> str += L<span class="stringliteral">&quot; &quot;</span>;</div><div class="line"> str.append(core::stringw(cam-&gt;getTarget().Z));</div><div class="line"> postext-&gt;setText(str.c_str());</div><div class="line"></div><div class="line"> <span class="comment">// update the tool dialog</span></div><div class="line"> updateToolBox();</div><div class="line"> }</div><div class="line"> <span class="keywordflow">else</span></div><div class="line"> Device-&gt;yield();</div><div class="line"> }</div><div class="line"></div><div class="line"> Device-&gt;drop();</div><div class="line"> <span class="keywordflow">return</span> 0;</div><div class="line">}</div></div><!-- fragment --> </div></div><!-- contents -->
  209. <!-- HTML footer for doxygen 1.8.13-->
  210. <!-- start footer part -->
  211. <p>&nbsp;</p>
  212. </body>
  213. </html>