Sophie

Sophie

distrib > Mandriva > 2010.1 > x86_64 > media > contrib-release > by-pkgid > 58828b263d8f56d90ac336dea07a4586 > files > 740

irrlicht-doc-1.6.1-1mdv2010.1.x86_64.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>Irrlicht Engine: Tutorial 9: Mesh Viewer</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<table class="irrlicht" >
  <tr valign="middle"> 
    <td><font size="2"><a class="qindex" href="index.html"><font color="#FFFFFF">Home</font></a> 
      | <a class="qindex" href="namespaces.html"><font color="#FFFFFF">Namespaces</font></a> 
      | <a class="qindex" href="hierarchy.html"><font color="#FFFFFF">Hierarchy</font></a> 
      | <a class="qindex" href="classes.html"><font color="#FFFFFF">Alphabetical 
      List</font></a> | <a class="qindex" href="annotated.html"><font color="#FFFFFF"> 
      Class list</font></a> | <a class="qindex" href="files.html"><font color="#FFFFFF">Files</font></a> 
      | <a class="qindex" href="namespacemembers.html"><font color="#FFFFFF"> 
      Namespace&nbsp;Members</font></a> | <a class="qindex" href="functions.html"><font color="#FFFFFF">Class 
      members</font></a> | <a class="qindex" href="globals.html"><font color="#FFFFFF">File 
      members</font></a> | <a class="qindex" href="pages.html"><font color="#FFFFFF">Tutorials</font></a></font> </td>
  </tr>
</table>
<!-- Generated by Doxygen 1.5.6 -->
<div class="contents">
<h1><a class="anchor" name="example009">Tutorial 9: Mesh Viewer </a></h1><div align="center">
<img src="009shot.jpg" alt="009shot.jpg">
</div>
 <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>
We start like in most other tutorials: Include all nesessary 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. <div class="fragment"><pre class="fragment"><span class="preprocessor">#include &lt;<a class="code" href="irrlicht_8h.html" title="Main header file of the irrlicht, the only file needed to include.">irrlicht.h</a>&gt;</span>
<span class="preprocessor">#include &lt;iostream&gt;</span>


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

<span class="preprocessor">#ifdef _MSC_VER</span>
<span class="preprocessor"></span><span class="preprocessor">#pragma comment(lib, "Irrlicht.lib")</span>
<span class="preprocessor">#endif</span>
</pre></div><p>
Some global variables used later on <div class="fragment"><pre class="fragment">IrrlichtDevice *Device = 0;
<a class="code" href="namespaceirr_1_1core.html#de1071a878633f2f6d8a75c5d11fec19" title="Typedef for character strings.">core::stringc</a> StartUpModelFile;
<a class="code" href="namespaceirr_1_1core.html#ef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">core::stringw</a> MessageText;
<a class="code" href="namespaceirr_1_1core.html#ef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">core::stringw</a> Caption;
scene::ISceneNode* Model = 0;
scene::ISceneNode* SkyBox = 0;
<span class="keywordtype">bool</span> Octree=<span class="keyword">false</span>;
<span class="keywordtype">bool</span> useLight=<span class="keyword">false</span>;

scene::ICameraSceneNode* Camera[2] = {0, 0};

<span class="comment">// Values used to identify individual GUI elements</span>
<span class="keyword">enum</span>
{
        GUI_ID_DIALOG_ROOT_WINDOW  = 0x10000,

        GUI_ID_X_SCALE,
        GUI_ID_Y_SCALE,
        GUI_ID_Z_SCALE,

        GUI_ID_OPEN_MODEL,
        GUI_ID_SET_MODEL_ARCHIVE,
        GUI_ID_LOAD_AS_OCTREE,

        GUI_ID_SKY_BOX_VISIBLE,
        GUI_ID_TOGGLE_DEBUG_INFO,

        GUI_ID_DEBUG_OFF,
        GUI_ID_DEBUG_BOUNDING_BOX,
        GUI_ID_DEBUG_NORMALS,
        GUI_ID_DEBUG_SKELETON,
        GUI_ID_DEBUG_WIRE_OVERLAY,
        GUI_ID_DEBUG_HALF_TRANSPARENT,
        GUI_ID_DEBUG_BUFFERS_BOUNDING_BOXES,
        GUI_ID_DEBUG_ALL,

        GUI_ID_MODEL_MATERIAL_SOLID,
        GUI_ID_MODEL_MATERIAL_TRANSPARENT,
        GUI_ID_MODEL_MATERIAL_REFLECTION,

        GUI_ID_CAMERA_MAYA,
        GUI_ID_CAMERA_FIRST_PERSON,

        GUI_ID_POSITION_TEXT,

        GUI_ID_ABOUT,
        GUI_ID_QUIT,

        <span class="comment">// And some magic numbers</span>
        MAX_FRAMERATE = 1000,
        DEFAULT_FRAMERATE = 30
};
</pre></div><p>
Toggle between various cameras <div class="fragment"><pre class="fragment"><span class="keywordtype">void</span> setActiveCamera(scene::ICameraSceneNode* newActive)
{
        <span class="keywordflow">if</span> (0 == Device)
                <span class="keywordflow">return</span>;

        scene::ICameraSceneNode * active = Device-&gt;getSceneManager()-&gt;getActiveCamera();
        active-&gt;setInputReceiverEnabled(<span class="keyword">false</span>);

        newActive-&gt;setInputReceiverEnabled(<span class="keyword">true</span>);
        Device-&gt;getSceneManager()-&gt;setActiveCamera(newActive);
}
</pre></div><p>
The three following functions do several stuff used by the mesh viewer. The first function showAboutText() simply displays a messagebox with a caption and a message text. The texts will be stored in the MessageText and Caption variables at startup. <div class="fragment"><pre class="fragment"><span class="keywordtype">void</span> showAboutText()
{
        <span class="comment">// create modal message box with the text</span>
        <span class="comment">// loaded from the xml file.</span>
        Device-&gt;getGUIEnvironment()-&gt;addMessageBox(
                Caption.c_str(), MessageText.c_str());
}
</pre></div><p>
The second 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. <div class="fragment"><pre class="fragment"><span class="keywordtype">void</span> loadModel(<span class="keyword">const</span> <a class="code" href="namespaceirr.html#9395eaea339bcb546b319e9c96bf7410" title="8 bit character variable.">c8</a>* fn)
{
        <span class="comment">// modify the name if it a .pk3 file</span>

        <a class="code" href="namespaceirr_1_1core.html#de1071a878633f2f6d8a75c5d11fec19" title="Typedef for character strings.">core::stringc</a> filename(fn);

        <a class="code" href="namespaceirr_1_1core.html#de1071a878633f2f6d8a75c5d11fec19" title="Typedef for character strings.">core::stringc</a> extension;
        <a class="code" href="namespaceirr_1_1core.html#651915bc0fdf4cba0154ba84fb150569" title="get the filename extension from a string">core::getFileNameExtension</a>(extension, filename);
        extension.make_lower();

        <span class="comment">// if a texture is loaded apply it to the current model..</span>
        <span class="keywordflow">if</span> (extension == <span class="stringliteral">".jpg"</span> || extension == <span class="stringliteral">".pcx"</span> ||
                extension == <span class="stringliteral">".png"</span> || extension == <span class="stringliteral">".ppm"</span> ||
                extension == <span class="stringliteral">".pgm"</span> || extension == <span class="stringliteral">".pbm"</span> ||
                extension == <span class="stringliteral">".psd"</span> || extension == <span class="stringliteral">".tga"</span> ||
                extension == <span class="stringliteral">".bmp"</span> || extension == <span class="stringliteral">".wal"</span>)
        {
                video::ITexture * texture =
                        Device-&gt;getVideoDriver()-&gt;getTexture( filename );
                <span class="keywordflow">if</span> ( texture &amp;&amp; Model )
                {
                        <span class="comment">// always reload texture</span>
                        Device-&gt;getVideoDriver()-&gt;removeTexture(texture);
                        texture = Device-&gt;getVideoDriver()-&gt;getTexture( filename );

                        Model-&gt;setMaterialTexture(0, texture);
                }
                <span class="keywordflow">return</span>;
        }
        <span class="comment">// if a archive is loaded add it to the FileArchive..</span>
        <span class="keywordflow">else</span> <span class="keywordflow">if</span> (extension == <span class="stringliteral">".pk3"</span> || extension == <span class="stringliteral">".zip"</span>)
        {
                Device-&gt;getFileSystem()-&gt;addZipFileArchive(filename.c_str());
                <span class="keywordflow">return</span>;
        }
        <span class="keywordflow">else</span> <span class="keywordflow">if</span> (extension == <span class="stringliteral">".pak"</span>)
        {
                Device-&gt;getFileSystem()-&gt;addPakFileArchive(filename.c_str());
                <span class="keywordflow">return</span>;
        }

        <span class="comment">// load a model into the engine</span>

        <span class="keywordflow">if</span> (Model)
                Model-&gt;remove();

        Model = 0;

        scene::IAnimatedMesh* m = Device-&gt;getSceneManager()-&gt;getMesh( filename.c_str() );

        <span class="keywordflow">if</span> (!m)
        {
                <span class="comment">// model could not be loaded</span>

                <span class="keywordflow">if</span> (StartUpModelFile != filename)
                        Device-&gt;getGUIEnvironment()-&gt;addMessageBox(
                        Caption.c_str(), L<span class="stringliteral">"The model could not be loaded. "</span> \
                        L<span class="stringliteral">"Maybe it is not a supported file format."</span>);
                <span class="keywordflow">return</span>;
        }

        <span class="comment">// set default material properties</span>

        <span class="keywordflow">if</span> (Octree)
                Model = Device-&gt;getSceneManager()-&gt;addOctTreeSceneNode(m-&gt;getMesh(0));
        <span class="keywordflow">else</span>
        {
                scene::IAnimatedMeshSceneNode* animModel = Device-&gt;getSceneManager()-&gt;addAnimatedMeshSceneNode(m);
                animModel-&gt;setAnimationSpeed(30);
                Model = animModel;
        }
        Model-&gt;setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#8a3bc00ae8137535b9fbc5f40add70d3cea597a2692b8415486a464a7f954d34" title="Will this material be lighted? Default: true.">video::EMF_LIGHTING</a>, useLight);
        Model-&gt;setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#8a3bc00ae8137535b9fbc5f40add70d33efe2d4921909a842adfc44dacc74520" title="Normalizes normals. Default: false.">video::EMF_NORMALIZE_NORMALS</a>, useLight);
<span class="comment">//      Model-&gt;setMaterialFlag(video::EMF_BACK_FACE_CULLING, false);</span>
        Model-&gt;setDebugDataVisible(<a class="code" href="namespaceirr_1_1scene.html#52b664c4c988113735042b168fc32dbe25111b15f03bee9a99498737286916dc" title="No Debug Data ( Default ).">scene::EDS_OFF</a>);

        <span class="comment">// we need to uncheck the menu entries. would be cool to fake a menu event, but</span>
        <span class="comment">// that's not so simple. so we do it brute force</span>
        gui::IGUIContextMenu* menu = (gui::IGUIContextMenu*)Device-&gt;getGUIEnvironment()-&gt;getRootGUIElement()-&gt;getElementFromId(GUI_ID_TOGGLE_DEBUG_INFO, <span class="keyword">true</span>);
        <span class="keywordflow">if</span> (menu)
                <span class="keywordflow">for</span>(<span class="keywordtype">int</span> item = 1; item &lt; 6; ++item)
                        menu-&gt;setItemChecked(item, <span class="keyword">false</span>);
        IGUIElement* toolboxWnd = Device-&gt;getGUIEnvironment()-&gt;getRootGUIElement()-&gt;getElementFromId(GUI_ID_DIALOG_ROOT_WINDOW, <span class="keyword">true</span>);
        <span class="keywordflow">if</span> ( toolboxWnd )
        {
                toolboxWnd-&gt;getElementFromId(GUI_ID_X_SCALE, <span class="keyword">true</span>)-&gt;setText(L<span class="stringliteral">"1.0"</span>);
                toolboxWnd-&gt;getElementFromId(GUI_ID_Y_SCALE, <span class="keyword">true</span>)-&gt;setText(L<span class="stringliteral">"1.0"</span>);
                toolboxWnd-&gt;getElementFromId(GUI_ID_Z_SCALE, <span class="keyword">true</span>)-&gt;setText(L<span class="stringliteral">"1.0"</span>);
        }
}
</pre></div><p>
Finally, the third function 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. <div class="fragment"><pre class="fragment"><span class="keywordtype">void</span> createToolBox()
{
        <span class="comment">// remove tool box if already there</span>
        IGUIEnvironment* env = Device-&gt;getGUIEnvironment();
        IGUIElement* root = env-&gt;getRootGUIElement();
        IGUIElement* e = root-&gt;getElementFromId(GUI_ID_DIALOG_ROOT_WINDOW, <span class="keyword">true</span>);
        <span class="keywordflow">if</span> (e)
                e-&gt;remove();

        <span class="comment">// create the toolbox window</span>
        IGUIWindow* wnd = env-&gt;addWindow(core::rect&lt;s32&gt;(600,45,800,480),
                <span class="keyword">false</span>, L<span class="stringliteral">"Toolset"</span>, 0, GUI_ID_DIALOG_ROOT_WINDOW);

        <span class="comment">// create tab control and tabs</span>
        IGUITabControl* tab = env-&gt;addTabControl(
                core::rect&lt;s32&gt;(2,20,800-602,480-7), wnd, <span class="keyword">true</span>, <span class="keyword">true</span>);

        IGUITab* t1 = tab-&gt;addTab(L<span class="stringliteral">"Config"</span>);

        <span class="comment">// add some edit boxes and a button to tab one</span>
        env-&gt;addStaticText(L<span class="stringliteral">"Scale:"</span>,
                        core::rect&lt;s32&gt;(10,20,150,45), <span class="keyword">false</span>, <span class="keyword">false</span>, t1);
        env-&gt;addStaticText(L<span class="stringliteral">"X:"</span>, core::rect&lt;s32&gt;(22,48,40,66), <span class="keyword">false</span>, <span class="keyword">false</span>, t1);
        env-&gt;addEditBox(L<span class="stringliteral">"1.0"</span>, core::rect&lt;s32&gt;(40,46,130,66), <span class="keyword">true</span>, t1, GUI_ID_X_SCALE);
        env-&gt;addStaticText(L<span class="stringliteral">"Y:"</span>, core::rect&lt;s32&gt;(22,82,40,GUI_ID_OPEN_MODEL), <span class="keyword">false</span>, <span class="keyword">false</span>, t1);
        env-&gt;addEditBox(L<span class="stringliteral">"1.0"</span>, core::rect&lt;s32&gt;(40,76,130,96), <span class="keyword">true</span>, t1, GUI_ID_Y_SCALE);
        env-&gt;addStaticText(L<span class="stringliteral">"Z:"</span>, core::rect&lt;s32&gt;(22,108,40,126), <span class="keyword">false</span>, <span class="keyword">false</span>, t1);
        env-&gt;addEditBox(L<span class="stringliteral">"1.0"</span>, core::rect&lt;s32&gt;(40,106,130,126), <span class="keyword">true</span>, t1, GUI_ID_Z_SCALE);

        env-&gt;addButton(core::rect&lt;s32&gt;(10,134,85,165), t1, 1101, L<span class="stringliteral">"Set"</span>);

        <span class="comment">// add transparency control</span>
        env-&gt;addStaticText(L<span class="stringliteral">"GUI Transparency Control:"</span>,
                        core::rect&lt;s32&gt;(10,200,150,225), <span class="keyword">true</span>, <span class="keyword">false</span>, t1);
        IGUIScrollBar* scrollbar = env-&gt;addScrollBar(<span class="keyword">true</span>,
                        core::rect&lt;s32&gt;(10,225,150,240), t1, 104);
        scrollbar-&gt;setMax(255);
        scrollbar-&gt;setPos(255);

        <span class="comment">// add framerate control</span>
        env-&gt;addStaticText(L<span class="stringliteral">"Framerate:"</span>,
                        core::rect&lt;s32&gt;(10,240,150,265), <span class="keyword">true</span>, <span class="keyword">false</span>, t1);
        scrollbar = env-&gt;addScrollBar(<span class="keyword">true</span>,
                        core::rect&lt;s32&gt;(10,265,150,280), t1, 105);
        scrollbar-&gt;setMax(MAX_FRAMERATE);
        scrollbar-&gt;setPos(DEFAULT_FRAMERATE);

        <span class="comment">// bring irrlicht engine logo to front, because it</span>
        <span class="comment">// now may be below the newly created toolbox</span>
        root-&gt;bringToFront(root-&gt;getElementFromId(666, <span class="keyword">true</span>));
}
</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, if opens a file-open-dialog. <div class="fragment"><pre class="fragment"><span class="keyword">class </span>MyEventReceiver : <span class="keyword">public</span> IEventReceiver
{
<span class="keyword">public</span>:
        <span class="keyword">virtual</span> <span class="keywordtype">bool</span> OnEvent(<span class="keyword">const</span> SEvent&amp; event)
        {
                <span class="comment">// Escape swaps Camera Input</span>
                <span class="keywordflow">if</span> (event.EventType == <a class="code" href="namespaceirr.html#c9eed96e06e85ce3c86fcbbbe9e48a0c6f90390f3147a1693e5e2e3422d6ca09" title="A key input event.">EET_KEY_INPUT_EVENT</a> &amp;&amp;
                        event.KeyInput.PressedDown == <span class="keyword">false</span>)
                {
                        <span class="keywordflow">if</span> (event.KeyInput.Key == <a class="code" href="namespaceirr.html#54da2a0e231901735e3da1b0edf72eb3ab32bfc194f119e5d5b9b39527bbcd61">irr::KEY_ESCAPE</a>)
                        {
                                <span class="keywordflow">if</span> (Device)
                                {
                                        scene::ICameraSceneNode * camera =
                                                Device-&gt;getSceneManager()-&gt;getActiveCamera();
                                        <span class="keywordflow">if</span> (camera)
                                        {
                                                camera-&gt;setInputReceiverEnabled( !camera-&gt;isInputReceiverEnabled() );
                                        }
                                        <span class="keywordflow">return</span> <span class="keyword">true</span>;
                                }
                        }
                        <span class="keywordflow">else</span> <span class="keywordflow">if</span> (event.KeyInput.Key == <a class="code" href="namespaceirr.html#54da2a0e231901735e3da1b0edf72eb35427274e34fd5587155fe8b3b12d96a8">irr::KEY_F1</a>)
                        {
                                <span class="keywordflow">if</span> (Device)
                                {
                                        IGUIElement* elem = Device-&gt;getGUIEnvironment()-&gt;getRootGUIElement()-&gt;getElementFromId(GUI_ID_POSITION_TEXT);
                                        <span class="keywordflow">if</span> (elem)
                                                elem-&gt;setVisible(!elem-&gt;isVisible());
                                }
                        }
                        <span class="keywordflow">else</span> <span class="keywordflow">if</span> (event.KeyInput.Key == <a class="code" href="namespaceirr.html#54da2a0e231901735e3da1b0edf72eb3864770d5fa3f9713dc7a37f66f6b84fc">irr::KEY_KEY_M</a>)
                        {
                                <span class="keywordflow">if</span> (Device)
                                        Device-&gt;minimizeWindow();
                        }
                        <span class="keywordflow">else</span> <span class="keywordflow">if</span> (event.KeyInput.Key == <a class="code" href="namespaceirr.html#54da2a0e231901735e3da1b0edf72eb3e1f51392abd7c04d8129d2c85dbd391c">irr::KEY_KEY_L</a>)
                        {
                                useLight=!useLight;
                                <span class="keywordflow">if</span> (Model)
                                {
                                        Model-&gt;setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#8a3bc00ae8137535b9fbc5f40add70d3cea597a2692b8415486a464a7f954d34" title="Will this material be lighted? Default: true.">video::EMF_LIGHTING</a>, useLight);
                                        Model-&gt;setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#8a3bc00ae8137535b9fbc5f40add70d33efe2d4921909a842adfc44dacc74520" title="Normalizes normals. Default: false.">video::EMF_NORMALIZE_NORMALS</a>, useLight);
                                }
                        }
                }

                <span class="keywordflow">if</span> (event.EventType == <a class="code" href="namespaceirr.html#c9eed96e06e85ce3c86fcbbbe9e48a0ce85bb44dd09a29c879d64a05047fc1d2" title="An event of the graphical user interface.">EET_GUI_EVENT</a>)
                {
                        <a class="code" href="namespaceirr.html#c66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> <span class="keywordtype">id</span> = <span class="keyword">event</span>.GUIEvent.Caller-&gt;getID();
                        IGUIEnvironment* env = Device-&gt;getGUIEnvironment();

                        <span class="keywordflow">switch</span>(event.GUIEvent.EventType)
                        {
                        <span class="keywordflow">case</span> <a class="code" href="namespaceirr_1_1gui.html#eac71ad17341a4b6e9026ae11d57680890e8bebdd49f2a2e451b1105a87ee7ef" title="A menu item was selected in a (context) menu.">EGET_MENU_ITEM_SELECTED</a>:
                                {
                                        <span class="comment">// a menu item was clicked</span>

                                        IGUIContextMenu* menu = (IGUIContextMenu*)event.GUIEvent.Caller;
                                        <a class="code" href="namespaceirr.html#c66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> <span class="keywordtype">id</span> = menu-&gt;getItemCommandId(menu-&gt;getSelectedItem());

                                        <span class="keywordflow">switch</span>(<span class="keywordtype">id</span>)
                                        {
                                        <span class="keywordflow">case</span> GUI_ID_OPEN_MODEL: <span class="comment">// File -&gt; Open Model</span>
                                                env-&gt;addFileOpenDialog(L<span class="stringliteral">"Please select a model file to open"</span>);
                                                <span class="keywordflow">break</span>;
                                        <span class="keywordflow">case</span> GUI_ID_SET_MODEL_ARCHIVE: <span class="comment">// File -&gt; Set Model Archive</span>
                                                env-&gt;addFileOpenDialog(L<span class="stringliteral">"Please select your game archive/directory"</span>);
                                                <span class="keywordflow">break</span>;
                                        <span class="keywordflow">case</span> GUI_ID_LOAD_AS_OCTREE: <span class="comment">// File -&gt; LoadAsOctree</span>
                                                Octree = !Octree;
                                                menu-&gt;setItemChecked(menu-&gt;getSelectedItem(), Octree);
                                                <span class="keywordflow">break</span>;
                                        <span class="keywordflow">case</span> GUI_ID_QUIT: <span class="comment">// File -&gt; Quit</span>
                                                Device-&gt;closeDevice();
                                                <span class="keywordflow">break</span>;
                                        <span class="keywordflow">case</span> GUI_ID_SKY_BOX_VISIBLE: <span class="comment">// View -&gt; Skybox</span>
                                                menu-&gt;setItemChecked(menu-&gt;getSelectedItem(), !menu-&gt;isItemChecked(menu-&gt;getSelectedItem()));
                                                SkyBox-&gt;setVisible(!SkyBox-&gt;isVisible());
                                                <span class="keywordflow">break</span>;
                                        <span class="keywordflow">case</span> GUI_ID_DEBUG_OFF: <span class="comment">// View -&gt; Debug Information</span>
                                                menu-&gt;setItemChecked(menu-&gt;getSelectedItem()+1, <span class="keyword">false</span>);
                                                menu-&gt;setItemChecked(menu-&gt;getSelectedItem()+2, <span class="keyword">false</span>);
                                                menu-&gt;setItemChecked(menu-&gt;getSelectedItem()+3, <span class="keyword">false</span>);
                                                menu-&gt;setItemChecked(menu-&gt;getSelectedItem()+4, <span class="keyword">false</span>);
                                                menu-&gt;setItemChecked(menu-&gt;getSelectedItem()+5, <span class="keyword">false</span>);
                                                menu-&gt;setItemChecked(menu-&gt;getSelectedItem()+6, <span class="keyword">false</span>);
                                                <span class="keywordflow">if</span> (Model)
                                                        Model-&gt;setDebugDataVisible(<a class="code" href="namespaceirr_1_1scene.html#52b664c4c988113735042b168fc32dbe25111b15f03bee9a99498737286916dc" title="No Debug Data ( Default ).">scene::EDS_OFF</a>);
                                                <span class="keywordflow">break</span>;
                                        <span class="keywordflow">case</span> GUI_ID_DEBUG_BOUNDING_BOX: <span class="comment">// View -&gt; Debug Information</span>
                                                menu-&gt;setItemChecked(menu-&gt;getSelectedItem(), !menu-&gt;isItemChecked(menu-&gt;getSelectedItem()));
                                                <span class="keywordflow">if</span> (Model)
                                                        Model-&gt;setDebugDataVisible((<a class="code" href="namespaceirr_1_1scene.html#52b664c4c988113735042b168fc32dbe" 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#52b664c4c988113735042b168fc32dbe19e56bb3d3b18134fa63e0529629b427" title="Show Bounding Boxes of SceneNode.">scene::EDS_BBOX</a>));
                                                <span class="keywordflow">break</span>;
                                        <span class="keywordflow">case</span> GUI_ID_DEBUG_NORMALS: <span class="comment">// View -&gt; Debug Information</span>
                                                menu-&gt;setItemChecked(menu-&gt;getSelectedItem(), !menu-&gt;isItemChecked(menu-&gt;getSelectedItem()));
                                                <span class="keywordflow">if</span> (Model)
                                                        Model-&gt;setDebugDataVisible((<a class="code" href="namespaceirr_1_1scene.html#52b664c4c988113735042b168fc32dbe" 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#52b664c4c988113735042b168fc32dbe2713e470ee18ec9bfe40fdfb502f8b05" title="Show Vertex Normals.">scene::EDS_NORMALS</a>));
                                                <span class="keywordflow">break</span>;
                                        <span class="keywordflow">case</span> GUI_ID_DEBUG_SKELETON: <span class="comment">// View -&gt; Debug Information</span>
                                                menu-&gt;setItemChecked(menu-&gt;getSelectedItem(), !menu-&gt;isItemChecked(menu-&gt;getSelectedItem()));
                                                <span class="keywordflow">if</span> (Model)
                                                        Model-&gt;setDebugDataVisible((<a class="code" href="namespaceirr_1_1scene.html#52b664c4c988113735042b168fc32dbe" 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#52b664c4c988113735042b168fc32dbea7664e189b8641ac54cf27f70f6d8144" title="Shows Skeleton/Tags.">scene::EDS_SKELETON</a>));
                                                <span class="keywordflow">break</span>;
                                        <span class="keywordflow">case</span> GUI_ID_DEBUG_WIRE_OVERLAY: <span class="comment">// View -&gt; Debug Information</span>
                                                menu-&gt;setItemChecked(menu-&gt;getSelectedItem(), !menu-&gt;isItemChecked(menu-&gt;getSelectedItem()));
                                                <span class="keywordflow">if</span> (Model)
                                                        Model-&gt;setDebugDataVisible((<a class="code" href="namespaceirr_1_1scene.html#52b664c4c988113735042b168fc32dbe" 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#52b664c4c988113735042b168fc32dbe349b086537ac770f09935af4e31d3f3e" title="Overlays Mesh Wireframe.">scene::EDS_MESH_WIRE_OVERLAY</a>));
                                                <span class="keywordflow">break</span>;
                                        <span class="keywordflow">case</span> GUI_ID_DEBUG_HALF_TRANSPARENT: <span class="comment">// View -&gt; Debug Information</span>
                                                menu-&gt;setItemChecked(menu-&gt;getSelectedItem(), !menu-&gt;isItemChecked(menu-&gt;getSelectedItem()));
                                                <span class="keywordflow">if</span> (Model)
                                                        Model-&gt;setDebugDataVisible((<a class="code" href="namespaceirr_1_1scene.html#52b664c4c988113735042b168fc32dbe" 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#52b664c4c988113735042b168fc32dbe1def9e1b7d86e286b07a4b7179e6ed85" title="Temporary use transparency Material Type.">scene::EDS_HALF_TRANSPARENCY</a>));
                                                <span class="keywordflow">break</span>;
                                        <span class="keywordflow">case</span> GUI_ID_DEBUG_BUFFERS_BOUNDING_BOXES: <span class="comment">// View -&gt; Debug Information</span>
                                                menu-&gt;setItemChecked(menu-&gt;getSelectedItem(), !menu-&gt;isItemChecked(menu-&gt;getSelectedItem()));
                                                <span class="keywordflow">if</span> (Model)
                                                        Model-&gt;setDebugDataVisible((<a class="code" href="namespaceirr_1_1scene.html#52b664c4c988113735042b168fc32dbe" 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#52b664c4c988113735042b168fc32dbe0179a3df80ac09143dfffed0bd9e99d1" title="Show Bounding Boxes of all MeshBuffers.">scene::EDS_BBOX_BUFFERS</a>));
                                                <span class="keywordflow">break</span>;
                                        <span class="keywordflow">case</span> GUI_ID_DEBUG_ALL: <span class="comment">// View -&gt; Debug Information</span>
                                                menu-&gt;setItemChecked(menu-&gt;getSelectedItem()-1, <span class="keyword">true</span>);
                                                menu-&gt;setItemChecked(menu-&gt;getSelectedItem()-2, <span class="keyword">true</span>);
                                                menu-&gt;setItemChecked(menu-&gt;getSelectedItem()-3, <span class="keyword">true</span>);
                                                menu-&gt;setItemChecked(menu-&gt;getSelectedItem()-4, <span class="keyword">true</span>);
                                                menu-&gt;setItemChecked(menu-&gt;getSelectedItem()-5, <span class="keyword">true</span>);
                                                menu-&gt;setItemChecked(menu-&gt;getSelectedItem()-6, <span class="keyword">true</span>);
                                                <span class="keywordflow">if</span> (Model)
                                                        Model-&gt;setDebugDataVisible(<a class="code" href="namespaceirr_1_1scene.html#52b664c4c988113735042b168fc32dbe24ffe5e6e99d589b3c80181e7c7dd4e2" title="Show all debug infos.">scene::EDS_FULL</a>);
                                                <span class="keywordflow">break</span>;
                                        <span class="keywordflow">case</span> GUI_ID_ABOUT: <span class="comment">// Help-&gt;About</span>
                                                showAboutText();
                                                <span class="keywordflow">break</span>;
                                        <span class="keywordflow">case</span> GUI_ID_MODEL_MATERIAL_SOLID: <span class="comment">// View -&gt; Material -&gt; Solid</span>
                                                <span class="keywordflow">if</span> (Model)
                                                        Model-&gt;setMaterialType(<a class="code" href="namespaceirr_1_1video.html#c8e9b6c66f7cebabd1a6d30cbc5430f19bc471b9c18c9e2d20496004d2a2e803" title="Standard solid material.">video::EMT_SOLID</a>);
                                                <span class="keywordflow">break</span>;
                                        <span class="keywordflow">case</span> GUI_ID_MODEL_MATERIAL_TRANSPARENT: <span class="comment">// View -&gt; Material -&gt; Transparent</span>
                                                <span class="keywordflow">if</span> (Model)
                                                        Model-&gt;setMaterialType(<a class="code" href="namespaceirr_1_1video.html#c8e9b6c66f7cebabd1a6d30cbc5430f11b5a814c4466aca2943ff056003a50d1" title="A transparent material.">video::EMT_TRANSPARENT_ADD_COLOR</a>);
                                                <span class="keywordflow">break</span>;
                                        <span class="keywordflow">case</span> GUI_ID_MODEL_MATERIAL_REFLECTION: <span class="comment">// View -&gt; Material -&gt; Reflection</span>
                                                <span class="keywordflow">if</span> (Model)
                                                        Model-&gt;setMaterialType(<a class="code" href="namespaceirr_1_1video.html#c8e9b6c66f7cebabd1a6d30cbc5430f142a8b6f5c933864ca104b3d46692c43b" title="Look like a reflection of the environment around it.">video::EMT_SPHERE_MAP</a>);
                                                <span class="keywordflow">break</span>;

                                        <span class="keywordflow">case</span> GUI_ID_CAMERA_MAYA:
                                                setActiveCamera(Camera[0]);
                                                <span class="keywordflow">break</span>;
                                        <span class="keywordflow">case</span> GUI_ID_CAMERA_FIRST_PERSON:
                                                setActiveCamera(Camera[1]);
                                                <span class="keywordflow">break</span>;

                                        }
                                <span class="keywordflow">break</span>;
                                }

                        <span class="keywordflow">case</span> <a class="code" href="namespaceirr_1_1gui.html#eac71ad17341a4b6e9026ae11d5768085b6504cf6b541d5ad95407c384632873" title="A file has been selected in the file dialog.">EGET_FILE_SELECTED</a>:
                                {
                                        <span class="comment">// load the model file, selected in the file open dialog</span>
                                        IGUIFileOpenDialog* dialog =
                                                (IGUIFileOpenDialog*)event.GUIEvent.Caller;
                                        loadModel(<a class="code" href="namespaceirr_1_1core.html#de1071a878633f2f6d8a75c5d11fec19" title="Typedef for character strings.">core::stringc</a>(dialog-&gt;getFileName()).c_str());
                                }
                                <span class="keywordflow">break</span>;

                        <span class="keywordflow">case</span> <a class="code" href="namespaceirr_1_1gui.html#eac71ad17341a4b6e9026ae11d5768082eea536494edcde2bb2608bda9d352b2" title="A scrollbar has changed its position.">EGET_SCROLL_BAR_CHANGED</a>:

                                <span class="comment">// control skin transparency</span>
                                <span class="keywordflow">if</span> (<span class="keywordtype">id</span> == 104)
                                {
                                        <span class="keyword">const</span> <a class="code" href="namespaceirr.html#c66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> pos = ((IGUIScrollBar*)event.GUIEvent.Caller)-&gt;getPos();
                                        <span class="keywordflow">for</span> (<a class="code" href="namespaceirr.html#c66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> i=0; i&lt;<a class="code" href="namespaceirr_1_1gui.html#bd15860fde29833c48daff5f95d5467af340f49e2e0827c0f06fdf65098554af">irr::gui::EGDC_COUNT</a> ; ++i)
                                        {
                                                video::SColor col = env-&gt;getSkin()-&gt;getColor((<a class="code" href="namespaceirr_1_1gui.html#bd15860fde29833c48daff5f95d5467a" title="Enumeration for skin colors.">EGUI_DEFAULT_COLOR</a>)i);
                                                col.setAlpha(pos);
                                                env-&gt;getSkin()-&gt;setColor((<a class="code" href="namespaceirr_1_1gui.html#bd15860fde29833c48daff5f95d5467a" title="Enumeration for skin colors.">EGUI_DEFAULT_COLOR</a>)i, col);
                                        }
                                }
                                <span class="keywordflow">else</span> <span class="keywordflow">if</span> (<span class="keywordtype">id</span> == 105)
                                {
                                        <span class="keyword">const</span> <a class="code" href="namespaceirr.html#c66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> pos = ((IGUIScrollBar*)event.GUIEvent.Caller)-&gt;getPos();
                                        <span class="keywordflow">if</span> (<a class="code" href="namespaceirr_1_1scene.html#cad3d7ef92a9807d391ba29120f3b7bd073d7fe9dfd49f24cb13bfae56d8d3b6" title="Animated Mesh Scene Node.">scene::ESNT_ANIMATED_MESH</a> == Model-&gt;getType())
                                                ((scene::IAnimatedMeshSceneNode*)Model)-&gt;setAnimationSpeed((<a class="code" href="namespaceirr.html#0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a>)pos);
                                }
                                <span class="keywordflow">break</span>;

                        <span class="keywordflow">case</span> <a class="code" href="namespaceirr_1_1gui.html#eac71ad17341a4b6e9026ae11d576808ef7f9081622a71160e161c80eb07d436" title="The selection in a combo box has been changed.">EGET_COMBO_BOX_CHANGED</a>:

                                <span class="comment">// control anti-aliasing/filtering</span>
                                <span class="keywordflow">if</span> (<span class="keywordtype">id</span> == 108)
                                {
                                        <a class="code" href="namespaceirr.html#c66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> pos = ((IGUIComboBox*)event.GUIEvent.Caller)-&gt;getSelected();
                                        <span class="keywordflow">switch</span> (pos)
                                        {
                                                <span class="keywordflow">case</span> 0:
                                                <span class="keywordflow">if</span> (Model)
                                                {
                                                        Model-&gt;setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#8a3bc00ae8137535b9fbc5f40add70d3fbf2b289d416e70466e4ab05e97b4934" title="Is bilinear filtering enabled? Default: true.">video::EMF_BILINEAR_FILTER</a>, <span class="keyword">false</span>);
                                                        Model-&gt;setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#8a3bc00ae8137535b9fbc5f40add70d37a2ed21d879b182fbc767a4c20d72eef" title="Is trilinear filtering enabled? Default: false.">video::EMF_TRILINEAR_FILTER</a>, <span class="keyword">false</span>);
                                                        Model-&gt;setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#8a3bc00ae8137535b9fbc5f40add70d3941c0756b9dc3f987a183a401c6fd4ad" title="Is anisotropic filtering? Default: false.">video::EMF_ANISOTROPIC_FILTER</a>, <span class="keyword">false</span>);
                                                }
                                                <span class="keywordflow">break</span>;
                                                <span class="keywordflow">case</span> 1:
                                                <span class="keywordflow">if</span> (Model)
                                                {
                                                        Model-&gt;setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#8a3bc00ae8137535b9fbc5f40add70d3fbf2b289d416e70466e4ab05e97b4934" title="Is bilinear filtering enabled? Default: true.">video::EMF_BILINEAR_FILTER</a>, <span class="keyword">true</span>);
                                                        Model-&gt;setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#8a3bc00ae8137535b9fbc5f40add70d37a2ed21d879b182fbc767a4c20d72eef" title="Is trilinear filtering enabled? Default: false.">video::EMF_TRILINEAR_FILTER</a>, <span class="keyword">false</span>);
                                                }
                                                <span class="keywordflow">break</span>;
                                                <span class="keywordflow">case</span> 2:
                                                <span class="keywordflow">if</span> (Model)
                                                {
                                                        Model-&gt;setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#8a3bc00ae8137535b9fbc5f40add70d3fbf2b289d416e70466e4ab05e97b4934" title="Is bilinear filtering enabled? Default: true.">video::EMF_BILINEAR_FILTER</a>, <span class="keyword">false</span>);
                                                        Model-&gt;setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#8a3bc00ae8137535b9fbc5f40add70d37a2ed21d879b182fbc767a4c20d72eef" title="Is trilinear filtering enabled? Default: false.">video::EMF_TRILINEAR_FILTER</a>, <span class="keyword">true</span>);
                                                }
                                                <span class="keywordflow">break</span>;
                                                <span class="keywordflow">case</span> 3:
                                                <span class="keywordflow">if</span> (Model)
                                                {
                                                        Model-&gt;setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#8a3bc00ae8137535b9fbc5f40add70d3941c0756b9dc3f987a183a401c6fd4ad" title="Is anisotropic filtering? Default: false.">video::EMF_ANISOTROPIC_FILTER</a>, <span class="keyword">true</span>);
                                                }
                                                <span class="keywordflow">break</span>;
                                                <span class="keywordflow">case</span> 4:
                                                <span class="keywordflow">if</span> (Model)
                                                {
                                                        Model-&gt;setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#8a3bc00ae8137535b9fbc5f40add70d3941c0756b9dc3f987a183a401c6fd4ad" title="Is anisotropic filtering? Default: false.">video::EMF_ANISOTROPIC_FILTER</a>, <span class="keyword">false</span>);
                                                }
                                                <span class="keywordflow">break</span>;
                                        }
                                }
                                <span class="keywordflow">break</span>;

                        <span class="keywordflow">case</span> <a class="code" href="namespaceirr_1_1gui.html#eac71ad17341a4b6e9026ae11d576808308ee345c92444931f83e48354072d98" title="A button was clicked.">EGET_BUTTON_CLICKED</a>:

                                <span class="keywordflow">switch</span>(<span class="keywordtype">id</span>)
                                {
                                <span class="keywordflow">case</span> 1101:
                                        {
                                                <span class="comment">// set scale</span>
                                                gui::IGUIElement* root = env-&gt;getRootGUIElement();
                                                <a class="code" href="namespaceirr_1_1core.html#06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a> scale;
                                                <a class="code" href="namespaceirr_1_1core.html#de1071a878633f2f6d8a75c5d11fec19" title="Typedef for character strings.">core::stringc</a> s;

                                                s = root-&gt;getElementFromId(GUI_ID_X_SCALE, <span class="keyword">true</span>)-&gt;getText();
                                                scale.X = (<a class="code" href="namespaceirr.html#0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a>)atof(s.c_str());
                                                s = root-&gt;getElementFromId(GUI_ID_Y_SCALE, <span class="keyword">true</span>)-&gt;getText();
                                                scale.Y = (<a class="code" href="namespaceirr.html#0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a>)atof(s.c_str());
                                                s = root-&gt;getElementFromId(GUI_ID_Z_SCALE, <span class="keyword">true</span>)-&gt;getText();
                                                scale.Z = (<a class="code" href="namespaceirr.html#0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a>)atof(s.c_str());

                                                <span class="keywordflow">if</span> (Model)
                                                        Model-&gt;setScale(scale);
                                        }
                                        <span class="keywordflow">break</span>;
                                <span class="keywordflow">case</span> 1102:
                                        env-&gt;addFileOpenDialog(L<span class="stringliteral">"Please select a model file to open"</span>);
                                        <span class="keywordflow">break</span>;
                                <span class="keywordflow">case</span> 1103:
                                        showAboutText();
                                        <span class="keywordflow">break</span>;
                                <span class="keywordflow">case</span> 1104:
                                        createToolBox();
                                        <span class="keywordflow">break</span>;
                                <span class="keywordflow">case</span> 1105:
                                        env-&gt;addFileOpenDialog(L<span class="stringliteral">"Please select your game archive/directory"</span>);
                                        <span class="keywordflow">break</span>;
                                }

                                <span class="keywordflow">break</span>;
                        <span class="keywordflow">default</span>:
                                <span class="keywordflow">break</span>;
                        }
                }

                <span class="keywordflow">return</span> <span class="keyword">false</span>;
        }
};
</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#baf4d8719cc26b0d30813abf85e47c76" title="Creates an Irrlicht device. The Irrlicht device is the root object for using the...">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. <div class="fragment"><pre class="fragment"><span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span>* argv[])
{
        <span class="comment">// ask user for driver</span>

        <a class="code" href="namespaceirr_1_1video.html#e35a6de6d436c76107ad157fe42356d0" title="An enum for all types of drivers the Irrlicht Engine supports.">video::E_DRIVER_TYPE</a> driverType = <a class="code" href="namespaceirr_1_1video.html#e35a6de6d436c76107ad157fe42356d08cc3807f6f28404f3424ad7e31b3142f" title="Direct3D8 device, only available on Win32 platforms.">video::EDT_DIRECT3D8</a>;

        printf(<span class="stringliteral">"Please select the driver you want for this example:\n"</span>\
                <span class="stringliteral">" (a) Direct3D 9.0c\n (b) Direct3D 8.1\n (c) OpenGL 1.5\n"</span>\
                <span class="stringliteral">" (d) Software Renderer\n (e) Burning's Software Renderer\n"</span>\
                <span class="stringliteral">" (f) NullDevice\n (otherKey) exit\n\n"</span>);

        <span class="keywordtype">char</span> key;
        std::cin &gt;&gt; key;

        <span class="keywordflow">switch</span>(key)
        {
                <span class="keywordflow">case</span> <span class="charliteral">'a'</span>: driverType = <a class="code" href="namespaceirr_1_1video.html#e35a6de6d436c76107ad157fe42356d04691ca314f9018f508dcf2c57dcaacec" title="Direct3D 9 device, only available on Win32 platforms.">video::EDT_DIRECT3D9</a>;<span class="keywordflow">break</span>;
                <span class="keywordflow">case</span> <span class="charliteral">'b'</span>: driverType = <a class="code" href="namespaceirr_1_1video.html#e35a6de6d436c76107ad157fe42356d08cc3807f6f28404f3424ad7e31b3142f" title="Direct3D8 device, only available on Win32 platforms.">video::EDT_DIRECT3D8</a>;<span class="keywordflow">break</span>;
                <span class="keywordflow">case</span> <span class="charliteral">'c'</span>: driverType = <a class="code" href="namespaceirr_1_1video.html#e35a6de6d436c76107ad157fe42356d02715182a79f1cb8e2826fd68a8150a53" title="OpenGL device, available on most platforms.">video::EDT_OPENGL</a>;   <span class="keywordflow">break</span>;
                <span class="keywordflow">case</span> <span class="charliteral">'d'</span>: driverType = <a class="code" href="namespaceirr_1_1video.html#e35a6de6d436c76107ad157fe42356d01598cd235a1a6bd052e2011b559e8995" title="The Irrlicht Engine Software renderer.">video::EDT_SOFTWARE</a>; <span class="keywordflow">break</span>;
                <span class="keywordflow">case</span> <span class="charliteral">'e'</span>: driverType = <a class="code" href="namespaceirr_1_1video.html#e35a6de6d436c76107ad157fe42356d0e85481da26159b967191ccc6de1e4a05" title="The Burning&amp;#39;s Software Renderer, an alternative software renderer.">video::EDT_BURNINGSVIDEO</a>;<span class="keywordflow">break</span>;
                <span class="keywordflow">case</span> <span class="charliteral">'f'</span>: driverType = <a class="code" href="namespaceirr_1_1video.html#e35a6de6d436c76107ad157fe42356d0cfdbd476cbfd4d05e72f9adffcc42210" title="Null driver, useful for applications to run the engine without visualisation.">video::EDT_NULL</a>;     <span class="keywordflow">break</span>;
                <span class="keywordflow">default</span>: <span class="keywordflow">return</span> 1;
        }

        <span class="comment">// create device and exit if creation failed</span>

        MyEventReceiver receiver;
        Device = <a class="code" href="namespaceirr.html#baf4d8719cc26b0d30813abf85e47c76" title="Creates an Irrlicht device. The Irrlicht device is the root object for using the...">createDevice</a>(driverType, core::dimension2d&lt;u32&gt;(800, 600),
                16, <span class="keyword">false</span>, <span class="keyword">false</span>, <span class="keyword">false</span>, &amp;receiver);

        <span class="keywordflow">if</span> (Device == 0)
                <span class="keywordflow">return</span> 1; <span class="comment">// could not create selected driver.</span>

        Device-&gt;setResizable(<span class="keyword">true</span>);

        Device-&gt;setWindowCaption(L<span class="stringliteral">"Irrlicht Engine - Loading..."</span>);

        video::IVideoDriver* driver = Device-&gt;getVideoDriver();
        IGUIEnvironment* env = Device-&gt;getGUIEnvironment();
        scene::ISceneManager* smgr = Device-&gt;getSceneManager();
        smgr-&gt;getParameters()-&gt;setAttribute(<a class="code" href="namespaceirr_1_1scene.html#157681b3ef101a801ce278e6f21de946" title="Name of the parameter specifying the COLLADA mesh loading mode.">scene::COLLADA_CREATE_SCENE_INSTANCES</a>, <span class="keyword">true</span>);

        driver-&gt;setTextureCreationFlag(<a class="code" href="namespaceirr_1_1video.html#caf6f7414534f7d62bff18c5bf11876f20881e307a778c4a4fbb5327a60a93bb">video::ETCF_ALWAYS_32_BIT</a>, <span class="keyword">true</span>);

        smgr-&gt;addLightSceneNode();
        smgr-&gt;addLightSceneNode(0, <a class="code" href="namespaceirr_1_1core.html#06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(200,200,200),
                video::SColorf(1.0f,1.0f,1.0f),2000);
        <span class="comment">// add our media directory as "search path"</span>
        Device-&gt;getFileSystem()-&gt;addFolderFileArchive(<span class="stringliteral">"../../media/"</span>);
</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>
<div class="fragment"><pre class="fragment">
	&lt;?xml version="1.0"?&gt;
	&lt;config&gt;
		&lt;startUpModel file="some filename" /&gt;
		&lt;messageText caption="Irrlicht Engine Mesh Viewer"&gt;
			Hello!
		&lt;/messageText&gt;
	&lt;/config&gt;
	</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: <div class="fragment"><pre class="fragment">        <span class="comment">// read configuration from xml file</span>

        <a class="code" href="namespaceirr_1_1io.html#9dc6291fb7e4c73155a3e3c8339f9bff" title="An xml reader for wide characters, derived from IReferenceCounted.">io::IXMLReader</a>* xml = Device-&gt;getFileSystem()-&gt;createXMLReader( L<span class="stringliteral">"config.xml"</span>);

        <span class="keywordflow">while</span>(xml &amp;&amp; xml-&gt;read())
        {
                <span class="keywordflow">switch</span>(xml-&gt;getNodeType())
                {
                <span class="keywordflow">case</span> <a class="code" href="namespaceirr_1_1io.html#86a02676c9cbb822e04d60c81b4f33ed0edf973f8ca0f6097f69369539d432a4" title="Text within an xml element: &amp;lt;foo&amp;gt; this is the text. &amp;lt;foo&amp;gt;.">io::EXN_TEXT</a>:
                        <span class="comment">// in this xml file, the only text which occurs is the</span>
                        <span class="comment">// messageText</span>
                        MessageText = xml-&gt;getNodeData();
                        <span class="keywordflow">break</span>;
                <span class="keywordflow">case</span> <a class="code" href="namespaceirr_1_1io.html#86a02676c9cbb822e04d60c81b4f33ed9df4f5baccc23a0ad1f6fa64d8de2fc0" title="An xml element such as &amp;lt;foo&amp;gt;.">io::EXN_ELEMENT</a>:
                        {
                                <span class="keywordflow">if</span> (<a class="code" href="namespaceirr_1_1core.html#ef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">core::stringw</a>(<span class="stringliteral">"startUpModel"</span>) == xml-&gt;getNodeName())
                                        StartUpModelFile = xml-&gt;getAttributeValue(L<span class="stringliteral">"file"</span>);
                                <span class="keywordflow">else</span>
                                <span class="keywordflow">if</span> (<a class="code" href="namespaceirr_1_1core.html#ef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">core::stringw</a>(<span class="stringliteral">"messageText"</span>) == xml-&gt;getNodeName())
                                        Caption = xml-&gt;getAttributeValue(L<span class="stringliteral">"caption"</span>);
                        }
                        <span class="keywordflow">break</span>;
                <span class="keywordflow">default</span>:
                        <span class="keywordflow">break</span>;
                }
        }

        <span class="keywordflow">if</span> (xml)
                xml-&gt;drop(); <span class="comment">// don't forget to delete the xml reader</span>

        <span class="keywordflow">if</span> (argc &gt; 1)
                StartUpModelFile = argv[1];
</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. <div class="fragment"><pre class="fragment">        <span class="comment">// set a nicer font</span>

        IGUISkin* skin = env-&gt;getSkin();
        IGUIFont* font = env-&gt;getFont(<span class="stringliteral">"fonthaettenschweiler.bmp"</span>);
        <span class="keywordflow">if</span> (font)
                skin-&gt;setFont(font);

        <span class="comment">// create menu</span>
        gui::IGUIContextMenu* menu = env-&gt;addMenu();
        menu-&gt;addItem(L<span class="stringliteral">"File"</span>, -1, <span class="keyword">true</span>, <span class="keyword">true</span>);
        menu-&gt;addItem(L<span class="stringliteral">"View"</span>, -1, <span class="keyword">true</span>, <span class="keyword">true</span>);
        menu-&gt;addItem(L<span class="stringliteral">"Camera"</span>, -1, <span class="keyword">true</span>, <span class="keyword">true</span>);
        menu-&gt;addItem(L<span class="stringliteral">"Help"</span>, -1, <span class="keyword">true</span>, <span class="keyword">true</span>);

        gui::IGUIContextMenu* submenu;
        submenu = menu-&gt;getSubMenu(0);
        submenu-&gt;addItem(L<span class="stringliteral">"Open Model File &amp; Texture..."</span>, GUI_ID_OPEN_MODEL);
        submenu-&gt;addItem(L<span class="stringliteral">"Set Model Archive..."</span>, GUI_ID_SET_MODEL_ARCHIVE);
        submenu-&gt;addItem(L<span class="stringliteral">"Load as Octree"</span>, GUI_ID_LOAD_AS_OCTREE);
        submenu-&gt;addSeparator();
        submenu-&gt;addItem(L<span class="stringliteral">"Quit"</span>, GUI_ID_QUIT);

        submenu = menu-&gt;getSubMenu(1);
        submenu-&gt;addItem(L<span class="stringliteral">"sky box visible"</span>, GUI_ID_SKY_BOX_VISIBLE, <span class="keyword">true</span>, <span class="keyword">false</span>, <span class="keyword">true</span>);
        submenu-&gt;addItem(L<span class="stringliteral">"toggle model debug information"</span>, GUI_ID_TOGGLE_DEBUG_INFO, <span class="keyword">true</span>, <span class="keyword">true</span>);
        submenu-&gt;addItem(L<span class="stringliteral">"model material"</span>, -1, <span class="keyword">true</span>, <span class="keyword">true</span> );

        submenu = submenu-&gt;getSubMenu(1);
        submenu-&gt;addItem(L<span class="stringliteral">"Off"</span>, GUI_ID_DEBUG_OFF);
        submenu-&gt;addItem(L<span class="stringliteral">"Bounding Box"</span>, GUI_ID_DEBUG_BOUNDING_BOX);
        submenu-&gt;addItem(L<span class="stringliteral">"Normals"</span>, GUI_ID_DEBUG_NORMALS);
        submenu-&gt;addItem(L<span class="stringliteral">"Skeleton"</span>, GUI_ID_DEBUG_SKELETON);
        submenu-&gt;addItem(L<span class="stringliteral">"Wire overlay"</span>, GUI_ID_DEBUG_WIRE_OVERLAY);
        submenu-&gt;addItem(L<span class="stringliteral">"Half-Transparent"</span>, GUI_ID_DEBUG_HALF_TRANSPARENT);
        submenu-&gt;addItem(L<span class="stringliteral">"Buffers bounding boxes"</span>, GUI_ID_DEBUG_BUFFERS_BOUNDING_BOXES);
        submenu-&gt;addItem(L<span class="stringliteral">"All"</span>, GUI_ID_DEBUG_ALL);

        submenu = menu-&gt;getSubMenu(1)-&gt;getSubMenu(2);
        submenu-&gt;addItem(L<span class="stringliteral">"Solid"</span>, GUI_ID_MODEL_MATERIAL_SOLID);
        submenu-&gt;addItem(L<span class="stringliteral">"Transparent"</span>, GUI_ID_MODEL_MATERIAL_TRANSPARENT);
        submenu-&gt;addItem(L<span class="stringliteral">"Reflection"</span>, GUI_ID_MODEL_MATERIAL_REFLECTION);

        submenu = menu-&gt;getSubMenu(2);
        submenu-&gt;addItem(L<span class="stringliteral">"Maya Style"</span>, GUI_ID_CAMERA_MAYA);
        submenu-&gt;addItem(L<span class="stringliteral">"First Person"</span>, GUI_ID_CAMERA_FIRST_PERSON);

        submenu = menu-&gt;getSubMenu(3);
        submenu-&gt;addItem(L<span class="stringliteral">"About"</span>, GUI_ID_ABOUT);
</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. <div class="fragment"><pre class="fragment">        <span class="comment">// create toolbar</span>

        gui::IGUIToolBar* bar = env-&gt;addToolBar();

        video::ITexture* image = driver-&gt;getTexture(<span class="stringliteral">"open.png"</span>);
        bar-&gt;addButton(1102, 0, L<span class="stringliteral">"Open a model"</span>,image, 0, <span class="keyword">false</span>, <span class="keyword">true</span>);

        image = driver-&gt;getTexture(<span class="stringliteral">"tools.png"</span>);
        bar-&gt;addButton(1104, 0, L<span class="stringliteral">"Open Toolset"</span>,image, 0, <span class="keyword">false</span>, <span class="keyword">true</span>);

        image = driver-&gt;getTexture(<span class="stringliteral">"zip.png"</span>);
        bar-&gt;addButton(1105, 0, L<span class="stringliteral">"Set Model Archive"</span>,image, 0, <span class="keyword">false</span>, <span class="keyword">true</span>);

        image = driver-&gt;getTexture(<span class="stringliteral">"help.png"</span>);
        bar-&gt;addButton(1103, 0, L<span class="stringliteral">"Open Help"</span>, image, 0, <span class="keyword">false</span>, <span class="keyword">true</span>);

        <span class="comment">// create a combobox with some senseless texts</span>

        gui::IGUIComboBox* box = env-&gt;addComboBox(core::rect&lt;s32&gt;(250,4,350,23), bar, 108);
        box-&gt;addItem(L<span class="stringliteral">"No filtering"</span>);
        box-&gt;addItem(L<span class="stringliteral">"Bilinear"</span>);
        box-&gt;addItem(L<span class="stringliteral">"Trilinear"</span>);
        box-&gt;addItem(L<span class="stringliteral">"Anisotropic"</span>);
        box-&gt;addItem(L<span class="stringliteral">"Isotropic"</span>);
</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. <div class="fragment"><pre class="fragment">        <span class="comment">// disable alpha</span>

        <span class="keywordflow">for</span> (<a class="code" href="namespaceirr.html#c66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> i=0; i&lt;<a class="code" href="namespaceirr_1_1gui.html#bd15860fde29833c48daff5f95d5467af340f49e2e0827c0f06fdf65098554af">gui::EGDC_COUNT</a> ; ++i)
        {
                video::SColor col = env-&gt;getSkin()-&gt;getColor((<a class="code" href="namespaceirr_1_1gui.html#bd15860fde29833c48daff5f95d5467a" title="Enumeration for skin colors.">gui::EGUI_DEFAULT_COLOR</a>)i);
                col.setAlpha(255);
                env-&gt;getSkin()-&gt;setColor((<a class="code" href="namespaceirr_1_1gui.html#bd15860fde29833c48daff5f95d5467a" title="Enumeration for skin colors.">gui::EGUI_DEFAULT_COLOR</a>)i, col);
        }

        <span class="comment">// add a tabcontrol</span>

        createToolBox();

        <span class="comment">// create fps text</span>

        IGUIStaticText* fpstext = env-&gt;addStaticText(L<span class="stringliteral">""</span>,
                        core::rect&lt;s32&gt;(400,4,570,23), <span class="keyword">true</span>, <span class="keyword">false</span>, bar);

        IGUIStaticText* postext = env-&gt;addStaticText(L<span class="stringliteral">""</span>,
                        core::rect&lt;s32&gt;(10,50,470,80),<span class="keyword">false</span>, <span class="keyword">false</span>, 0, GUI_ID_POSITION_TEXT);
        postext-&gt;setVisible(<span class="keyword">false</span>);

        <span class="comment">// set window caption</span>

        Caption += <span class="stringliteral">" - ["</span>;
        Caption += driver-&gt;getName();
        Caption += <span class="stringliteral">"]"</span>;
        Device-&gt;setWindowCaption(Caption.c_str());
</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 controled camera, to make the application a little bit more interactive. Finally, everything is drawn in a standard drawing loop. <div class="fragment"><pre class="fragment">        <span class="comment">// show about message box and load default model</span>
        <span class="keywordflow">if</span> (argc==1)
                showAboutText();
        loadModel(StartUpModelFile.c_str());

        <span class="comment">// add skybox</span>

        SkyBox = smgr-&gt;addSkyBoxSceneNode(
                driver-&gt;getTexture(<span class="stringliteral">"irrlicht2_up.jpg"</span>),
                driver-&gt;getTexture(<span class="stringliteral">"irrlicht2_dn.jpg"</span>),
                driver-&gt;getTexture(<span class="stringliteral">"irrlicht2_lf.jpg"</span>),
                driver-&gt;getTexture(<span class="stringliteral">"irrlicht2_rt.jpg"</span>),
                driver-&gt;getTexture(<span class="stringliteral">"irrlicht2_ft.jpg"</span>),
                driver-&gt;getTexture(<span class="stringliteral">"irrlicht2_bk.jpg"</span>));

        <span class="comment">// add a camera scene node</span>
        Camera[0] = smgr-&gt;addCameraSceneNodeMaya();
        Camera[0]-&gt;setFarValue(20000.f);
        <span class="comment">// Maya cameras reposition themselves relative to their target, so target the location</span>
        <span class="comment">// where the mesh scene node is placed.</span>
        Camera[0]-&gt;setTarget(<a class="code" href="namespaceirr_1_1core.html#06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(0,30,0));

        Camera[1] = smgr-&gt;addCameraSceneNodeFPS();
        Camera[1]-&gt;setFarValue(20000.f);
        Camera[1]-&gt;setPosition(<a class="code" href="namespaceirr_1_1core.html#06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(0,0,-70));
        Camera[1]-&gt;setTarget(<a class="code" href="namespaceirr_1_1core.html#06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(0,30,0));

        setActiveCamera(Camera[0]);

        <span class="comment">// load the irrlicht engine logo</span>
        IGUIImage *img =
                env-&gt;addImage(driver-&gt;getTexture(<span class="stringliteral">"irrlichtlogo2.png"</span>),
                        core::position2d&lt;s32&gt;(10, driver-&gt;getScreenSize().Height - 128));

        <span class="comment">// lock the logo's edges to the bottom left corner of the screen</span>
        img-&gt;setAlignment(<a class="code" href="namespaceirr_1_1gui.html#19eb5fb40e67f108cb16aba922ddaa2d4bb8a01452727274e18047a872da1809" title="Aligned to parent&amp;#39;s top or left side (default).">EGUIA_UPPERLEFT</a>, <a class="code" href="namespaceirr_1_1gui.html#19eb5fb40e67f108cb16aba922ddaa2d4bb8a01452727274e18047a872da1809" title="Aligned to parent&amp;#39;s top or left side (default).">EGUIA_UPPERLEFT</a>,
                        <a class="code" href="namespaceirr_1_1gui.html#19eb5fb40e67f108cb16aba922ddaa2d48b4d042b2d6cd63b876cef62c9cfb97" title="Aligned to parent&amp;#39;s bottom or right side.">EGUIA_LOWERRIGHT</a>, <a class="code" href="namespaceirr_1_1gui.html#19eb5fb40e67f108cb16aba922ddaa2d48b4d042b2d6cd63b876cef62c9cfb97" title="Aligned to parent&amp;#39;s bottom or right side.">EGUIA_LOWERRIGHT</a>);

        <span class="comment">// draw everything</span>

        <span class="keywordflow">while</span>(Device-&gt;run() &amp;&amp; driver)
        {
                <span class="keywordflow">if</span> (Device-&gt;isWindowActive())
                {
                        driver-&gt;beginScene(<span class="keyword">true</span>, <span class="keyword">true</span>, video::SColor(150,50,50,50));

                        smgr-&gt;drawAll();
                        env-&gt;drawAll();

                        driver-&gt;endScene();

                        <a class="code" href="namespaceirr_1_1core.html#ef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">core::stringw</a> str(L<span class="stringliteral">"FPS: "</span>);
                        str.append(<a class="code" href="namespaceirr_1_1core.html#ef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">core::stringw</a>(driver-&gt;getFPS()));
                        str += L<span class="stringliteral">" Tris: "</span>;
                        str.append(<a class="code" href="namespaceirr_1_1core.html#ef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">core::stringw</a>(driver-&gt;getPrimitiveCountDrawn()));
                        fpstext-&gt;setText(str.c_str());

                        scene::ICameraSceneNode* cam = Device-&gt;getSceneManager()-&gt;getActiveCamera();
                        str = L<span class="stringliteral">"Pos: "</span>;
                        str.append(<a class="code" href="namespaceirr_1_1core.html#ef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">core::stringw</a>(cam-&gt;getPosition().X));
                        str += L<span class="stringliteral">" "</span>;
                        str.append(<a class="code" href="namespaceirr_1_1core.html#ef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">core::stringw</a>(cam-&gt;getPosition().Y));
                        str += L<span class="stringliteral">" "</span>;
                        str.append(<a class="code" href="namespaceirr_1_1core.html#ef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">core::stringw</a>(cam-&gt;getPosition().Z));
                        str += L<span class="stringliteral">" Tgt: "</span>;
                        str.append(<a class="code" href="namespaceirr_1_1core.html#ef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">core::stringw</a>(cam-&gt;getTarget().X));
                        str += L<span class="stringliteral">" "</span>;
                        str.append(<a class="code" href="namespaceirr_1_1core.html#ef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">core::stringw</a>(cam-&gt;getTarget().Y));
                        str += L<span class="stringliteral">" "</span>;
                        str.append(<a class="code" href="namespaceirr_1_1core.html#ef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">core::stringw</a>(cam-&gt;getTarget().Z));
                        postext-&gt;setText(str.c_str());
                }
                <span class="keywordflow">else</span>
                        Device-&gt;yield();
        }

        Device-&gt;drop();
        <span class="keywordflow">return</span> 0;
}
</pre></div> </div>
<hr size="1">
<address style="align: right;">
<small> </small>
</address>
<table width="100%" border="0" cellspacing="0" cellpadding="2">
  <tr> 
    <td width="0"> <div align="left"><small><a href="http://irrlicht.sourceforge.net" target="_blank"><img src="irrlicht.png" alt="The Irrlicht Engine" align="middle" border=0 width=88 height=31></a></small></div></td>
    <td> <div align="left"><small><em><font size="2">The <a href="http://irrlicht.sourceforge.net" target="_blank">Irrlicht 
        Engine</a> Documentation &copy; 2003-2009 by Nikolaus Gebhardt. Generated 
        on Sun Jan 10 09:24:07 2010 by <a href="http://www.doxygen.org" target="_blank">Doxygen</a> 
        (1.5.6)</font></em></small></div></td>
  </tr>
</table>
<address style="align: right;">
</address>
</body>
</html>