aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/others/irrlicht-1.8.1/doc/html/example001.html
diff options
context:
space:
mode:
Diffstat (limited to 'src/others/irrlicht-1.8.1/doc/html/example001.html')
-rw-r--r--src/others/irrlicht-1.8.1/doc/html/example001.html232
1 files changed, 232 insertions, 0 deletions
diff --git a/src/others/irrlicht-1.8.1/doc/html/example001.html b/src/others/irrlicht-1.8.1/doc/html/example001.html
new file mode 100644
index 0000000..0943cd9
--- /dev/null
+++ b/src/others/irrlicht-1.8.1/doc/html/example001.html
@@ -0,0 +1,232 @@
1<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2<html xmlns="http://www.w3.org/1999/xhtml">
3<head>
4<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
5<title>Irrlicht 3D Engine: Tutorial 1: HelloWorld</title>
6
7<link href="tabs.css" rel="stylesheet" type="text/css"/>
8<link href="doxygen.css" rel="stylesheet" type="text/css" />
9<link href="navtree.css" rel="stylesheet" type="text/css"/>
10<script type="text/javascript" src="jquery.js"></script>
11<script type="text/javascript" src="resize.js"></script>
12<script type="text/javascript" src="navtree.js"></script>
13<script type="text/javascript">
14 $(document).ready(initResizable);
15</script>
16<link href="search/search.css" rel="stylesheet" type="text/css"/>
17<script type="text/javascript" src="search/search.js"></script>
18<script type="text/javascript">
19 $(document).ready(function() { searchBox.OnSelectItem(0); });
20</script>
21
22</head>
23<body>
24<div id="top"><!-- do not remove this div! -->
25
26
27<div id="titlearea">
28<table cellspacing="0" cellpadding="0">
29 <tbody>
30 <tr style="height: 56px;">
31
32 <td id="projectlogo"><img alt="Logo" src="irrlichtlogo.png"/></td>
33
34
35 <td style="padding-left: 0.5em;">
36 <div id="projectname">Irrlicht 3D Engine
37
38 </div>
39
40 </td>
41
42
43
44
45 <td> <div id="MSearchBox" class="MSearchBoxInactive">
46 <span class="left">
47 <img id="MSearchSelect" src="search/mag_sel.png"
48 onmouseover="return searchBox.OnSearchSelectShow()"
49 onmouseout="return searchBox.OnSearchSelectHide()"
50 alt=""/>
51 <input type="text" id="MSearchField" value="Search" accesskey="S"
52 onfocus="searchBox.OnSearchFieldFocus(true)"
53 onblur="searchBox.OnSearchFieldFocus(false)"
54 onkeyup="searchBox.OnSearchFieldChange(event)"/>
55 </span><span class="right">
56 <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
57 </span>
58 </div>
59</td>
60
61
62 </tr>
63 </tbody>
64</table>
65</div>
66
67<!-- Generated by Doxygen 1.7.5.1 -->
68<script type="text/javascript">
69var searchBox = new SearchBox("searchBox", "search",false,'Search');
70</script>
71<script type="text/javascript" src="dynsections.js"></script>
72</div>
73<div id="side-nav" class="ui-resizable side-nav-resizable">
74 <div id="nav-tree">
75 <div id="nav-tree-contents">
76 </div>
77 </div>
78 <div id="splitbar" style="-moz-user-select:none;"
79 class="ui-resizable-handle">
80 </div>
81</div>
82<script type="text/javascript">
83 initNavTree('example001.html','');
84</script>
85<div id="doc-content">
86<div class="header">
87 <div class="headertitle">
88<div class="title">Tutorial 1: HelloWorld </div> </div>
89</div>
90<div class="contents">
91<div class="textblock"><div class="image">
92<img src="001shot.jpg" alt="001shot.jpg"/>
93</div>
94 <p>This Tutorial shows how to set up the IDE for using the Irrlicht Engine and how to write a simple HelloWorld program with it. The program will show how to use the basics of the VideoDriver, the GUIEnvironment, and the SceneManager. Microsoft Visual Studio is used as an IDE, but you will also be able to understand everything if you are using a different one or even another operating system than windows.</p>
95<p>You have to include the header file &lt;<a class="el" href="irrlicht_8h.html" title="Main header file of the irrlicht, the only file needed to include.">irrlicht.h</a>&gt; in order to use the engine. The header file can be found in the Irrlicht Engine SDK directory <code>include</code>. To let the compiler find this header file, the directory where it is located has to be specified. This is different for every IDE and compiler you use. Let's explain shortly how to do this in Microsoft Visual Studio:</p>
96<ul>
97<li>If you use Version 6.0, select the Menu Extras -&gt; Options. Select the directories tab, and select the 'Include' Item in the combo box. Add the <code>include</code> directory of the irrlicht engine folder to the list of directories. Now the compiler will find the <a class="el" href="irrlicht_8h.html" title="Main header file of the irrlicht, the only file needed to include.">Irrlicht.h</a> header file. We also need the irrlicht.lib to be found, so stay in that dialog, select 'Libraries' in the combo box and add the <code>lib/VisualStudio</code> directory. <div class="image">
98<img src="vc6optionsdir.jpg" alt="vc6optionsdir.jpg"/>
99</div>
100 <div class="image">
101<img src="vc6include.jpg" alt="vc6include.jpg"/>
102</div>
103 </li>
104</ul>
105<ul>
106<li>If your IDE is Visual Studio .NET, select Tools -&gt; Options. Select the projects entry and then select VC++ directories. Select 'show directories for include files' in the combo box, and add the <code>include</code> directory of the irrlicht engine folder to the list of directories. Now the compiler will find the <a class="el" href="irrlicht_8h.html" title="Main header file of the irrlicht, the only file needed to include.">Irrlicht.h</a> header file. We also need the irrlicht.lib to be found, so stay in that dialog, select 'show directories for Library files' and add the <code>lib/VisualStudio</code> directory. <div class="image">
107<img src="vcnetinclude.jpg" alt="vcnetinclude.jpg"/>
108</div>
109 </li>
110</ul>
111<p>That's it. With your IDE set up like this, you will now be able to develop applications with the Irrlicht Engine.</p>
112<p>Lets start!</p>
113<p>After we have set up the IDE, the compiler will know where to find the Irrlicht Engine header files so we can include it now in our code. </p>
114<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>
115</pre></div><p>In the Irrlicht Engine, everything can be found in the namespace 'irr'. So if you want to use a class of the engine, you have to write irr:: before the name of the class. For example to use the IrrlichtDevice write: <a class="el" href="classirr_1_1_irrlicht_device.html" title="The Irrlicht device. You can create it with createDevice() or createDeviceEx().">irr::IrrlichtDevice</a>. To get rid of the irr:: in front of the name of every class, we tell the compiler that we use that namespace from now on, and we will not have to write irr:: anymore. </p>
116<div class="fragment"><pre class="fragment"><span class="keyword">using namespace </span>irr;
117</pre></div><p>There are 5 sub namespaces in the Irrlicht Engine. Take a look at them, you can read a detailed description of them in the documentation by clicking on the top menu item 'Namespace List' or by using this link: <a href="http://irrlicht.sourceforge.net/docu/namespaces.html">http://irrlicht.sourceforge.net/docu/namespaces.html</a> Like the irr namespace, we do not want these 5 sub namespaces now, to keep this example simple. Hence, we tell the compiler again that we do not want always to write their names. </p>
118<div class="fragment"><pre class="fragment"><span class="keyword">using namespace </span>core;
119<span class="keyword">using namespace </span>scene;
120<span class="keyword">using namespace </span>video;
121<span class="keyword">using namespace </span>io;
122<span class="keyword">using namespace </span>gui;
123</pre></div><p>To be able to use the Irrlicht.DLL file, we need to link with the Irrlicht.lib. We could set this option in the project settings, but to make it easy, we use a pragma comment lib for VisualStudio. On Windows platforms, we have to get rid of the console window, which pops up when starting a program with main(). This is done by the second pragma. We could also use the WinMain method, though losing platform independence then. </p>
124<div class="fragment"><pre class="fragment"><span class="preprocessor">#ifdef _IRR_WINDOWS_</span>
125<span class="preprocessor"></span><span class="preprocessor">#pragma comment(lib, &quot;Irrlicht.lib&quot;)</span>
126<span class="preprocessor"></span><span class="preprocessor">#pragma comment(linker, &quot;/subsystem:windows /ENTRY:mainCRTStartup&quot;)</span>
127<span class="preprocessor">#endif</span>
128</pre></div><p>This is the main method. We can now use main() on every platform. </p>
129<div class="fragment"><pre class="fragment"><span class="keywordtype">int</span> main()
130{
131</pre></div><p>The most important function of the engine is the <a class="el" href="namespaceirr.html#abaf4d8719cc26b0d30813abf85e47c76" title="Creates an Irrlicht device. The Irrlicht device is the root object for using the engine.">createDevice()</a> function. The IrrlichtDevice is created by it, which is the root object for doing anything with the engine. <a class="el" href="namespaceirr.html#abaf4d8719cc26b0d30813abf85e47c76" title="Creates an Irrlicht device. The Irrlicht device is the root object for using the engine.">createDevice()</a> has 7 parameters:</p>
132<ul>
133<li>deviceType: Type of the device. This can currently be the Null-device, one of the two software renderers, D3D8, D3D9, or OpenGL. In this example we use EDT_SOFTWARE, but to try out, you might want to change it to EDT_BURNINGSVIDEO, EDT_NULL, EDT_DIRECT3D8, EDT_DIRECT3D9, or EDT_OPENGL.</li>
134</ul>
135<ul>
136<li>windowSize: Size of the Window or screen in FullScreenMode to be created. In this example we use 640x480.</li>
137</ul>
138<ul>
139<li>bits: Amount of color bits per pixel. This should be 16 or 32. The parameter is often ignored when running in windowed mode.</li>
140</ul>
141<ul>
142<li>fullscreen: Specifies if we want the device to run in fullscreen mode or not.</li>
143</ul>
144<ul>
145<li>stencilbuffer: Specifies if we want to use the stencil buffer (for drawing shadows).</li>
146</ul>
147<ul>
148<li>vsync: Specifies if we want to have vsync enabled, this is only useful in fullscreen mode.</li>
149</ul>
150<ul>
151<li>eventReceiver: An object to receive events. We do not want to use this parameter here, and set it to 0.</li>
152</ul>
153<p>Always check the return value to cope with unsupported drivers, dimensions, etc. </p>
154<div class="fragment"><pre class="fragment"> IrrlichtDevice *device =
155 <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>( <a class="code" href="namespaceirr_1_1video.html#ae35a6de6d436c76107ad157fe42356d0a1598cd235a1a6bd052e2011b559e8995" title="The Irrlicht Engine Software renderer.">video::EDT_SOFTWARE</a>, dimension2d&lt;u32&gt;(640, 480), 16,
156 <span class="keyword">false</span>, <span class="keyword">false</span>, <span class="keyword">false</span>, 0);
157
158 <span class="keywordflow">if</span> (!device)
159 <span class="keywordflow">return</span> 1;
160</pre></div><p>Set the caption of the window to some nice text. Note that there is an 'L' in front of the string. The Irrlicht Engine uses wide character strings when displaying text. </p>
161<div class="fragment"><pre class="fragment"> device-&gt;setWindowCaption(L<span class="stringliteral">&quot;Hello World! - Irrlicht Engine Demo&quot;</span>);
162</pre></div><p>Get a pointer to the VideoDriver, the SceneManager and the graphical user interface environment, so that we do not always have to write device-&gt;getVideoDriver(), device-&gt;getSceneManager(), or device-&gt;getGUIEnvironment(). </p>
163<div class="fragment"><pre class="fragment"> IVideoDriver* driver = device-&gt;getVideoDriver();
164 ISceneManager* smgr = device-&gt;getSceneManager();
165 IGUIEnvironment* guienv = device-&gt;getGUIEnvironment();
166</pre></div><p>We add a hello world label to the window, using the GUI environment. The text is placed at the position (10,10) as top left corner and (260,22) as lower right corner. </p>
167<div class="fragment"><pre class="fragment"> guienv-&gt;addStaticText(L<span class="stringliteral">&quot;Hello World! This is the Irrlicht Software renderer!&quot;</span>,
168 rect&lt;s32&gt;(10,10,260,22), <span class="keyword">true</span>);
169</pre></div><p>To show something interesting, we load a Quake 2 model and display it. We only have to get the Mesh from the Scene Manager with getMesh() and add a SceneNode to display the mesh with addAnimatedMeshSceneNode(). We check the return value of getMesh() to become aware of loading problems and other errors.</p>
170<p>Instead of writing the filename sydney.md2, it would also be possible to load a Maya object file (.obj), a complete Quake3 map (.bsp) or any other supported file format. By the way, that cool Quake 2 model called sydney was modelled by Brian Collins. </p>
171<div class="fragment"><pre class="fragment"> IAnimatedMesh* mesh = smgr-&gt;getMesh(<span class="stringliteral">&quot;../../media/sydney.md2&quot;</span>);
172 <span class="keywordflow">if</span> (!mesh)
173 {
174 device-&gt;drop();
175 <span class="keywordflow">return</span> 1;
176 }
177 IAnimatedMeshSceneNode* node = smgr-&gt;addAnimatedMeshSceneNode( mesh );
178</pre></div><p>To let the mesh look a little bit nicer, we change its material. We disable lighting because we do not have a dynamic light in here, and the mesh would be totally black otherwise. Then we set the frame loop, such that the predefined STAND animation is used. And last, we apply a texture to the mesh. Without it the mesh would be drawn using only a color. </p>
179<div class="fragment"><pre class="fragment"> <span class="keywordflow">if</span> (node)
180 {
181 node-&gt;setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#a8a3bc00ae8137535b9fbc5f40add70d3acea597a2692b8415486a464a7f954d34" title="Will this material be lighted? Default: true.">EMF_LIGHTING</a>, <span class="keyword">false</span>);
182 node-&gt;setMD2Animation(<a class="code" href="namespaceirr_1_1scene.html#a08d4a84966e1d2886d0d57e4acbb4f19a35893ae58423c41dace23ad13e262e2c">scene::EMAT_STAND</a>);
183 node-&gt;setMaterialTexture( 0, driver-&gt;getTexture(<span class="stringliteral">&quot;../../media/sydney.bmp&quot;</span>) );
184 }
185</pre></div><p>To look at the mesh, we place a camera into 3d space at the position (0, 30, -40). The camera looks from there to (0,5,0), which is approximately the place where our md2 model is. </p>
186<div class="fragment"><pre class="fragment"> smgr-&gt;addCameraSceneNode(0, <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">vector3df</a>(0,30,-40), <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">vector3df</a>(0,5,0));
187</pre></div><p>Ok, now we have set up the scene, lets draw everything: We run the device in a while() loop, until the device does not want to run any more. This would be when the user closes the window or presses ALT+F4 (or whatever keycode closes a window). </p>
188<div class="fragment"><pre class="fragment"> <span class="keywordflow">while</span>(device-&gt;run())
189 {
190</pre></div><p>Anything can be drawn between a beginScene() and an endScene() call. The beginScene() call clears the screen with a color and the depth buffer, if desired. Then we let the Scene Manager and the GUI Environment draw their content. With the endScene() call everything is presented on the screen. </p>
191<div class="fragment"><pre class="fragment"> driver-&gt;beginScene(<span class="keyword">true</span>, <span class="keyword">true</span>, SColor(255,100,101,140));
192
193 smgr-&gt;drawAll();
194 guienv-&gt;drawAll();
195
196 driver-&gt;endScene();
197 }
198</pre></div><p>After we are done with the render loop, we have to delete the Irrlicht Device created before with <a class="el" href="namespaceirr.html#abaf4d8719cc26b0d30813abf85e47c76" title="Creates an Irrlicht device. The Irrlicht device is the root object for using the engine.">createDevice()</a>. In the Irrlicht Engine, you have to delete all objects you created with a method or function which starts with 'create'. The object is simply deleted by calling -&gt;drop(). See the documentation at <a class="el" href="classirr_1_1_i_reference_counted.html#afb169a857e0d2cdb96b8821cb9bff17a" title="Drops the object. Decrements the reference counter by one.">irr::IReferenceCounted::drop()</a> for more information. </p>
199<div class="fragment"><pre class="fragment"> device-&gt;drop();
200
201 <span class="keywordflow">return</span> 0;
202}
203</pre></div><p>That's it. Compile and run. </p>
204</div></div>
205</div>
206 <div id="nav-path" class="navpath">
207 <ul>
208<!-- window showing the filter options -->
209<div id="MSearchSelectWindow"
210 onmouseover="return searchBox.OnSearchSelectShow()"
211 onmouseout="return searchBox.OnSearchSelectHide()"
212 onkeydown="return searchBox.OnSearchSelectKey(event)">
213<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Namespaces</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(9)"><span class="SelectionMark">&#160;</span>Friends</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(10)"><span class="SelectionMark">&#160;</span>Defines</a></div>
214
215<!-- iframe showing the search results (closed by default) -->
216<div id="MSearchResultsWindow">
217<iframe src="javascript:void(0)" frameborder="0"
218 name="MSearchResults" id="MSearchResults">
219</iframe>
220</div>
221
222
223 <li class="footer">
224<a href="http://irrlicht.sourceforge.net" target="_blank">Irrlicht
225Engine</a> Documentation &copy; 2003-2012 by Nikolaus Gebhardt. Generated on Sun Nov 17 2013 20:18:41 for Irrlicht 3D Engine by
226<a href="http://www.doxygen.org/index.html" target="_blank">Doxygen</a> 1.7.5.1 </li>
227 </ul>
228 </div>
229
230
231</body>
232</html>