aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/others/irrlicht-1.8.1/examples/06.2DGraphics/tutorial.html
diff options
context:
space:
mode:
Diffstat (limited to 'src/others/irrlicht-1.8.1/examples/06.2DGraphics/tutorial.html')
-rw-r--r--src/others/irrlicht-1.8.1/examples/06.2DGraphics/tutorial.html163
1 files changed, 163 insertions, 0 deletions
diff --git a/src/others/irrlicht-1.8.1/examples/06.2DGraphics/tutorial.html b/src/others/irrlicht-1.8.1/examples/06.2DGraphics/tutorial.html
new file mode 100644
index 0000000..ea6291a
--- /dev/null
+++ b/src/others/irrlicht-1.8.1/examples/06.2DGraphics/tutorial.html
@@ -0,0 +1,163 @@
1<html>
2<head>
3<title>Irrlicht Engine Tutorial</title>
4<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
5</head>
6
7<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
8<br>
9<table width="95%" border="0" cellspacing="0" cellpadding="2" align="center">
10 <tr>
11 <td bgcolor="#666699" width="10"><b><a href="http://irrlicht.sourceforge.net" target="_blank"><img src="../../media/irrlichtlogo.jpg" width="88" height="31" border="0"></a></b></td>
12 <td bgcolor="#666699" width="100%">
13<div align="center">
14<div align="center"></div>
15 <div align="left"><b><font color="#FFFFFF">Tutorial 6. 2D Graphics</font></b></div>
16 </div>
17 </td>
18 </tr>
19 <tr bgcolor="#eeeeff">
20 <td height="90" colspan="2">
21 <div align="left">
22 <p>This Tutorial shows how to do 2d graphics with the Irrlicht Engine.
23 It shows how to draw images, keycolor based sprites, transparent rectangles
24 and different fonts. You will may consider this useful if you want to
25 make a 2d game with the engine, or if you want to draw a cool interface
26 or head up display for your 3d game.</p>
27 <p>The program which is described here will look like this:</p>
28 <p align="center"><img src="../../media/006shot.jpg" width="259" height="204"><br>
29 </p>
30 </div>
31 </td>
32 </tr>
33</table>
34<br>
35<table width="95%" border="0" cellspacing="0" cellpadding="2" align="center">
36 <tr>
37 <td bgcolor="#666699"> <div align="center"><b><font color="#FFFFFF"></font></b></div>
38 <b><font color="#FFFFFF">Lets start!</font></b></td>
39 </tr>
40 <tr>
41 <td height="90" bgcolor="#eeeeff" valign="top"> <div align="left">
42 <p>As always, I include the header files, use the irr namespace, and tell
43 the linker to link with the .lib file. </p>
44 <table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center">
45 <tr>
46 <td> <pre>#include &lt;irrlicht.h&gt;<br>#include &lt;iostream&gt;<br><br>using namespace irr;</pre>
47 <pre>#pragma comment(lib, &quot;Irrlicht.lib&quot;)
48 </pre></td>
49 </tr>
50 </table>
51 <p>At first, we let the user select the driver type, then start up the
52 engine, set a caption, and get a pointer to the video driver.</p>
53 <table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center">
54 <tr>
55 <td> <pre>int main()<br>{<br> // let user select driver type<br> video::E_DRIVER_TYPE driverType;<br><br> printf(&quot;Please select the driver you want for this example:\n&quot;\<br> &quot; (a) Direct3D 9.0c\n (b) Direct3D 8.1\n (c) OpenGL 1.5\n&quot;\<br> &quot; (d) Software Renderer\n (e) Apfelbaum Software Renderer\n&quot;\<br> &quot; (f) NullDevice\n (otherKey) exit\n\n&quot;);<br><br> char i;<br> std::cin &gt;&gt; i;<br><br> switch(i)<br> {<br> case 'a': driverType = video::EDT_DIRECT3D9;break;<br> case 'b': driverType = video::EDT_DIRECT3D8;break;<br> case 'c': driverType = video::EDT_OPENGL; break;<br> case 'd': driverType = video::EDT_SOFTWARE; break;<br> case 'e': driverType = video::EDT_BURNINGSVIDEO;break;<br> case 'f': driverType = video::EDT_NULL; break;<br> default: return 0;<br> } <br><br> // create device</pre>
56 <pre> IrrlichtDevice *device = createDevice(driverType,
57 core::dimension2d&lt;s32&gt;(512, 384));</pre>
58 <pre> if (device == 0)
59 return 1;
60 <br> device-&gt;setWindowCaption(L&quot;Irrlicht Engine - 2D Graphics Demo&quot;);</pre>
61 <pre> video::IVideoDriver* driver = device-&gt;getVideoDriver();</pre></td>
62 </tr>
63 </table>
64 <p> All 2d graphics in this example are put together into one texture,
65 2ddemo.bmp. Because we want to draw colorkey based sprites, we need
66 to load this texture and tell the engine, which part of it should be
67 transparent based on a colorkey. In this example, we don't tell it the
68 color directly, we just say &quot;Hey Irrlicht Engine, you'll find the
69 color I want at position (0,0) on the texture.&quot;. Instead, it would
70 be also possible to call <font face="Courier New, Courier, mono">driver-&gt;makeColorKeyTexture(images,
71 video::SColor(0,0,0,0))</font>, to make e.g. all black pixels transparent.
72 Please note, that makeColorKeyTexture just creates an alpha channel
73 based on the color. </p>
74 <table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center">
75 <tr>
76 <td> <pre>video::ITexture* images = driver-&gt;getTexture(&quot;../../media/2ddemo.bmp&quot;);<br>driver-&gt;makeColorKeyTexture(images, core::position2d&lt;s32&gt;(0,0));</pre></td>
77 </tr>
78 </table>
79 <p>To be able to draw some text with two different fonts, we load them.
80 Ok, we load just one, as first font we just use the default font which
81 is built into the engine.<br>
82 Also, we define two rectangles, which specify the position of the images
83 of the red imps (little flying creatures) in the texture.</p>
84 <table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center">
85 <tr>
86 <td> <pre>gui::IGUIFont* font = device-&gt;getGUIEnvironment()-&gt;getBuiltInFont();<br>gui::IGUIFont* font2 = device-&gt;getGUIEnvironment()-&gt;getFont(
87 &quot;../../media/fonthaettenschweiler.bmp&quot;);</pre>
88 <pre>core::rect&lt;s32&gt; imp1(349,15,385,78);
89core::rect&lt;s32&gt; imp2(387,15,423,78);</pre></td>
90 </tr>
91 </table>
92 <p>Everything is prepared, now we can draw everything in the draw loop,
93 between the begin scene and end scene calls. In this example, we are
94 just doing 2d graphics, but it would be no problem to mix them with
95 3d graphics. Just try it out, and draw some 3d vertices or set up a
96 scene with the scene manager and draw it.</p>
97 </div>
98 <table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center">
99 <tr>
100 <td> <pre>while(device-&gt;run() &amp;&amp; driver)<br>{<br> if (device-&gt;isWindowActive())<br> {<br> u32 time = device-&gt;getTimer()-&gt;getTime();<br> driver-&gt;beginScene(true, true, video::SColor(0,120,102,136));
101</pre></td>
102 </tr>
103 </table>
104 <p> First, we draw 3 sprites, using the alpha channel we created with makeColorKeyTexture.
105 The last parameter specifiys that the drawing method should use thiw alpha
106 channel. The parameter before the last one specifies a color, with wich
107 the sprite should be colored. (255,255,255,255) is full white, so the
108 sprite will look like the original. The third sprite is drawed colored
109 based on the time. </p>
110 <table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center">
111 <tr>
112 <td><pre>// draw fire &amp; dragons background world<br>driver-&gt;draw2DImage(images, core::position2d&lt;s32&gt;(50,50),<br> core::rect&lt;s32&gt;(0,0,342,224), 0, <br> video::SColor(255,255,255,255), true);</pre>
113 <pre>// draw flying imp
114driver-&gt;draw2DImage(images, core::position2d&lt;s32&gt;(164,125),
115 (time/500 % 2) ? imp1 : imp2, 0,
116 video::SColor(255,255,255,255), true);</pre>
117 <pre>// draw second flying imp with colorcylce
118driver-&gt;draw2DImage(images, core::position2d&lt;s32&gt;(270,105),
119 (time/500 % 2) ? imp1 : imp2, 0,
120 video::SColor(255,(time) % 255,255,255), true);</pre></td>
121 </tr>
122 </table>
123 <p> Drawing text is really simple. The code should be self explanatory.</p>
124 <table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center">
125 <tr>
126 <td><pre>// draw some text<br>if (font)<br> font-&gt;draw(L&quot;This is some text.&quot;,<br> core::rect&lt;s32&gt;(130,10,300,50),<br> video::SColor(255,255,255,255));</pre>
127 <pre>// draw some other text
128if (font2)
129 font2-&gt;draw(L&quot;This is some other text.&quot;,
130 core::rect&lt;s32&gt;(130,20,300,60),
131 video::SColor(255,time % 255,time % 255,255));</pre></td>
132 </tr>
133 </table>
134 <p>At last, we draw the Irrlicht Engine logo (without using a color or an
135 alpha channel) and a transparent 2d Rectangle at the position of the mouse
136 cursor.</p>
137 <table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center">
138 <tr>
139 <td> <pre> // draw logo<br> driver-&gt;draw2DImage(images, core::position2d&lt;s32&gt;(10,10),<br> core::rect&lt;s32&gt;(354,87,442,118));</pre>
140 <pre> // draw transparent rect under cursor
141 core::position2d&lt;s32&gt; m = device-&gt;getCursorControl()-&gt;getPosition();
142 driver-&gt;draw2DRectangle(video::SColor(100,255,255,255),
143 core::rect&lt;s32&gt;(m.X-20, m.Y-20, m.X+20, m.Y+20));</pre>
144 <pre> driver-&gt;endScene();
145 }
146}</pre></td>
147 </tr>
148 </table>
149 <p>That's all, it was not really difficult, I hope.</p>
150 <table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center">
151 <tr>
152 <td> <pre> device-&gt;drop();
153 return 0;
154}</pre>
155 </td>
156 </tr>
157 </table>
158 <p>&nbsp;</p></td>
159 </tr>
160</table>
161<p>&nbsp;</p>
162 </body>
163</html>