diff options
Diffstat (limited to 'doc/html/example022.html')
| -rw-r--r-- | doc/html/example022.html | 1136 |
1 files changed, 1136 insertions, 0 deletions
diff --git a/doc/html/example022.html b/doc/html/example022.html new file mode 100644 index 0000000..8b0ce09 --- /dev/null +++ b/doc/html/example022.html @@ -0,0 +1,1136 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml"> +<head> +<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> +<title>Irrlicht 3D Engine: Tutorial 22: Material Viewer</title> + +<link href="tabs.css" rel="stylesheet" type="text/css"/> +<link href="doxygen.css" rel="stylesheet" type="text/css" /> +<link href="navtree.css" rel="stylesheet" type="text/css"/> +<script type="text/javascript" src="jquery.js"></script> +<script type="text/javascript" src="resize.js"></script> +<script type="text/javascript" src="navtree.js"></script> +<script type="text/javascript"> + $(document).ready(initResizable); +</script> +<link href="search/search.css" rel="stylesheet" type="text/css"/> +<script type="text/javascript" src="search/search.js"></script> +<script type="text/javascript"> + $(document).ready(function() { searchBox.OnSelectItem(0); }); +</script> + +</head> +<body> +<div id="top"><!-- do not remove this div! --> + + +<div id="titlearea"> +<table cellspacing="0" cellpadding="0"> + <tbody> + <tr style="height: 56px;"> + + <td id="projectlogo"><img alt="Logo" src="irrlichtlogo.png"/></td> + + + <td style="padding-left: 0.5em;"> + <div id="projectname">Irrlicht 3D Engine + + </div> + + </td> + + + + + <td> <div id="MSearchBox" class="MSearchBoxInactive"> + <span class="left"> + <img id="MSearchSelect" src="search/mag_sel.png" + onmouseover="return searchBox.OnSearchSelectShow()" + onmouseout="return searchBox.OnSearchSelectHide()" + alt=""/> + <input type="text" id="MSearchField" value="Search" accesskey="S" + onfocus="searchBox.OnSearchFieldFocus(true)" + onblur="searchBox.OnSearchFieldFocus(false)" + onkeyup="searchBox.OnSearchFieldChange(event)"/> + </span><span class="right"> + <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a> + </span> + </div> +</td> + + + </tr> + </tbody> +</table> +</div> + +<!-- Generated by Doxygen 1.7.5.1 --> +<script type="text/javascript"> +var searchBox = new SearchBox("searchBox", "search",false,'Search'); +</script> +<script type="text/javascript" src="dynsections.js"></script> +</div> +<div id="side-nav" class="ui-resizable side-nav-resizable"> + <div id="nav-tree"> + <div id="nav-tree-contents"> + </div> + </div> + <div id="splitbar" style="-moz-user-select:none;" + class="ui-resizable-handle"> + </div> +</div> +<script type="text/javascript"> + initNavTree('example022.html',''); +</script> +<div id="doc-content"> +<div class="header"> + <div class="headertitle"> +<div class="title">Tutorial 22: Material Viewer </div> </div> +</div> +<div class="contents"> +<div class="textblock"><div class="image"> +<img src="022shot.jpg" alt="022shot.jpg"/> +</div> + <p>This example can be used to play around with material settings and watch the results. Only the default non-shader materials are used in here.</p> +<p>You have two nodes to make it easier to see which difference your settings will make. Additionally you have one lightscenenode and you can set the global ambient values. </p> +<div class="fragment"><pre class="fragment"><span class="preprocessor">#include <<a class="code" href="irrlicht_8h.html" title="Main header file of the irrlicht, the only file needed to include.">irrlicht.h</a>></span> +<span class="preprocessor">#include "<a class="code" href="driver_choice_8h.html">driverChoice.h</a>"</span> + +<span class="keyword">using namespace </span>irr; + +<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>Variables within the empty namespace are globals which are restricted to this file. </p> +<div class="fragment"><pre class="fragment"><span class="keyword">namespace</span> +{ + <span class="keyword">const</span> <span class="keywordtype">wchar_t</span>* <span class="keyword">const</span> DriverTypeNames[] = + { + L<span class="stringliteral">"NULL"</span>, + L<span class="stringliteral">"SOFTWARE"</span>, + L<span class="stringliteral">"BURNINGSVIDEO"</span>, + L<span class="stringliteral">"DIRECT3D8"</span>, + L<span class="stringliteral">"DIRECT3D9"</span>, + L<span class="stringliteral">"OPENGL"</span>, + 0, + }; + + <span class="comment">// For the gui id's</span> + <span class="keyword">enum</span> EGUI_IDS + { + GUI_ID_OPEN_TEXTURE = 1, + GUI_ID_QUIT, + GUI_ID_MAX + }; + + <span class="comment">// Name used in texture selection to clear the textures on the node</span> + <span class="keyword">const</span> <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">core::stringw</a> CLEAR_TEXTURE = L<span class="stringliteral">"CLEAR texture"</span>; + + <span class="comment">// some useful color constants</span> + <span class="keyword">const</span> video::SColor SCOL_BLACK = video::SColor(255, 0, 0, 0); + <span class="keyword">const</span> video::SColor SCOL_BLUE = video::SColor(255, 0, 0, 255); + <span class="keyword">const</span> video::SColor SCOL_CYAN = video::SColor(255, 0, 255, 255); + <span class="keyword">const</span> video::SColor SCOL_GRAY = video::SColor(255, 128,128, 128); + <span class="keyword">const</span> video::SColor SCOL_GREEN = video::SColor(255, 0, 255, 0); + <span class="keyword">const</span> video::SColor SCOL_MAGENTA = video::SColor(255, 255, 0, 255); + <span class="keyword">const</span> video::SColor SCOL_RED = video::SColor(255, 255, 0, 0); + <span class="keyword">const</span> video::SColor SCOL_YELLOW = video::SColor(255, 255, 255, 0); + <span class="keyword">const</span> video::SColor SCOL_WHITE = video::SColor(255, 255, 255, 255); +}; <span class="comment">// namespace</span> +</pre></div><p>Returns a new unique number on each call. </p> +<div class="fragment"><pre class="fragment"><a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> makeUniqueId() +{ + <span class="keyword">static</span> <span class="keywordtype">int</span> unique = GUI_ID_MAX; + ++unique; + <span class="keywordflow">return</span> unique; +} +</pre></div><p>Find out which vertex-type is needed for the given material type. </p> +<div class="fragment"><pre class="fragment"><a class="code" href="namespaceirr_1_1video.html#a0e3b59e025e0d0db0ed2ee0ce904deac" title="Enumeration for all vertex types there are.">video::E_VERTEX_TYPE</a> getVertexTypeForMaterialType(<a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1" title="Abstracted and easy to use fixed function/programmable pipeline material modes.">video::E_MATERIAL_TYPE</a> materialType) +{ + <span class="keyword">using namespace </span>video; + + <span class="keywordflow">switch</span> ( materialType ) + { + <span class="keywordflow">case</span> <a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1a9bc471b9c18c9e2d20496004d2a2e803" title="Standard solid material.">EMT_SOLID</a>: + <span class="keywordflow">return</span> <a class="code" href="namespaceirr_1_1video.html#a0e3b59e025e0d0db0ed2ee0ce904deaca98c8b791280bbf9252c4f4a37e91a416" title="Standard vertex type used by the Irrlicht engine, video::S3DVertex.">EVT_STANDARD</a>; + + <span class="keywordflow">case</span> <a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1a3246cbdb780b42b819eb8a24c2ef40d9" title="Solid material with 2 texture layers.">EMT_SOLID_2_LAYER</a>: + <span class="keywordflow">return</span> <a class="code" href="namespaceirr_1_1video.html#a0e3b59e025e0d0db0ed2ee0ce904deaca98c8b791280bbf9252c4f4a37e91a416" title="Standard vertex type used by the Irrlicht engine, video::S3DVertex.">EVT_STANDARD</a>; + + <span class="keywordflow">case</span> <a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1a5dc90a3b4a8d82f10503ddf834a3143f" title="Material type with standard lightmap technique.">EMT_LIGHTMAP</a>: + <span class="keywordflow">case</span> <a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1a7aa628bfc8b6ac56c30e93549b799855" title="Material type with lightmap technique like EMT_LIGHTMAP.">EMT_LIGHTMAP_ADD</a>: + <span class="keywordflow">case</span> <a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1abd740658d7ca152bab745c63107d7edb" title="Material type with standard lightmap technique.">EMT_LIGHTMAP_M2</a>: + <span class="keywordflow">case</span> <a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1ad61a64f074256bb1cc1b6c130e18ebdc" title="Material type with standard lightmap technique.">EMT_LIGHTMAP_M4</a>: + <span class="keywordflow">case</span> <a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1add532294454c4842964c79a14ac4af34" title="Like EMT_LIGHTMAP, but also supports dynamic lighting.">EMT_LIGHTMAP_LIGHTING</a>: + <span class="keywordflow">case</span> <a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1a9cd386cb5151eabccbdded029529dec0" title="Like EMT_LIGHTMAP_M2, but also supports dynamic lighting.">EMT_LIGHTMAP_LIGHTING_M2</a>: + <span class="keywordflow">case</span> <a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1a6b7a3c28cfc214c63df8674565e28f17" title="Like EMT_LIGHTMAP_4, but also supports dynamic lighting.">EMT_LIGHTMAP_LIGHTING_M4</a>: + <span class="keywordflow">return</span> <a class="code" href="namespaceirr_1_1video.html#a0e3b59e025e0d0db0ed2ee0ce904deaca7b5127a706ee33eb4385d702da007016" title="Vertex with two texture coordinates, video::S3DVertex2TCoords.">EVT_2TCOORDS</a>; + + <span class="keywordflow">case</span> <a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1a065af4f8daeb15f81bfe0417a3f231b1" title="Detail mapped material.">EMT_DETAIL_MAP</a>: + <span class="keywordflow">return</span> <a class="code" href="namespaceirr_1_1video.html#a0e3b59e025e0d0db0ed2ee0ce904deaca7b5127a706ee33eb4385d702da007016" title="Vertex with two texture coordinates, video::S3DVertex2TCoords.">EVT_2TCOORDS</a>; + + <span class="keywordflow">case</span> <a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1a42a8b6f5c933864ca104b3d46692c43b" title="Look like a reflection of the environment around it.">EMT_SPHERE_MAP</a>: + <span class="keywordflow">return</span> <a class="code" href="namespaceirr_1_1video.html#a0e3b59e025e0d0db0ed2ee0ce904deaca98c8b791280bbf9252c4f4a37e91a416" title="Standard vertex type used by the Irrlicht engine, video::S3DVertex.">EVT_STANDARD</a>; + + <span class="keywordflow">case</span> <a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1ad8574343353ed8ade6e78bc04d64b6ae" title="A reflecting material with an optional non reflecting texture layer.">EMT_REFLECTION_2_LAYER</a>: + <span class="keywordflow">return</span> <a class="code" href="namespaceirr_1_1video.html#a0e3b59e025e0d0db0ed2ee0ce904deaca7b5127a706ee33eb4385d702da007016" title="Vertex with two texture coordinates, video::S3DVertex2TCoords.">EVT_2TCOORDS</a>; + + <span class="keywordflow">case</span> <a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1a1b5a814c4466aca2943ff056003a50d1" title="A transparent material.">EMT_TRANSPARENT_ADD_COLOR</a>: + <span class="keywordflow">return</span> <a class="code" href="namespaceirr_1_1video.html#a0e3b59e025e0d0db0ed2ee0ce904deaca98c8b791280bbf9252c4f4a37e91a416" title="Standard vertex type used by the Irrlicht engine, video::S3DVertex.">EVT_STANDARD</a>; + + <span class="keywordflow">case</span> <a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1ac08aa3715ad41281472202107a81f736" title="Makes the material transparent based on the texture alpha channel.">EMT_TRANSPARENT_ALPHA_CHANNEL</a>: + <span class="keywordflow">return</span> <a class="code" href="namespaceirr_1_1video.html#a0e3b59e025e0d0db0ed2ee0ce904deaca98c8b791280bbf9252c4f4a37e91a416" title="Standard vertex type used by the Irrlicht engine, video::S3DVertex.">EVT_STANDARD</a>; + + <span class="keywordflow">case</span> <a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1a167b3eb9c4c09ee1f145d914f4ddb619" title="Makes the material transparent based on the texture alpha channel.">EMT_TRANSPARENT_ALPHA_CHANNEL_REF</a>: + <span class="keywordflow">return</span> <a class="code" href="namespaceirr_1_1video.html#a0e3b59e025e0d0db0ed2ee0ce904deaca98c8b791280bbf9252c4f4a37e91a416" title="Standard vertex type used by the Irrlicht engine, video::S3DVertex.">EVT_STANDARD</a>; + + <span class="keywordflow">case</span> <a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1a26529b1cf18ec4d8073809f6bd15ebbb" title="Makes the material transparent based on the vertex alpha value.">EMT_TRANSPARENT_VERTEX_ALPHA</a>: + <span class="keywordflow">return</span> <a class="code" href="namespaceirr_1_1video.html#a0e3b59e025e0d0db0ed2ee0ce904deaca98c8b791280bbf9252c4f4a37e91a416" title="Standard vertex type used by the Irrlicht engine, video::S3DVertex.">EVT_STANDARD</a>; + + <span class="keywordflow">case</span> <a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1a8b074c837c82178daa178a3a7321a32d" title="A transparent reflecting material with an optional additional non reflecting texture layer...">EMT_TRANSPARENT_REFLECTION_2_LAYER</a>: + <span class="keywordflow">return</span> <a class="code" href="namespaceirr_1_1video.html#a0e3b59e025e0d0db0ed2ee0ce904deaca7b5127a706ee33eb4385d702da007016" title="Vertex with two texture coordinates, video::S3DVertex2TCoords.">EVT_2TCOORDS</a>; + + <span class="keywordflow">case</span> <a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1a89220ece17ea7d54a530de9756734c70" title="A solid normal map renderer.">EMT_NORMAL_MAP_SOLID</a>: + <span class="keywordflow">case</span> <a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1a12323a7408cc28c4e57c4ae52758086c" title="A transparent normal map renderer.">EMT_NORMAL_MAP_TRANSPARENT_ADD_COLOR</a>: + <span class="keywordflow">case</span> <a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1a0d6f6973795d52d137955699537565db" title="A transparent (based on the vertex alpha value) normal map renderer.">EMT_NORMAL_MAP_TRANSPARENT_VERTEX_ALPHA</a>: + <span class="keywordflow">case</span> <a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1a833aaad409476c3c4baf59e2d1096f4a" title="Just like EMT_NORMAL_MAP_SOLID, but uses parallax mapping.">EMT_PARALLAX_MAP_SOLID</a>: + <span class="keywordflow">case</span> <a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1a84787f1dfcbdc1578ecd84f6de4a22a1" title="A material like EMT_PARALLAX_MAP_SOLID, but transparent.">EMT_PARALLAX_MAP_TRANSPARENT_ADD_COLOR</a>: + <span class="keywordflow">case</span> <a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1a4c3e6b604a6d0fc5dffec661f470c11a" title="A material like EMT_PARALLAX_MAP_SOLID, but transparent.">EMT_PARALLAX_MAP_TRANSPARENT_VERTEX_ALPHA</a>: + <span class="keywordflow">return</span> <a class="code" href="namespaceirr_1_1video.html#a0e3b59e025e0d0db0ed2ee0ce904deaca8c50b5b2c88f08709d640fecc83dfb9b" title="Vertex with a tangent and binormal vector, video::S3DVertexTangents.">EVT_TANGENTS</a>; + + <span class="keywordflow">case</span> <a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1a09498eaf291e1f7abdc04db808cc15d9" title="BlendFunc = source * sourceFactor + dest * destFactor ( E_BLEND_FUNC )">EMT_ONETEXTURE_BLEND</a>: + <span class="keywordflow">return</span> <a class="code" href="namespaceirr_1_1video.html#a0e3b59e025e0d0db0ed2ee0ce904deaca98c8b791280bbf9252c4f4a37e91a416" title="Standard vertex type used by the Irrlicht engine, video::S3DVertex.">EVT_STANDARD</a>; + + <span class="keywordflow">case</span> <a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1a85962cdf5aab2ddd245cada9b1859e30" title="This value is not used. It only forces this enumeration to compile to 32 bit.">EMT_FORCE_32BIT</a>: + <span class="keywordflow">return</span> <a class="code" href="namespaceirr_1_1video.html#a0e3b59e025e0d0db0ed2ee0ce904deaca98c8b791280bbf9252c4f4a37e91a416" title="Standard vertex type used by the Irrlicht engine, video::S3DVertex.">EVT_STANDARD</a>; + } + <span class="keywordflow">return</span> <a class="code" href="namespaceirr_1_1video.html#a0e3b59e025e0d0db0ed2ee0ce904deaca98c8b791280bbf9252c4f4a37e91a416" title="Standard vertex type used by the Irrlicht engine, video::S3DVertex.">EVT_STANDARD</a>; +} +</pre></div><p>Custom GUI-control to edit colorvalues. </p> +<div class="fragment"><pre class="fragment"><span class="keyword">class </span>CColorControl : <span class="keyword">public</span> gui::IGUIElement +{ +<span class="keyword">public</span>: + <span class="comment">// Constructor</span> + CColorControl(gui::IGUIEnvironment* guiEnv, <span class="keyword">const</span> core::position2d<s32> & pos, <span class="keyword">const</span> <span class="keywordtype">wchar_t</span> *text, IGUIElement* parent, <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> <span class="keywordtype">id</span>=-1 ) + : gui::IGUIElement(gui::<a class="code" href="namespaceirr_1_1gui.html#ae4d66df0ecf4117cdbcf9f22404bd254afab12396466cf3add0f9e7408a053932" title="Unknown type.">EGUIET_ELEMENT</a>, guiEnv, parent,id, core::rect< <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> >(pos, pos+core::dimension2d<<a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a>>(80, 75))) + , DirtyFlag(true) + , ColorStatic(0) + , EditAlpha(0) + , EditRed(0) + , EditGreen(0) + , EditBlue(0) + { + <span class="keyword">using namespace </span>gui; + ButtonSetId = makeUniqueId(); + + <span class="keyword">const</span> core::rect< s32 > rectControls(0,0,AbsoluteRect.getWidth(),AbsoluteRect.getHeight() ); + IGUIStaticText * groupElement = guiEnv->addStaticText (L<span class="stringliteral">""</span>, rectControls, <span class="keyword">true</span>, <span class="keyword">false</span>, <span class="keyword">this</span>, -1, <span class="keyword">false</span>); + groupElement->setNotClipped(<span class="keyword">true</span>); + + guiEnv->addStaticText (text, core::rect<s32>(0,0,80,15), <span class="keyword">false</span>, <span class="keyword">false</span>, groupElement, -1, <span class="keyword">false</span>); + + EditAlpha = addEditForNumbers(guiEnv, core::position2d<s32>(0,15), L<span class="stringliteral">"a"</span>, -1, groupElement ); + EditRed = addEditForNumbers(guiEnv, core::position2d<s32>(0,30), L<span class="stringliteral">"r"</span>, -1, groupElement ); + EditGreen = addEditForNumbers(guiEnv, core::position2d<s32>(0,45), L<span class="stringliteral">"g"</span>, -1, groupElement ); + EditBlue = addEditForNumbers(guiEnv, core::position2d<s32>(0,60), L<span class="stringliteral">"b"</span>, -1, groupElement ); + + ColorStatic = guiEnv->addStaticText (L<span class="stringliteral">""</span>, core::rect<s32>(60,15,80,75), <span class="keyword">true</span>, <span class="keyword">false</span>, groupElement, -1, <span class="keyword">true</span>); + + guiEnv->addButton (core::rect<s32>(60,35,80,50), groupElement, ButtonSetId, L<span class="stringliteral">"set"</span>); + SetEditsFromColor(Color); + } + + <span class="comment">// event receiver</span> + <span class="keyword">virtual</span> <span class="keywordtype">bool</span> OnEvent(<span class="keyword">const</span> SEvent &event) + { + <span class="keywordflow">if</span> ( event.EventType != <a class="code" href="namespaceirr.html#ac9eed96e06e85ce3c86fcbbbe9e48a0cae85bb44dd09a29c879d64a05047fc1d2" title="An event of the graphical user interface.">EET_GUI_EVENT</a> ) + <span class="keywordflow">return</span> <span class="keyword">false</span>; + + <span class="keywordflow">if</span> ( event.GUIEvent.Caller->getID() == ButtonSetId && <span class="keyword">event</span>.GUIEvent.EventType == <a class="code" href="namespaceirr_1_1gui.html#aeac71ad17341a4b6e9026ae11d576808a308ee345c92444931f83e48354072d98" title="A button was clicked.">gui::EGET_BUTTON_CLICKED</a> ) + { + Color = GetColorFromEdits(); + SetEditsFromColor(Color); + } + + <span class="keywordflow">return</span> <span class="keyword">false</span>; + } + + <span class="comment">// set the color values</span> + <span class="keywordtype">void</span> setColor(<span class="keyword">const</span> video::SColor& col) + { + DirtyFlag = <span class="keyword">true</span>; + Color = col; + SetEditsFromColor(Color); + } + + <span class="comment">// get the color values</span> + <span class="keyword">const</span> video::SColor& getColor()<span class="keyword"> const</span> +<span class="keyword"> </span>{ + <span class="keywordflow">return</span> Color; + } + + <span class="comment">// To reset the dirty flag</span> + <span class="keywordtype">void</span> resetDirty() + { + DirtyFlag = <span class="keyword">false</span>; + } + + <span class="comment">// when the color was changed the dirty flag is set</span> + <span class="keywordtype">bool</span> isDirty()<span class="keyword"> const</span> +<span class="keyword"> </span>{ + <span class="keywordflow">return</span> DirtyFlag; + }; + +<span class="keyword">protected</span>: + + <span class="comment">// Add a staticbox for a description + an editbox so users can enter numbers</span> + gui::IGUIEditBox* addEditForNumbers(gui::IGUIEnvironment* guiEnv, <span class="keyword">const</span> core::position2d<s32> & pos, <span class="keyword">const</span> <span class="keywordtype">wchar_t</span> *text, <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> <span class="keywordtype">id</span>, gui::IGUIElement * parent) + { + <span class="keyword">using namespace </span>gui; + + core::rect< s32 > rect(pos, pos+core::dimension2d<s32>(10, 15)); + guiEnv->addStaticText (text, rect, <span class="keyword">false</span>, <span class="keyword">false</span>, parent, -1, <span class="keyword">false</span>); + rect += core::position2d<s32>( 20, 0 ); + rect.LowerRightCorner.X += 20; + gui::IGUIEditBox* edit = guiEnv->addEditBox(L<span class="stringliteral">"0"</span>, rect, <span class="keyword">true</span>, parent, <span class="keywordtype">id</span>); + <span class="keywordflow">return</span> edit; + } + + <span class="comment">// Get the color value from the editfields</span> + video::SColor GetColorFromEdits() + { + video::SColor col; + + <span class="keywordflow">if</span> (EditAlpha) + { + <a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> alpha = <a class="code" href="namespaceirr_1_1core.html#ae7f759b603f4caaa8471cb9bc2e23648" title="Convert a simple string of base 10 digits into an unsigned 32 bit integer.">core::strtoul10</a>(<a class="code" href="namespaceirr_1_1core.html#ade1071a878633f2f6d8a75c5d11fec19" title="Typedef for character strings.">core::stringc</a>(EditAlpha->getText()).c_str()); + <span class="keywordflow">if</span> (alpha > 255) + alpha = 255; + col.setAlpha(alpha); + } + + <span class="keywordflow">if</span> (EditRed) + { + <a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> red = <a class="code" href="namespaceirr_1_1core.html#ae7f759b603f4caaa8471cb9bc2e23648" title="Convert a simple string of base 10 digits into an unsigned 32 bit integer.">core::strtoul10</a>(<a class="code" href="namespaceirr_1_1core.html#ade1071a878633f2f6d8a75c5d11fec19" title="Typedef for character strings.">core::stringc</a>(EditRed->getText()).c_str()); + <span class="keywordflow">if</span> (red > 255) + red = 255; + col.setRed(red); + } + + <span class="keywordflow">if</span> (EditGreen) + { + <a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> green = <a class="code" href="namespaceirr_1_1core.html#ae7f759b603f4caaa8471cb9bc2e23648" title="Convert a simple string of base 10 digits into an unsigned 32 bit integer.">core::strtoul10</a>(<a class="code" href="namespaceirr_1_1core.html#ade1071a878633f2f6d8a75c5d11fec19" title="Typedef for character strings.">core::stringc</a>(EditGreen->getText()).c_str()); + <span class="keywordflow">if</span> (green > 255) + green = 255; + col.setGreen(green); + } + + <span class="keywordflow">if</span> (EditBlue) + { + <a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> blue = <a class="code" href="namespaceirr_1_1core.html#ae7f759b603f4caaa8471cb9bc2e23648" title="Convert a simple string of base 10 digits into an unsigned 32 bit integer.">core::strtoul10</a>(<a class="code" href="namespaceirr_1_1core.html#ade1071a878633f2f6d8a75c5d11fec19" title="Typedef for character strings.">core::stringc</a>(EditBlue->getText()).c_str()); + <span class="keywordflow">if</span> (blue > 255) + blue = 255; + col.setBlue(blue); + } + + <span class="keywordflow">return</span> col; + } + + <span class="comment">// Fill the editfields with the value for the given color</span> + <span class="keywordtype">void</span> SetEditsFromColor(video::SColor col) + { + DirtyFlag = <span class="keyword">true</span>; + <span class="keywordflow">if</span> ( EditAlpha ) + EditAlpha->setText( <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">core::stringw</a>(col.getAlpha()).c_str() ); + <span class="keywordflow">if</span> ( EditRed ) + EditRed->setText( <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">core::stringw</a>(col.getRed()).c_str() ); + <span class="keywordflow">if</span> ( EditGreen ) + EditGreen->setText( <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">core::stringw</a>(col.getGreen()).c_str() ); + <span class="keywordflow">if</span> ( EditBlue ) + EditBlue->setText( <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">core::stringw</a>(col.getBlue()).c_str() ); + <span class="keywordflow">if</span> ( ColorStatic ) + ColorStatic->setBackgroundColor(col); + } + +<span class="keyword">private</span>: + + <span class="keywordtype">bool</span> DirtyFlag; + video::SColor Color; + <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> ButtonSetId; + gui::IGUIStaticText * ColorStatic; + gui::IGUIEditBox * EditAlpha; + gui::IGUIEditBox * EditRed; + gui::IGUIEditBox * EditGreen; + gui::IGUIEditBox * EditBlue; +}; +</pre></div><p>Custom GUI-control for to edit all colors typically used in materials and lights </p> +<div class="fragment"><pre class="fragment"><span class="keyword">class </span>CAllColorsControl : <span class="keyword">public</span> gui::IGUIElement +{ +<span class="keyword">public</span>: + <span class="comment">// Constructor</span> + CAllColorsControl(gui::IGUIEnvironment* guiEnv, <span class="keyword">const</span> core::position2d<s32> & pos, <span class="keyword">const</span> <span class="keywordtype">wchar_t</span> * description, <span class="keywordtype">bool</span> hasEmissive, IGUIElement* parent, <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> <span class="keywordtype">id</span>=-1) + : gui::IGUIElement(gui::<a class="code" href="namespaceirr_1_1gui.html#ae4d66df0ecf4117cdbcf9f22404bd254afab12396466cf3add0f9e7408a053932" title="Unknown type.">EGUIET_ELEMENT</a>, guiEnv, parent,id, core::rect<<a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a>>(pos,pos+core::dimension2d<<a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a>>(60,250))) + , ControlAmbientColor(0), ControlDiffuseColor(0), ControlSpecularColor(0), ControlEmissiveColor(0) + { + core::rect<s32> rect(0, 0, 60, 15); + guiEnv->addStaticText (description, rect, <span class="keyword">false</span>, <span class="keyword">false</span>, <span class="keyword">this</span>, -1, <span class="keyword">false</span>); + createColorControls(guiEnv, core::position2d<s32>(0, 15), hasEmissive); + } + + <span class="comment">// Destructor</span> + <span class="keyword">virtual</span> ~CAllColorsControl() + { + ControlAmbientColor->drop(); + ControlDiffuseColor->drop(); + <span class="keywordflow">if</span> ( ControlEmissiveColor ) + ControlEmissiveColor->drop(); + ControlSpecularColor->drop(); + } + + <span class="comment">// Set the color values to those within the material</span> + <span class="keywordtype">void</span> setColorsToMaterialColors(<span class="keyword">const</span> video::SMaterial & material) + { + ControlAmbientColor->setColor(material.AmbientColor); + ControlDiffuseColor->setColor(material.DiffuseColor); + ControlEmissiveColor->setColor(material.EmissiveColor); + ControlSpecularColor->setColor(material.SpecularColor); + } + + <span class="comment">// Update all changed colors in the material</span> + <span class="keywordtype">void</span> updateMaterialColors(video::SMaterial & material) + { + <span class="keywordflow">if</span> ( ControlAmbientColor->isDirty() ) + material.AmbientColor = ControlAmbientColor->getColor(); + <span class="keywordflow">if</span> ( ControlDiffuseColor->isDirty() ) + material.DiffuseColor = ControlDiffuseColor->getColor(); + <span class="keywordflow">if</span> ( ControlEmissiveColor->isDirty() ) + material.EmissiveColor = ControlEmissiveColor->getColor(); + <span class="keywordflow">if</span> ( ControlSpecularColor->isDirty() ) + material.SpecularColor = ControlSpecularColor->getColor(); + } + + <span class="comment">// Set the color values to those from the light data</span> + <span class="keywordtype">void</span> setColorsToLightDataColors(<span class="keyword">const</span> video::SLight & lightData) + { + ControlAmbientColor->setColor(lightData.AmbientColor.toSColor()); + ControlAmbientColor->setColor(lightData.DiffuseColor.toSColor()); + ControlAmbientColor->setColor(lightData.SpecularColor.toSColor()); + } + + <span class="comment">// Update all changed colors in the light data</span> + <span class="keywordtype">void</span> updateLightColors(video::SLight & lightData) + { + <span class="keywordflow">if</span> ( ControlAmbientColor->isDirty() ) + lightData.AmbientColor = video::SColorf( ControlAmbientColor->getColor() ); + <span class="keywordflow">if</span> ( ControlDiffuseColor->isDirty() ) + lightData.DiffuseColor = video::SColorf( ControlDiffuseColor->getColor() ); + <span class="keywordflow">if</span> ( ControlSpecularColor->isDirty() ) + lightData.SpecularColor = video::SColorf(ControlSpecularColor->getColor() ); + } + + <span class="comment">// To reset the dirty flags</span> + <span class="keywordtype">void</span> resetDirty() + { + ControlAmbientColor->resetDirty(); + ControlDiffuseColor->resetDirty(); + ControlSpecularColor->resetDirty(); + <span class="keywordflow">if</span> ( ControlEmissiveColor ) + ControlEmissiveColor->resetDirty(); + } + +<span class="keyword">protected</span>: + <span class="keywordtype">void</span> createColorControls(gui::IGUIEnvironment* guiEnv, <span class="keyword">const</span> core::position2d<s32> & pos, <span class="keywordtype">bool</span> hasEmissive) + { + ControlAmbientColor = <span class="keyword">new</span> CColorControl( guiEnv, pos, L<span class="stringliteral">"ambient"</span>, <span class="keyword">this</span>); + ControlDiffuseColor = <span class="keyword">new</span> CColorControl( guiEnv, pos + core::position2d<s32>(0, 75), L<span class="stringliteral">"diffuse"</span>, <span class="keyword">this</span> ); + ControlSpecularColor = <span class="keyword">new</span> CColorControl( guiEnv, pos + core::position2d<s32>(0, 150), L<span class="stringliteral">"specular"</span>, <span class="keyword">this</span> ); + <span class="keywordflow">if</span> ( hasEmissive ) + { + ControlEmissiveColor = <span class="keyword">new</span> CColorControl( guiEnv, pos + core::position2d<s32>(0, 225), L<span class="stringliteral">"emissive"</span>, <span class="keyword">this</span> ); + } + } + +<span class="keyword">private</span>: + CColorControl* ControlAmbientColor; + CColorControl* ControlDiffuseColor; + CColorControl* ControlSpecularColor; + CColorControl* ControlEmissiveColor; +}; +</pre></div><p>GUI-Control to offer a selection of available textures. </p> +<div class="fragment"><pre class="fragment"><span class="keyword">class </span>CTextureControl : <span class="keyword">public</span> gui::IGUIElement +{ +<span class="keyword">public</span>: + CTextureControl(gui::IGUIEnvironment* guiEnv, video::IVideoDriver * driver, <span class="keyword">const</span> core::position2d<s32> & pos, IGUIElement* parent, <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> <span class="keywordtype">id</span>=-1) + : gui::IGUIElement(gui::<a class="code" href="namespaceirr_1_1gui.html#ae4d66df0ecf4117cdbcf9f22404bd254afab12396466cf3add0f9e7408a053932" title="Unknown type.">EGUIET_ELEMENT</a>, guiEnv, parent,id, core::rect<<a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a>>(pos,pos+core::dimension2d<<a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a>>(100,15))) + , DirtyFlag(true), ComboTexture(0) + { + core::rect<s32> rectCombo(0, 0, AbsoluteRect.getWidth(),AbsoluteRect.getHeight()); + ComboTexture = guiEnv->addComboBox (rectCombo, <span class="keyword">this</span>); + updateTextures(driver); + } + + <span class="keyword">virtual</span> <span class="keywordtype">bool</span> OnEvent(<span class="keyword">const</span> SEvent &event) + { + <span class="keywordflow">if</span> ( event.EventType != <a class="code" href="namespaceirr.html#ac9eed96e06e85ce3c86fcbbbe9e48a0cae85bb44dd09a29c879d64a05047fc1d2" title="An event of the graphical user interface.">EET_GUI_EVENT</a> ) + <span class="keywordflow">return</span> <span class="keyword">false</span>; + + <span class="keywordflow">if</span> ( event.GUIEvent.Caller == ComboTexture && event.GUIEvent.EventType == <a class="code" href="namespaceirr_1_1gui.html#aeac71ad17341a4b6e9026ae11d576808aef7f9081622a71160e161c80eb07d436" title="The selection in a combo box has been changed.">gui::EGET_COMBO_BOX_CHANGED</a> ) + { + DirtyFlag = <span class="keyword">true</span>; + } + + <span class="keywordflow">return</span> <span class="keyword">false</span>; + } + + <span class="comment">// Workaround for a problem with comboboxes.</span> + <span class="comment">// We have to get in front when the combobox wants to get in front or combobox-list might be drawn below other elements.</span> + <span class="keyword">virtual</span> <span class="keywordtype">bool</span> bringToFront(IGUIElement* element) + { + <span class="keywordtype">bool</span> result = gui::IGUIElement::bringToFront(element); + <span class="keywordflow">if</span> ( Parent && element == ComboTexture ) + result &= Parent->bringToFront(<span class="keyword">this</span>); + <span class="keywordflow">return</span> result; + } + + <span class="comment">// return selected texturename (if any, otherwise 0)</span> + <span class="keyword">const</span> <span class="keywordtype">wchar_t</span> * getSelectedTextureName()<span class="keyword"> const</span> +<span class="keyword"> </span>{ + <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> selected = ComboTexture->getSelected(); + <span class="keywordflow">if</span> ( selected < 0 ) + <span class="keywordflow">return</span> 0; + <span class="keywordflow">return</span> ComboTexture->getItem(selected); + } + + <span class="comment">// reset the dirty flag</span> + <span class="keywordtype">void</span> resetDirty() + { + DirtyFlag = <span class="keyword">false</span>; + } + + <span class="comment">// when the texture was changed the dirty flag is set</span> + <span class="keywordtype">bool</span> isDirty()<span class="keyword"> const</span> +<span class="keyword"> </span>{ + <span class="keywordflow">return</span> DirtyFlag; + }; + + <span class="comment">// Put the names of all currently loaded textures in a combobox</span> + <span class="keywordtype">void</span> updateTextures(video::IVideoDriver * driver) + { + <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> oldSelected = ComboTexture->getSelected(); + <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> selectNew = -1; + <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">core::stringw</a> oldTextureName; + <span class="keywordflow">if</span> ( oldSelected >= 0 ) + { + oldTextureName = ComboTexture->getItem(oldSelected); + } + ComboTexture->clear(); + <span class="keywordflow">for</span> ( <a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> i=0; i < driver->getTextureCount(); ++i ) + { + video::ITexture * texture = driver->getTextureByIndex(i); + <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">core::stringw</a> name( texture->getName() ); + ComboTexture->addItem( name.c_str() ); + <span class="keywordflow">if</span> ( !oldTextureName.empty() && selectNew < 0 && name == oldTextureName ) + selectNew = i; + } + + <span class="comment">// add another name which can be used to clear the texture</span> + ComboTexture->addItem( CLEAR_TEXTURE.c_str() ); + <span class="keywordflow">if</span> ( CLEAR_TEXTURE == oldTextureName ) + selectNew = ComboTexture->getItemCount()-1; + + <span class="keywordflow">if</span> ( selectNew >= 0 ) + ComboTexture->setSelected(selectNew); + + DirtyFlag = <span class="keyword">true</span>; + } + +<span class="keyword">private</span>: + <span class="keywordtype">bool</span> DirtyFlag; + gui::IGUIComboBox * ComboTexture; +}; +</pre></div><p>Control which allows setting some of the material values for a meshscenenode </p> +<div class="fragment"><pre class="fragment"><span class="keyword">struct </span>SMeshNodeControl +{ + <span class="comment">// constructor</span> + SMeshNodeControl() + : Initialized(false), Driver(0), MeshManipulator(0), SceneNode(0), SceneNode2T(0), SceneNodeTangents(0) + , AllColorsControl(0), ButtonLighting(0), InfoLighting(0), ComboMaterial(0), TextureControl1(0), TextureControl2(0), ControlVertexColors(0) + { + } + + <span class="comment">// Destructor</span> + <span class="keyword">virtual</span> ~SMeshNodeControl() + { + <span class="keywordflow">if</span> ( TextureControl1 ) + TextureControl1->drop(); + <span class="keywordflow">if</span> ( TextureControl2 ) + TextureControl2->drop(); + <span class="keywordflow">if</span> ( ControlVertexColors ) + ControlVertexColors->drop(); + <span class="keywordflow">if</span> ( AllColorsControl ) + AllColorsControl->drop(); + } + + <span class="keywordtype">void</span> init(scene::IMeshSceneNode* node, IrrlichtDevice * device, <span class="keyword">const</span> core::position2d<s32> & pos, <span class="keyword">const</span> <span class="keywordtype">wchar_t</span> * description) + { + <span class="keywordflow">if</span> ( Initialized || !node || !device) <span class="comment">// initializing twice or with invalid data not allowed</span> + <span class="keywordflow">return</span>; + + Driver = device->getVideoDriver (); + gui::IGUIEnvironment* guiEnv = device->getGUIEnvironment(); + scene::ISceneManager* smgr = device->getSceneManager(); + MeshManipulator = smgr->getMeshManipulator(); + + SceneNode = node; + scene::IMeshManipulator * meshManip = smgr->getMeshManipulator(); + + scene::IMesh * mesh2T = meshManip->createMeshWith2TCoords(node->getMesh()); + SceneNode2T = smgr->addMeshSceneNode(mesh2T, 0, -1, SceneNode->getPosition(), SceneNode->getRotation(), SceneNode->getScale() ); + mesh2T->drop(); + + scene::IMesh * meshTangents = meshManip->createMeshWithTangents(node->getMesh(), <span class="keyword">false</span>, <span class="keyword">false</span>, <span class="keyword">false</span>); + SceneNodeTangents = smgr->addMeshSceneNode(meshTangents, 0, -1 + , SceneNode->getPosition(), SceneNode->getRotation(), SceneNode->getScale() ); + meshTangents->drop(); + + video::SMaterial & material = SceneNode->getMaterial(0); + material.Lighting = <span class="keyword">true</span>; + AllColorsControl = <span class="keyword">new</span> CAllColorsControl(guiEnv, pos, description, <span class="keyword">true</span>, guiEnv->getRootGUIElement()); + AllColorsControl->setColorsToMaterialColors(material); + + core::rect<s32> rectBtn(pos + core::position2d<s32>(0, 320), core::dimension2d<s32>(60, 15)); + ButtonLighting = guiEnv->addButton (rectBtn, 0, -1, L<span class="stringliteral">"Lighting"</span>); + ButtonLighting->setIsPushButton(<span class="keyword">true</span>); + ButtonLighting->setPressed(material.Lighting); + core::rect<s32> rectInfo( rectBtn.LowerRightCorner.X, rectBtn.UpperLeftCorner.Y, rectBtn.LowerRightCorner.X+40, rectBtn.UpperLeftCorner.Y+15 ); + InfoLighting = guiEnv->addStaticText(L<span class="stringliteral">""</span>, rectInfo, <span class="keyword">true</span>, <span class="keyword">false</span> ); + InfoLighting->setTextAlignment(<a class="code" href="namespaceirr_1_1gui.html#a19eb5fb40e67f108cb16aba922ddaa2da9da0fb4bcb85d509bdfe018b720e4606" title="Aligned to the center of parent.">gui::EGUIA_CENTER</a>, <a class="code" href="namespaceirr_1_1gui.html#a19eb5fb40e67f108cb16aba922ddaa2da9da0fb4bcb85d509bdfe018b720e4606" title="Aligned to the center of parent.">gui::EGUIA_CENTER</a> ); + + core::rect<s32> rectCombo(pos.X, rectBtn.LowerRightCorner.Y, pos.X+100, rectBtn.LowerRightCorner.Y+15); + ComboMaterial = guiEnv->addComboBox (rectCombo); + <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0; i <= (int)<a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1a09498eaf291e1f7abdc04db808cc15d9" title="BlendFunc = source * sourceFactor + dest * destFactor ( E_BLEND_FUNC )">video::EMT_ONETEXTURE_BLEND</a>; ++i ) + { + ComboMaterial->addItem( <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">core::stringw</a>(<a class="code" href="namespaceirr_1_1video.html#a833460ba01098710b6df3ec5c281c873" title="Array holding the built in material type names.">video::sBuiltInMaterialTypeNames</a>[i]).c_str() ); + } + ComboMaterial->setSelected( (<a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a>)material.MaterialType ); + + core::position2d<s32> posTex(rectCombo.UpperLeftCorner.X,rectCombo.LowerRightCorner.Y); + TextureControl1 = <span class="keyword">new</span> CTextureControl(guiEnv, Driver, posTex, guiEnv->getRootGUIElement()); + posTex.Y += 15; + TextureControl2 = <span class="keyword">new</span> CTextureControl(guiEnv, Driver, posTex, guiEnv->getRootGUIElement()); + + core::position2d<s32> posVertexColors( posTex.X, posTex.Y + 15); + ControlVertexColors = <span class="keyword">new</span> CColorControl( guiEnv, posVertexColors, L<span class="stringliteral">"Vertex colors"</span>, guiEnv->getRootGUIElement()); + + video::S3DVertex * vertices = (video::S3DVertex *)node->getMesh()->getMeshBuffer(0)->getVertices(); + <span class="keywordflow">if</span> ( vertices ) + { + ControlVertexColors->setColor(vertices[0].Color); + } + + Initialized = <span class="keyword">true</span>; + } + + <span class="keywordtype">void</span> update() + { + <span class="keywordflow">if</span> ( !Initialized ) + <span class="keywordflow">return</span>; + + video::SMaterial & material = SceneNode->getMaterial(0); + video::SMaterial & material2T = SceneNode2T->getMaterial(0); + video::SMaterial & materialTangents = SceneNodeTangents->getMaterial(0); + + <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> selectedMaterial = ComboMaterial->getSelected(); + <span class="keywordflow">if</span> ( selectedMaterial >= (<a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a>)<a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1a9bc471b9c18c9e2d20496004d2a2e803" title="Standard solid material.">video::EMT_SOLID</a> && selectedMaterial <= (<a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a>)<a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1a09498eaf291e1f7abdc04db808cc15d9" title="BlendFunc = source * sourceFactor + dest * destFactor ( E_BLEND_FUNC )">video::EMT_ONETEXTURE_BLEND</a>) + { + <a class="code" href="namespaceirr_1_1video.html#a0e3b59e025e0d0db0ed2ee0ce904deac" title="Enumeration for all vertex types there are.">video::E_VERTEX_TYPE</a> vertexType = getVertexTypeForMaterialType((<a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1" title="Abstracted and easy to use fixed function/programmable pipeline material modes.">video::E_MATERIAL_TYPE</a>)selectedMaterial); + <span class="keywordflow">switch</span> ( vertexType ) + { + <span class="keywordflow">case</span> <a class="code" href="namespaceirr_1_1video.html#a0e3b59e025e0d0db0ed2ee0ce904deaca98c8b791280bbf9252c4f4a37e91a416" title="Standard vertex type used by the Irrlicht engine, video::S3DVertex.">video::EVT_STANDARD</a>: + material.MaterialType = (<a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1" title="Abstracted and easy to use fixed function/programmable pipeline material modes.">video::E_MATERIAL_TYPE</a>)selectedMaterial; + SceneNode->setVisible(<span class="keyword">true</span>); + SceneNode2T->setVisible(<span class="keyword">false</span>); + SceneNodeTangents->setVisible(<span class="keyword">false</span>); + <span class="keywordflow">break</span>; + <span class="keywordflow">case</span> <a class="code" href="namespaceirr_1_1video.html#a0e3b59e025e0d0db0ed2ee0ce904deaca7b5127a706ee33eb4385d702da007016" title="Vertex with two texture coordinates, video::S3DVertex2TCoords.">video::EVT_2TCOORDS</a>: + material2T.MaterialType = (<a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1" title="Abstracted and easy to use fixed function/programmable pipeline material modes.">video::E_MATERIAL_TYPE</a>)selectedMaterial; + SceneNode->setVisible(<span class="keyword">false</span>); + SceneNode2T->setVisible(<span class="keyword">true</span>); + SceneNodeTangents->setVisible(<span class="keyword">false</span>); + <span class="keywordflow">break</span>; + <span class="keywordflow">case</span> <a class="code" href="namespaceirr_1_1video.html#a0e3b59e025e0d0db0ed2ee0ce904deaca8c50b5b2c88f08709d640fecc83dfb9b" title="Vertex with a tangent and binormal vector, video::S3DVertexTangents.">video::EVT_TANGENTS</a>: + materialTangents.MaterialType = (<a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1" title="Abstracted and easy to use fixed function/programmable pipeline material modes.">video::E_MATERIAL_TYPE</a>)selectedMaterial; + SceneNode->setVisible(<span class="keyword">false</span>); + SceneNode2T->setVisible(<span class="keyword">false</span>); + SceneNodeTangents->setVisible(<span class="keyword">true</span>); + <span class="keywordflow">break</span>; + } + } + + updateMaterial(material); + updateMaterial(material2T); + updateMaterial(materialTangents); + + <span class="keywordflow">if</span> ( ButtonLighting->isPressed() ) + InfoLighting->setText(L<span class="stringliteral">"on"</span>); + <span class="keywordflow">else</span> + InfoLighting->setText(L<span class="stringliteral">"off"</span>); + + AllColorsControl->resetDirty(); + TextureControl1->resetDirty(); + TextureControl2->resetDirty(); + ControlVertexColors->resetDirty(); + } + + <span class="keywordtype">void</span> updateTextures() + { + TextureControl1->updateTextures(Driver); + TextureControl2->updateTextures(Driver); + } + +<span class="keyword">protected</span>: + + <span class="keywordtype">void</span> updateMaterial(video::SMaterial & material) + { + AllColorsControl->updateMaterialColors(material); + material.Lighting = ButtonLighting->isPressed(); + <span class="keywordflow">if</span> ( TextureControl1->isDirty() ) + { + material.TextureLayer[0].Texture = Driver->getTexture( <a class="code" href="namespaceirr_1_1io.html#ab1bdc45edb3f94d8319c02bc0f840ee1" title="Type used for all file system related strings.">io::path</a>(TextureControl1->getSelectedTextureName()) ); + } + <span class="keywordflow">if</span> ( TextureControl2->isDirty() ) + { + material.TextureLayer[1].Texture = Driver->getTexture( <a class="code" href="namespaceirr_1_1io.html#ab1bdc45edb3f94d8319c02bc0f840ee1" title="Type used for all file system related strings.">io::path</a>(TextureControl2->getSelectedTextureName()) ); + } + <span class="keywordflow">if</span> ( ControlVertexColors->isDirty() ) + { + MeshManipulator->setVertexColors (SceneNode->getMesh(), ControlVertexColors->getColor()); + MeshManipulator->setVertexColors (SceneNode2T->getMesh(), ControlVertexColors->getColor()); + MeshManipulator->setVertexColors (SceneNodeTangents->getMesh(), ControlVertexColors->getColor()); + } + } + + <span class="keywordtype">bool</span> Initialized; + video::IVideoDriver * Driver; + scene::IMeshManipulator* MeshManipulator; + scene::IMeshSceneNode* SceneNode; + scene::IMeshSceneNode* SceneNode2T; + scene::IMeshSceneNode* SceneNodeTangents; + CAllColorsControl* AllColorsControl; + gui::IGUIButton * ButtonLighting; + gui::IGUIStaticText* InfoLighting; + gui::IGUIComboBox * ComboMaterial; + CTextureControl* TextureControl1; + CTextureControl* TextureControl2; + CColorControl* ControlVertexColors; +}; +</pre></div><p>Control to allow setting the color values of a lightscenenode. </p> +<div class="fragment"><pre class="fragment"><span class="keyword">struct </span>SLightNodeControl +{ + <span class="comment">// constructor</span> + SLightNodeControl() : Initialized(false), SceneNode(0), AllColorsControl(0) + { + } + + <span class="keyword">virtual</span> ~SLightNodeControl() + { + <span class="keywordflow">if</span> ( AllColorsControl ) + AllColorsControl->drop(); + } + + <span class="keywordtype">void</span> init(scene::ILightSceneNode* node, gui::IGUIEnvironment* guiEnv, <span class="keyword">const</span> core::position2d<s32> & pos, <span class="keyword">const</span> <span class="keywordtype">wchar_t</span> * description) + { + <span class="keywordflow">if</span> ( Initialized || !node || !guiEnv) <span class="comment">// initializing twice or with invalid data not allowed</span> + <span class="keywordflow">return</span>; + SceneNode = node; + AllColorsControl = <span class="keyword">new</span> CAllColorsControl(guiEnv, pos, description, <span class="keyword">false</span>, guiEnv->getRootGUIElement()); + <span class="keyword">const</span> video::SLight & lightData = SceneNode->getLightData(); + AllColorsControl->setColorsToLightDataColors(lightData); + Initialized = <span class="keyword">true</span>; + } + + <span class="keywordtype">void</span> update() + { + <span class="keywordflow">if</span> ( !Initialized ) + <span class="keywordflow">return</span>; + + video::SLight & lightData = SceneNode->getLightData(); + AllColorsControl->updateLightColors(lightData); + } + +<span class="keyword">protected</span>: + <span class="keywordtype">bool</span> Initialized; + scene::ILightSceneNode* SceneNode; + CAllColorsControl* AllColorsControl; +}; +</pre></div><p>Application configuration </p> +<div class="fragment"><pre class="fragment"><span class="keyword">struct </span>SConfig +{ + SConfig() + : RenderInBackground(true) + , DriverType(video::<a class="code" href="namespaceirr_1_1video.html#ae35a6de6d436c76107ad157fe42356d0ae85481da26159b967191ccc6de1e4a05" title="The Burning's Software Renderer, an alternative software renderer.">EDT_BURNINGSVIDEO</a>) + , ScreenSize(640, 480) + { + } + + <span class="keywordtype">bool</span> RenderInBackground; + <a class="code" href="namespaceirr_1_1video.html#ae35a6de6d436c76107ad157fe42356d0" title="An enum for all types of drivers the Irrlicht Engine supports.">video::E_DRIVER_TYPE</a> DriverType; + core::dimension2d<u32> ScreenSize; +}; +</pre></div><p>Main application class </p> +<div class="fragment"><pre class="fragment"><span class="keyword">class </span>CApp : <span class="keyword">public</span> IEventReceiver +{ + <span class="keyword">friend</span> <span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> *argv[]); + +<span class="keyword">public</span>: + <span class="comment">// constructor</span> + CApp() + : IsRunning(false) + , Device(0) + , Camera(0) + , GlobalAmbient(0) + { + } + + <span class="comment">// destructor</span> + ~CApp() + { + } + + <span class="comment">// stop running - will quit at end of mainloop</span> + <span class="keywordtype">void</span> stopApp() + { + IsRunning = <span class="keyword">false</span>; + } + + <span class="comment">// Event handler</span> + <span class="keyword">virtual</span> <span class="keywordtype">bool</span> OnEvent(<span class="keyword">const</span> SEvent &event) + { + <span class="keywordflow">if</span> (event.EventType == <a class="code" href="namespaceirr.html#ac9eed96e06e85ce3c86fcbbbe9e48a0cae85bb44dd09a29c879d64a05047fc1d2" title="An event of the graphical user interface.">EET_GUI_EVENT</a>) + { + gui::IGUIEnvironment* env = Device->getGUIEnvironment(); + + <span class="keywordflow">switch</span>(event.GUIEvent.EventType) + { + <span class="keywordflow">case</span> <a class="code" href="namespaceirr_1_1gui.html#aeac71ad17341a4b6e9026ae11d576808a90e8bebdd49f2a2e451b1105a87ee7ef" title="A menu item was selected in a (context) menu.">gui::EGET_MENU_ITEM_SELECTED</a>: + { + gui::IGUIContextMenu* menu = (gui::IGUIContextMenu*)event.GUIEvent.Caller; + <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> <span class="keywordtype">id</span> = menu->getItemCommandId(menu->getSelectedItem()); + + <span class="keywordflow">switch</span>(<span class="keywordtype">id</span>) + { + <span class="keywordflow">case</span> GUI_ID_OPEN_TEXTURE: <span class="comment">// File -> Open Texture</span> + env->addFileOpenDialog(L<span class="stringliteral">"Please select a texture file to open"</span>); + <span class="keywordflow">break</span>; + <span class="keywordflow">case</span> GUI_ID_QUIT: <span class="comment">// File -> Quit</span> + stopApp(); + <span class="keywordflow">break</span>; + } + } + <span class="keywordflow">break</span>; + + <span class="keywordflow">case</span> <a class="code" href="namespaceirr_1_1gui.html#aeac71ad17341a4b6e9026ae11d576808a5b6504cf6b541d5ad95407c384632873" title="A file has been selected in the file dialog.">gui::EGET_FILE_SELECTED</a>: + { + <span class="comment">// load the model file, selected in the file open dialog</span> + gui::IGUIFileOpenDialog* dialog = + (gui::IGUIFileOpenDialog*)event.GUIEvent.Caller; + loadTexture(<a class="code" href="namespaceirr_1_1io.html#ab1bdc45edb3f94d8319c02bc0f840ee1" title="Type used for all file system related strings.">io::path</a>(dialog->getFileName()).c_str()); + } + <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>; + } + +<span class="keyword">protected</span>: + + <span class="comment">// Application initialization</span> + <span class="comment">// returns true when it was successful initialized, otherwise false.</span> + <span class="keywordtype">bool</span> init(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> *argv[]) + { + <span class="comment">// ask user for driver</span> + Config.DriverType=driverChoiceConsole(); + <span class="keywordflow">if</span> (Config.DriverType==<a class="code" href="namespaceirr_1_1video.html#ae35a6de6d436c76107ad157fe42356d0ae685cada50f8c100403134d932d0414c" title="No driver, just for counting the elements.">video::EDT_COUNT</a>) + <span class="keywordflow">return</span> <span class="keyword">false</span>; + + <span class="comment">// create the device with the settings from our config</span> + Device = <a class="code" href="namespaceirr.html#abaf4d8719cc26b0d30813abf85e47c76" title="Creates an Irrlicht device. The Irrlicht device is the root object for using the engine.">createDevice</a>(Config.DriverType, Config.ScreenSize); + <span class="keywordflow">if</span> (!Device) + <span class="keywordflow">return</span> <span class="keyword">false</span>; + Device->setWindowCaption( DriverTypeNames[Config.DriverType] ); + Device->setEventReceiver(<span class="keyword">this</span>); + + scene::ISceneManager* smgr = Device->getSceneManager(); + video::IVideoDriver * driver = Device->getVideoDriver (); + gui::IGUIEnvironment* guiEnv = Device->getGUIEnvironment(); + + <span class="comment">// set a nicer font</span> + gui::IGUISkin* skin = guiEnv->getSkin(); + gui::IGUIFont* font = guiEnv->getFont(<span class="stringliteral">"../../media/fonthaettenschweiler.bmp"</span>); + <span class="keywordflow">if</span> (font) + skin->setFont(font); + + <span class="comment">// remove some alpha value because it makes those menus harder to read otherwise</span> + video::SColor col3dHighLight( skin->getColor(<a class="code" href="namespaceirr_1_1gui.html#abd15860fde29833c48daff5f95d5467aa130f7af380737d820220cc59a716b04d" title="Background color of multiple document interface (MDI) applications.">gui::EGDC_APP_WORKSPACE</a>) ); + col3dHighLight.setAlpha(255); + video::SColor colHighLight( col3dHighLight ); + skin->setColor(<a class="code" href="namespaceirr_1_1gui.html#abd15860fde29833c48daff5f95d5467aa1a7a2f4f13165eee4772e76f11866cbd" title="Item(s) selected in a control.">gui::EGDC_HIGH_LIGHT</a>, colHighLight ); + skin->setColor(<a class="code" href="namespaceirr_1_1gui.html#abd15860fde29833c48daff5f95d5467aa1227b2c3a809d139e1ead87aa29fa101" title="Highlight color for three-dimensional display elements (for edges facing the light source...">gui::EGDC_3D_HIGH_LIGHT</a>, col3dHighLight ); + + <span class="comment">// Add some textures which are useful to test material settings</span> + createDefaultTextures(driver); + + <span class="comment">// create a menu</span> + gui::IGUIContextMenu * menuBar = guiEnv->addMenu(); + menuBar->addItem(L<span class="stringliteral">"File"</span>, -1, <span class="keyword">true</span>, <span class="keyword">true</span>); + + gui::IGUIContextMenu* subMenuFile = menuBar->getSubMenu(0); + subMenuFile->addItem(L<span class="stringliteral">"Open texture ..."</span>, GUI_ID_OPEN_TEXTURE); + subMenuFile->addSeparator(); + subMenuFile->addItem(L<span class="stringliteral">"Quit"</span>, GUI_ID_QUIT); + + <span class="comment">// a static camera</span> + Camera = smgr->addCameraSceneNode (0, <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(0, 0, 0), + <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(0, 0, 100), + -1); + + <span class="comment">// add the nodes which are used to show the materials</span> + scene::IMeshSceneNode* nodeL = smgr->addCubeSceneNode (30.0f, 0, -1, + <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(-35, 0, 100), + <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(0, 0, 0), + <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(1.0f, 1.0f, 1.0f)); + NodeLeft.init( nodeL, Device, core::position2d<s32>(10,20), L<span class="stringliteral">"left node"</span> ); + + scene::IMeshSceneNode* nodeR = smgr->addCubeSceneNode (30.0f, 0, -1, + <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(35, 0, 100), + <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(0, 0, 0), + <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(1.0f, 1.0f, 1.0f)); + NodeRight.init( nodeR, Device, core::position2d<s32>(530,20), L<span class="stringliteral">"right node"</span> ); + + <span class="comment">// add one light</span> + scene::ILightSceneNode* nodeLight = smgr->addLightSceneNode(0, <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(0, 0, 0), + video::SColorf(1.0f, 1.0f, 1.0f), + 100.0f); + LightControl.init(nodeLight, guiEnv, core::position2d<s32>(270,20), L<span class="stringliteral">"light"</span> ); + + <span class="comment">// one large cube around everything. That's mainly to make the light more obvious.</span> + scene::IMeshSceneNode* backgroundCube = smgr->addCubeSceneNode (200.0f, 0, -1, <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(0, 0, 0), + <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(45, 0, 0), + <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(1.0f, 1.0f, 1.0f)); + backgroundCube->getMaterial(0).BackfaceCulling = <span class="keyword">false</span>; <span class="comment">// we are within the cube, so we have to disable backface culling to see it</span> + backgroundCube->getMaterial(0).EmissiveColor.set(255,50,50,50); <span class="comment">// we keep some self lighting to keep texts visible</span> + + <span class="comment">// set the ambient light value</span> + GlobalAmbient = <span class="keyword">new</span> CColorControl( guiEnv, core::position2d<s32>(270, 300), L<span class="stringliteral">"global ambient"</span>, guiEnv->getRootGUIElement()); + GlobalAmbient->setColor( smgr->getAmbientLight().toSColor() ); + + <span class="keywordflow">return</span> <span class="keyword">true</span>; + } + + <span class="comment">// Update one frame</span> + <span class="keywordtype">bool</span> update() + { + <span class="keyword">using namespace </span>irr; + + <a class="code" href="classirr_1_1video_1_1_i_video_driver.html" title="Interface to driver which is able to perform 2d and 3d graphics functions.">video::IVideoDriver</a>* videoDriver = Device->getVideoDriver(); + <span class="keywordflow">if</span> ( !Device->run() ) + <span class="keywordflow">return</span> <span class="keyword">false</span>; + + <span class="keywordflow">if</span> ( Device->isWindowActive() || Config.RenderInBackground ) + { + <a class="code" href="classirr_1_1gui_1_1_i_g_u_i_environment.html" title="GUI Environment. Used as factory and manager of all other GUI elements.">gui::IGUIEnvironment</a>* guiEnv = Device->getGUIEnvironment(); + <a class="code" href="classirr_1_1scene_1_1_i_scene_manager.html" title="The Scene Manager manages scene nodes, mesh recources, cameras and all the other stuff.">scene::ISceneManager</a>* smgr = Device->getSceneManager(); + <a class="code" href="classirr_1_1gui_1_1_i_g_u_i_skin.html" title="A skin modifies the look of the GUI elements.">gui::IGUISkin</a> * skin = guiEnv-><a class="code" href="classirr_1_1gui_1_1_i_g_u_i_environment.html#a54ce9072ea7b89cdaea65306e93ba90c" title="Returns pointer to the current gui skin.">getSkin</a>(); + + <span class="comment">// update our controls</span> + NodeLeft.update(); + NodeRight.update(); + LightControl.update(); + + <span class="comment">// update ambient light settings</span> + <span class="keywordflow">if</span> ( GlobalAmbient->isDirty() ) + { + smgr-><a class="code" href="classirr_1_1scene_1_1_i_scene_manager.html#a8a424accb615c4f60fde59f55033a816" title="Sets ambient color of the scene.">setAmbientLight</a>( GlobalAmbient->getColor() ); + GlobalAmbient->resetDirty(); + } + + <span class="comment">// draw everything</span> + <a class="code" href="classirr_1_1video_1_1_s_color.html" title="Class representing a 32 bit ARGB color.">video::SColor</a> bkColor( skin-><a class="code" href="classirr_1_1gui_1_1_i_g_u_i_skin.html#ad1afa2e5e34c30e0cbfb85b1dee2dbe3" title="returns default color">getColor</a>(<a class="code" href="namespaceirr_1_1gui.html#abd15860fde29833c48daff5f95d5467aa130f7af380737d820220cc59a716b04d" title="Background color of multiple document interface (MDI) applications.">gui::EGDC_APP_WORKSPACE</a>) ); + videoDriver->beginScene(<span class="keyword">true</span>, <span class="keyword">true</span>, bkColor); + + smgr-><a class="code" href="classirr_1_1scene_1_1_i_scene_manager.html#a04240262904667c821bd9de5e5fd9b02" title="Draws all the scene nodes.">drawAll</a>(); + guiEnv-><a class="code" href="classirr_1_1gui_1_1_i_g_u_i_environment.html#aa6ba29bbf3121a5954cfa5a9ca72982f" title="Draws all gui elements by traversing the GUI environment starting at the root node.">drawAll</a>(); + + videoDriver->endScene(); + } + + <span class="keywordflow">return</span> <span class="keyword">true</span>; + } + + <span class="comment">// Run the application. Our main loop.</span> + <span class="keywordtype">void</span> run() + { + IsRunning = <span class="keyword">true</span>; + + <span class="keywordflow">if</span> ( !Device ) + <span class="keywordflow">return</span>; + + <span class="comment">// main application loop</span> + <span class="keywordflow">while</span>(IsRunning) + { + <span class="keywordflow">if</span> ( !update() ) + <span class="keywordflow">break</span>; + + Device->sleep( 5 ); + } + } + + <span class="comment">// Close down the application</span> + <span class="keywordtype">void</span> quit() + { + IsRunning = <span class="keyword">false</span>; + GlobalAmbient->drop(); + GlobalAmbient = NULL; + <span class="keywordflow">if</span> ( Device ) + { + Device->closeDevice(); + Device->drop(); + Device = NULL; + } + } + + <span class="comment">// Create some useful textures.</span> + <span class="comment">// Note that the function put readability over speed, you shouldn't use setPixel at runtime but for initialization it's nice.</span> + <span class="keywordtype">void</span> createDefaultTextures(<a class="code" href="classirr_1_1video_1_1_i_video_driver.html" title="Interface to driver which is able to perform 2d and 3d graphics functions.">video::IVideoDriver</a> * driver) + { + <span class="keyword">const</span> <a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> width = 256; + <span class="keyword">const</span> <a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> height = 256; + <a class="code" href="classirr_1_1video_1_1_i_image.html" title="Interface for software image data.">video::IImage</a> * imageA8R8G8B8 = driver-><a class="code" href="classirr_1_1video_1_1_i_video_driver.html#aee1578fdd92118665755f31c0dd1dbb5" title="Creates an empty software image.">createImage</a> (<a class="code" href="namespaceirr_1_1video.html#a1d5e487888c32b1674a8f75116d829eda55c57d63efff39efe33ee733fe962df0" title="Default 32 bit color format. 8 bits are used for every component: red, green, blue and alpha...">video::ECF_A8R8G8B8</a>, <a class="code" href="classirr_1_1core_1_1dimension2d.html">core::dimension2d<u32></a>(width, height)); + <span class="keywordflow">if</span> ( !imageA8R8G8B8 ) + <span class="keywordflow">return</span>; + <span class="keyword">const</span> <a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> pitch = imageA8R8G8B8-><a class="code" href="classirr_1_1video_1_1_i_image.html#aace497c2d12f217a795a546a735e2675" title="Returns pitch of image.">getPitch</a>(); + + <span class="comment">// some nice square-pattern with 9 typical colors</span> + <span class="keywordflow">for</span> ( <a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> y = 0; y < height; ++ y ) + { + <span class="keywordflow">for</span> ( <a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> x = 0; x < pitch; ++x ) + { + <span class="keywordflow">if</span> ( y < height/3 ) + { + <span class="keywordflow">if</span> ( x < width/3 ) + imageA8R8G8B8-><a class="code" href="classirr_1_1video_1_1_i_image.html#a89bf6020ce6ac1066e4d585ce46f79bd" title="Sets a pixel.">setPixel</a> (x, y, SCOL_BLACK); + <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( x < 2*width/3 ) + imageA8R8G8B8-><a class="code" href="classirr_1_1video_1_1_i_image.html#a89bf6020ce6ac1066e4d585ce46f79bd" title="Sets a pixel.">setPixel</a> (x, y, SCOL_BLUE); + <span class="keywordflow">else</span> + imageA8R8G8B8-><a class="code" href="classirr_1_1video_1_1_i_image.html#a89bf6020ce6ac1066e4d585ce46f79bd" title="Sets a pixel.">setPixel</a> (x, y, SCOL_CYAN); + } + <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( y < 2*height/3 ) + { + <span class="keywordflow">if</span> ( x < width/3 ) + imageA8R8G8B8-><a class="code" href="classirr_1_1video_1_1_i_image.html#a89bf6020ce6ac1066e4d585ce46f79bd" title="Sets a pixel.">setPixel</a> (x, y, SCOL_GRAY); + <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( x < 2*width/3 ) + imageA8R8G8B8-><a class="code" href="classirr_1_1video_1_1_i_image.html#a89bf6020ce6ac1066e4d585ce46f79bd" title="Sets a pixel.">setPixel</a> (x, y, SCOL_GREEN); + <span class="keywordflow">else</span> + imageA8R8G8B8-><a class="code" href="classirr_1_1video_1_1_i_image.html#a89bf6020ce6ac1066e4d585ce46f79bd" title="Sets a pixel.">setPixel</a> (x, y, SCOL_MAGENTA); + } + <span class="keywordflow">else</span> + { + <span class="keywordflow">if</span> ( x < width/3 ) + imageA8R8G8B8-><a class="code" href="classirr_1_1video_1_1_i_image.html#a89bf6020ce6ac1066e4d585ce46f79bd" title="Sets a pixel.">setPixel</a> (x, y, SCOL_RED); + <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( x < 2*width/3 ) + imageA8R8G8B8-><a class="code" href="classirr_1_1video_1_1_i_image.html#a89bf6020ce6ac1066e4d585ce46f79bd" title="Sets a pixel.">setPixel</a> (x, y, SCOL_YELLOW); + <span class="keywordflow">else</span> + imageA8R8G8B8-><a class="code" href="classirr_1_1video_1_1_i_image.html#a89bf6020ce6ac1066e4d585ce46f79bd" title="Sets a pixel.">setPixel</a> (x, y, SCOL_WHITE); + } + } + } + driver-><a class="code" href="classirr_1_1video_1_1_i_video_driver.html#a8c02ee280bb738cdf38b77e7a798244e" title="Creates an empty texture of specified size.">addTexture</a> (<a class="code" href="classirr_1_1core_1_1string.html">io::path</a>(<span class="stringliteral">"CARO_A8R8G8B8"</span>), imageA8R8G8B8); + + <span class="comment">// all white</span> + imageA8R8G8B8-><a class="code" href="classirr_1_1video_1_1_i_image.html#a04973e101790130f611c4c6790e5b352" title="fills the surface with given color">fill</a>(SCOL_WHITE); + driver-><a class="code" href="classirr_1_1video_1_1_i_video_driver.html#a8c02ee280bb738cdf38b77e7a798244e" title="Creates an empty texture of specified size.">addTexture</a> (<a class="code" href="classirr_1_1core_1_1string.html">io::path</a>(<span class="stringliteral">"WHITE_A8R8G8B8"</span>), imageA8R8G8B8); + + <span class="comment">// all black</span> + imageA8R8G8B8-><a class="code" href="classirr_1_1video_1_1_i_image.html#a04973e101790130f611c4c6790e5b352" title="fills the surface with given color">fill</a>(SCOL_BLACK); + driver-><a class="code" href="classirr_1_1video_1_1_i_video_driver.html#a8c02ee280bb738cdf38b77e7a798244e" title="Creates an empty texture of specified size.">addTexture</a> (<a class="code" href="classirr_1_1core_1_1string.html">io::path</a>(<span class="stringliteral">"BLACK_A8R8G8B8"</span>), imageA8R8G8B8); + + <span class="comment">// gray-scale</span> + <span class="keywordflow">for</span> ( <a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> y = 0; y < height; ++ y ) + { + <span class="keywordflow">for</span> ( <a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> x = 0; x < pitch; ++x ) + { + imageA8R8G8B8-><a class="code" href="classirr_1_1video_1_1_i_image.html#a89bf6020ce6ac1066e4d585ce46f79bd" title="Sets a pixel.">setPixel</a> (x, y, <a class="code" href="classirr_1_1video_1_1_s_color.html" title="Class representing a 32 bit ARGB color.">video::SColor</a>(y, x,x,x) ); + } + } + driver-><a class="code" href="classirr_1_1video_1_1_i_video_driver.html#a8c02ee280bb738cdf38b77e7a798244e" title="Creates an empty texture of specified size.">addTexture</a> (<a class="code" href="classirr_1_1core_1_1string.html">io::path</a>(<span class="stringliteral">"GRAYSCALE_A8R8G8B8"</span>), imageA8R8G8B8); + + imageA8R8G8B8-><a class="code" href="classirr_1_1_i_reference_counted.html#afb169a857e0d2cdb96b8821cb9bff17a" title="Drops the object. Decrements the reference counter by one.">drop</a>(); + } + + <span class="comment">// Load a texture and make sure nodes know it when more textures are available.</span> + <span class="keywordtype">void</span> loadTexture(<span class="keyword">const</span> <a class="code" href="classirr_1_1core_1_1string.html">io::path</a> &name) + { + Device->getVideoDriver()->getTexture(name); + NodeLeft.updateTextures(); + NodeRight.updateTextures(); + } + +<span class="keyword">private</span>: + SConfig Config; + <span class="keyword">volatile</span> <span class="keywordtype">bool</span> IsRunning; + <a class="code" href="classirr_1_1_irrlicht_device.html" title="The Irrlicht device. You can create it with createDevice() or createDeviceEx().">IrrlichtDevice</a> * Device; + <a class="code" href="classirr_1_1scene_1_1_i_camera_scene_node.html" title="Scene Node which is a (controlable) camera.">scene::ICameraSceneNode</a> * Camera; + SMeshNodeControl NodeLeft; + SMeshNodeControl NodeRight; + SLightNodeControl LightControl; + CColorControl * GlobalAmbient; +}; +</pre></div><p>A very short main as we do everything else in classes. </p> +<div class="fragment"><pre class="fragment"><span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> *argv[]) +{ + CApp APP; + + <span class="keywordflow">if</span> ( !APP.init(argc, argv) ) + { + printf(<span class="stringliteral">"init failed\n"</span>); + <span class="keywordflow">return</span> 1; + } + + APP.run(); + APP.quit(); + + <span class="keywordflow">return</span> 0; +} +</pre></div> </div></div> +</div> + <div id="nav-path" class="navpath"> + <ul> +<!-- window showing the filter options --> +<div id="MSearchSelectWindow" + onmouseover="return searchBox.OnSearchSelectShow()" + onmouseout="return searchBox.OnSearchSelectHide()" + onkeydown="return searchBox.OnSearchSelectKey(event)"> +<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark"> </span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark"> </span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark"> </span>Namespaces</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark"> </span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark"> </span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark"> </span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark"> </span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark"> </span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark"> </span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(9)"><span class="SelectionMark"> </span>Friends</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(10)"><span class="SelectionMark"> </span>Defines</a></div> + +<!-- iframe showing the search results (closed by default) --> +<div id="MSearchResultsWindow"> +<iframe src="javascript:void(0)" frameborder="0" + name="MSearchResults" id="MSearchResults"> +</iframe> +</div> + + + <li class="footer"> +<a href="http://irrlicht.sourceforge.net" target="_blank">Irrlicht +Engine</a> Documentation © 2003-2012 by Nikolaus Gebhardt. Generated on Fri Mar 12 2021 17:21:54 for Irrlicht 3D Engine by +<a href="http://www.doxygen.org/index.html" target="_blank">Doxygen</a> 1.7.5.1 </li> + </ul> + </div> + + +</body> +</html> |
