aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/irrlicht-1.8/doc/html/example014.html
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/irrlicht-1.8/doc/html/example014.html')
-rw-r--r--libraries/irrlicht-1.8/doc/html/example014.html317
1 files changed, 317 insertions, 0 deletions
diff --git a/libraries/irrlicht-1.8/doc/html/example014.html b/libraries/irrlicht-1.8/doc/html/example014.html
new file mode 100644
index 0000000..da6979a
--- /dev/null
+++ b/libraries/irrlicht-1.8/doc/html/example014.html
@@ -0,0 +1,317 @@
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 14: Win32 Window</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('example014.html','');
84</script>
85<div id="doc-content">
86<div class="header">
87 <div class="headertitle">
88<div class="title">Tutorial 14: Win32 Window </div> </div>
89</div>
90<div class="contents">
91<div class="textblock"><div class="image">
92<img src="014shot.jpg" alt="014shot.jpg"/>
93</div>
94 <p>This example only runs under MS Windows and demonstrates that Irrlicht can render inside a win32 window. MFC and .NET Windows.Forms windows are possible, too.</p>
95<p>In the beginning, we create a windows window using the windows API. I'm not going to explain this code, because it is windows specific. See the MSDN or a windows book for details. </p>
96<div class="fragment"><pre class="fragment"><span class="preprocessor">#include &lt;<a class="code" href="irrlicht_8h.html" title="Main header file of the irrlicht, the only file needed to include.">irrlicht.h</a>&gt;</span>
97<span class="preprocessor">#ifndef _IRR_WINDOWS_</span>
98<span class="preprocessor"></span><span class="preprocessor">#error Windows only example</span>
99<span class="preprocessor"></span><span class="preprocessor">#else</span>
100<span class="preprocessor"></span><span class="preprocessor">#include &lt;windows.h&gt;</span> <span class="comment">// this example only runs with windows</span>
101<span class="preprocessor">#include &lt;iostream&gt;</span>
102<span class="preprocessor">#include &quot;<a class="code" href="driver_choice_8h.html">driverChoice.h</a>&quot;</span>
103
104<span class="keyword">using namespace </span>irr;
105
106<span class="preprocessor">#pragma comment(lib, &quot;irrlicht.lib&quot;)</span>
107<span class="preprocessor"></span>
108HWND hOKButton;
109HWND hWnd;
110
111<span class="keyword">static</span> LRESULT CALLBACK CustomWndProc(HWND hWnd, UINT message,
112 WPARAM wParam, LPARAM lParam)
113{
114 <span class="keywordflow">switch</span> (message)
115 {
116 <span class="keywordflow">case</span> WM_COMMAND:
117 {
118 HWND hwndCtl = (HWND)lParam;
119 <span class="keywordtype">int</span> code = HIWORD(wParam);
120
121 <span class="keywordflow">if</span> (hwndCtl == hOKButton)
122 {
123 DestroyWindow(hWnd);
124 PostQuitMessage(0);
125 <span class="keywordflow">return</span> 0;
126 }
127 }
128 <span class="keywordflow">break</span>;
129 <span class="keywordflow">case</span> WM_DESTROY:
130 PostQuitMessage(0);
131 <span class="keywordflow">return</span> 0;
132
133 }
134
135 <span class="keywordflow">return</span> DefWindowProc(hWnd, message, wParam, lParam);
136}
137</pre></div><p>Now ask for the driver and create the Windows specific window. </p>
138<div class="fragment"><pre class="fragment"><span class="keywordtype">int</span> main()
139{
140 <span class="comment">// ask user for driver</span>
141 <a class="code" href="namespaceirr_1_1video.html#ae35a6de6d436c76107ad157fe42356d0" title="An enum for all types of drivers the Irrlicht Engine supports.">video::E_DRIVER_TYPE</a> driverType=driverChoiceConsole();
142 <span class="keywordflow">if</span> (driverType==<a class="code" href="namespaceirr_1_1video.html#ae35a6de6d436c76107ad157fe42356d0ae685cada50f8c100403134d932d0414c" title="No driver, just for counting the elements.">video::EDT_COUNT</a>)
143 <span class="keywordflow">return</span> 1;
144
145 printf(<span class="stringliteral">&quot;Select the render window (some dead window may exist too):\n&quot;</span>\
146 <span class="stringliteral">&quot; (a) Window with button (via CreationParam)\n&quot;</span>\
147 <span class="stringliteral">&quot; (b) Window with button (via beginScene)\n&quot;</span>\
148 <span class="stringliteral">&quot; (c) Own Irrlicht window (default behavior)\n&quot;</span>\
149 <span class="stringliteral">&quot; (otherKey) exit\n\n&quot;</span>);
150
151 <span class="keywordtype">char</span> key;
152 std::cin &gt;&gt; key;
153 <span class="keywordflow">if</span> (key != <span class="charliteral">&#39;a&#39;</span> &amp;&amp; key != <span class="charliteral">&#39;b&#39;</span> &amp;&amp; key != <span class="charliteral">&#39;c&#39;</span>)
154 <span class="keywordflow">return</span> 1;
155
156 HINSTANCE hInstance = 0;
157 <span class="comment">// create dialog</span>
158
159 <span class="keyword">const</span> <span class="keywordtype">char</span>* Win32ClassName = <span class="stringliteral">&quot;CIrrlichtWindowsTestDialog&quot;</span>;
160
161 WNDCLASSEX wcex;
162 wcex.cbSize = <span class="keyword">sizeof</span>(WNDCLASSEX);
163 wcex.style = CS_HREDRAW | CS_VREDRAW;
164 wcex.lpfnWndProc = (WNDPROC)CustomWndProc;
165 wcex.cbClsExtra = 0;
166 wcex.cbWndExtra = DLGWINDOWEXTRA;
167 wcex.hInstance = hInstance;
168 wcex.hIcon = NULL;
169 wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
170 wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW);
171 wcex.lpszMenuName = 0;
172 wcex.lpszClassName = Win32ClassName;
173 wcex.hIconSm = 0;
174
175 RegisterClassEx(&amp;wcex);
176
177 DWORD style = WS_SYSMENU | WS_BORDER | WS_CAPTION |
178 WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_MAXIMIZEBOX | WS_MINIMIZEBOX | WS_SIZEBOX;
179
180 <span class="keywordtype">int</span> windowWidth = 440;
181 <span class="keywordtype">int</span> windowHeight = 380;
182
183 hWnd = CreateWindow( Win32ClassName, <span class="stringliteral">&quot;Irrlicht Win32 window example&quot;</span>,
184 style, 100, 100, windowWidth, windowHeight,
185 NULL, NULL, hInstance, NULL);
186
187 RECT clientRect;
188 GetClientRect(hWnd, &amp;clientRect);
189 windowWidth = clientRect.right;
190 windowHeight = clientRect.bottom;
191
192 <span class="comment">// create ok button</span>
193
194 hOKButton = CreateWindow(<span class="stringliteral">&quot;BUTTON&quot;</span>, <span class="stringliteral">&quot;OK - Close&quot;</span>, WS_CHILD | WS_VISIBLE | BS_TEXT,
195 windowWidth - 160, windowHeight - 40, 150, 30, hWnd, NULL, hInstance, NULL);
196
197 <span class="comment">// create some text</span>
198
199 CreateWindow(<span class="stringliteral">&quot;STATIC&quot;</span>, <span class="stringliteral">&quot;This is Irrlicht running inside a standard Win32 window.\n&quot;</span>\
200 <span class="stringliteral">&quot;Also mixing with MFC and .NET Windows.Forms is possible.&quot;</span>,
201 WS_CHILD | WS_VISIBLE, 20, 20, 400, 40, hWnd, NULL, hInstance, NULL);
202
203 <span class="comment">// create window to put irrlicht in</span>
204
205 HWND hIrrlichtWindow = CreateWindow(<span class="stringliteral">&quot;BUTTON&quot;</span>, <span class="stringliteral">&quot;&quot;</span>,
206 WS_CHILD | WS_VISIBLE | BS_OWNERDRAW,
207 50, 80, 320, 220, hWnd, NULL, hInstance, NULL);
208 video::SExposedVideoData videodata((key==<span class="charliteral">&#39;b&#39;</span>)?hIrrlichtWindow:0);
209</pre></div><p>So now that we have some window, we can create an Irrlicht device inside of it. We use Irrlicht createEx() function for this. We only need the handle (HWND) to that window, set it as windowsID parameter and start up the engine as usual. That's it. </p>
210<div class="fragment"><pre class="fragment"> <span class="comment">// create irrlicht device in the button window</span>
211
212 <a class="code" href="structirr_1_1_s_irrlicht_creation_parameters.html" title="Structure for holding Irrlicht Device creation parameters.">irr::SIrrlichtCreationParameters</a> param;
213 param.<a class="code" href="structirr_1_1_s_irrlicht_creation_parameters.html#a1ea2f50c3b3a8eed6602a1a86e1cdf82" title="Type of video driver used to render graphics.">DriverType</a> = driverType;
214 <span class="keywordflow">if</span> (key==<span class="charliteral">&#39;a&#39;</span>)
215 param.<a class="code" href="structirr_1_1_s_irrlicht_creation_parameters.html#af287810d910a23f8f7db98cef87b6eae" title="Window Id.">WindowId</a> = <span class="keyword">reinterpret_cast&lt;</span><span class="keywordtype">void</span>*<span class="keyword">&gt;</span>(hIrrlichtWindow);
216
217 <a class="code" href="classirr_1_1_irrlicht_device.html" title="The Irrlicht device. You can create it with createDevice() or createDeviceEx().">irr::IrrlichtDevice</a>* device = <a class="code" href="namespaceirr.html#ac83a30d674204dcb94d70f849e9b4a62" title="Creates an Irrlicht device with the option to specify advanced parameters.">irr::createDeviceEx</a>(param);
218 <span class="keywordflow">if</span> (!device)
219 <span class="keywordflow">return</span> 1;
220
221 <span class="comment">// setup a simple 3d scene</span>
222
223 <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.">irr::scene::ISceneManager</a>* smgr = device-&gt;<a class="code" href="classirr_1_1_irrlicht_device.html#a891b503ff4d5041296d88f23f97d7b3d" title="Provides access to the scene manager.">getSceneManager</a>();
224 video::IVideoDriver* driver = device-&gt;<a class="code" href="classirr_1_1_irrlicht_device.html#ada90707ba5c645d47e000e4e0f87c4c4" title="Provides access to the video driver for drawing 3d and 2d geometry.">getVideoDriver</a>();
225
226 <span class="keywordflow">if</span> (driverType==<a class="code" href="namespaceirr_1_1video.html#ae35a6de6d436c76107ad157fe42356d0a2715182a79f1cb8e2826fd68a8150a53" title="OpenGL device, available on most platforms.">video::EDT_OPENGL</a>)
227 {
228 HDC HDc=GetDC(hIrrlichtWindow);
229 PIXELFORMATDESCRIPTOR pfd={0};
230 pfd.nSize=<span class="keyword">sizeof</span>(PIXELFORMATDESCRIPTOR);
231 <span class="keywordtype">int</span> pf = GetPixelFormat(HDc);
232 DescribePixelFormat(HDc, pf, <span class="keyword">sizeof</span>(PIXELFORMATDESCRIPTOR), &amp;pfd);
233 pfd.dwFlags |= PFD_DOUBLEBUFFER | PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW;
234 pfd.cDepthBits=16;
235 pf = ChoosePixelFormat(HDc, &amp;pfd);
236 SetPixelFormat(HDc, pf, &amp;pfd);
237 videodata.OpenGLWin32.HDc = HDc;
238 videodata.OpenGLWin32.HRc=wglCreateContext(HDc);
239 wglShareLists((HGLRC)driver-&gt;getExposedVideoData().OpenGLWin32.HRc, (HGLRC)videodata.OpenGLWin32.HRc);
240 }
241 scene::ICameraSceneNode* cam = smgr-&gt;<a class="code" href="classirr_1_1scene_1_1_i_scene_manager.html#afc3733849319078d5d22d94f58c7d1f2" title="Adds a camera scene node to the scene graph and sets it as active camera.">addCameraSceneNode</a>();
242 cam-&gt;setTarget(<a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(0,0,0));
243
244 scene::ISceneNodeAnimator* anim =
245 smgr-&gt;<a class="code" href="classirr_1_1scene_1_1_i_scene_manager.html#a2e49ff49bc9e88e8ecf3d681354e1ab6" title="Creates a fly circle animator, which lets the attached scene node fly around a center.">createFlyCircleAnimator</a>(<a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(0,15,0), 30.0f);
246 cam-&gt;addAnimator(anim);
247 anim-&gt;drop();
248
249 scene::ISceneNode* cube = smgr-&gt;<a class="code" href="classirr_1_1scene_1_1_i_scene_manager.html#a23d1328c68b1585f613108f386fabc1c" title="Adds a cube scene node.">addCubeSceneNode</a>(20);
250
251 cube-&gt;setMaterialTexture(0, driver-&gt;getTexture(<span class="stringliteral">&quot;../../media/wall.bmp&quot;</span>));
252 cube-&gt;setMaterialTexture(1, driver-&gt;getTexture(<span class="stringliteral">&quot;../../media/water.jpg&quot;</span>));
253 cube-&gt;setMaterialFlag( <a class="code" href="namespaceirr_1_1video.html#a8a3bc00ae8137535b9fbc5f40add70d3acea597a2692b8415486a464a7f954d34" title="Will this material be lighted? Default: true.">video::EMF_LIGHTING</a>, <span class="keyword">false</span> );
254 cube-&gt;setMaterialType( <a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1ad8574343353ed8ade6e78bc04d64b6ae" title="A reflecting material with an optional non reflecting texture layer.">video::EMT_REFLECTION_2_LAYER</a> );
255
256 smgr-&gt;<a class="code" href="classirr_1_1scene_1_1_i_scene_manager.html#a2b08b9f20ec62faeffc02b9fed9fd683" title="Adds a skybox scene node to the scene graph.">addSkyBoxSceneNode</a>(
257 driver-&gt;getTexture(<span class="stringliteral">&quot;../../media/irrlicht2_up.jpg&quot;</span>),
258 driver-&gt;getTexture(<span class="stringliteral">&quot;../../media/irrlicht2_dn.jpg&quot;</span>),
259 driver-&gt;getTexture(<span class="stringliteral">&quot;../../media/irrlicht2_lf.jpg&quot;</span>),
260 driver-&gt;getTexture(<span class="stringliteral">&quot;../../media/irrlicht2_rt.jpg&quot;</span>),
261 driver-&gt;getTexture(<span class="stringliteral">&quot;../../media/irrlicht2_ft.jpg&quot;</span>),
262 driver-&gt;getTexture(<span class="stringliteral">&quot;../../media/irrlicht2_bk.jpg&quot;</span>));
263
264 <span class="comment">// show and execute dialog</span>
265
266 ShowWindow(hWnd , SW_SHOW);
267 UpdateWindow(hWnd);
268
269 <span class="comment">// do message queue</span>
270</pre></div><p>Now the only thing missing is the drawing loop using IrrlichtDevice::run(). We do this as usual. But instead of this, there is another possibility: You can also simply use your own message loop using GetMessage, DispatchMessage and whatever. Calling Device-&gt;run() will cause Irrlicht to dispatch messages internally too. You need not call Device-&gt;run() if you want to do your own message dispatching loop, but Irrlicht will not be able to fetch user input then and you have to do it on your own using the window messages, DirectInput, or whatever. </p>
271<div class="fragment"><pre class="fragment"> <span class="keywordflow">while</span> (device-&gt;<a class="code" href="classirr_1_1_irrlicht_device.html#a0489f8151dc43f6f41503ffb5a160b35" title="Runs the device.">run</a>())
272 {
273 driver-&gt;beginScene(<span class="keyword">true</span>, <span class="keyword">true</span>, 0, videodata);
274 smgr-&gt;<a class="code" href="classirr_1_1scene_1_1_i_scene_manager.html#a04240262904667c821bd9de5e5fd9b02" title="Draws all the scene nodes.">drawAll</a>();
275 driver-&gt;endScene();
276 }
277</pre></div><p>The alternative, own message dispatching loop without Device-&gt;run() would look like this: </p>
278<div class="fragment"><pre class="fragment"></pre></div><p> MSG msg; while (true) { if (PeekMessage(&amp;msg, NULL, 0, 0, PM_REMOVE)) { TranslateMessage(&amp;msg); DispatchMessage(&amp;msg);</p>
279<p>if (msg.message == WM_QUIT) break; }</p>
280<p>advance virtual time device-&gt;getTimer()-&gt;tick();</p>
281<p>draw engine picture driver-&gt;beginScene(true, true, 0, (key=='c')?hIrrlichtWindow:0); smgr-&gt;drawAll(); driver-&gt;endScene(); } </p>
282<div class="fragment"><pre class="fragment"> device-&gt;<a class="code" href="classirr_1_1_irrlicht_device.html#a08c97937e0f60f98d443b397a7c60e18" title="Notifies the device that it should close itself.">closeDevice</a>();
283 device-&gt;<a class="code" href="classirr_1_1_i_reference_counted.html#afb169a857e0d2cdb96b8821cb9bff17a" title="Drops the object. Decrements the reference counter by one.">drop</a>();
284
285 <span class="keywordflow">return</span> 0;
286}
287<span class="preprocessor">#endif // if windows</span>
288</pre></div><p>That's it, Irrlicht now runs in your own windows window. </p>
289</div></div>
290</div>
291 <div id="nav-path" class="navpath">
292 <ul>
293<!-- window showing the filter options -->
294<div id="MSearchSelectWindow"
295 onmouseover="return searchBox.OnSearchSelectShow()"
296 onmouseout="return searchBox.OnSearchSelectHide()"
297 onkeydown="return searchBox.OnSearchSelectKey(event)">
298<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>
299
300<!-- iframe showing the search results (closed by default) -->
301<div id="MSearchResultsWindow">
302<iframe src="javascript:void(0)" frameborder="0"
303 name="MSearchResults" id="MSearchResults">
304</iframe>
305</div>
306
307
308 <li class="footer">
309<a href="http://irrlicht.sourceforge.net" target="_blank">Irrlicht
310Engine</a> Documentation &copy; 2003-2012 by Nikolaus Gebhardt. Generated on Tue Nov 6 2012 11:06:01 for Irrlicht 3D Engine by
311<a href="http://www.doxygen.org/index.html" target="_blank">Doxygen</a> 1.7.5.1 </li>
312 </ul>
313 </div>
314
315
316</body>
317</html>