diff options
Diffstat (limited to 'libraries/irrlicht-1.8/examples/13.RenderToTexture/tutorial.html')
-rw-r--r-- | libraries/irrlicht-1.8/examples/13.RenderToTexture/tutorial.html | 488 |
1 files changed, 244 insertions, 244 deletions
diff --git a/libraries/irrlicht-1.8/examples/13.RenderToTexture/tutorial.html b/libraries/irrlicht-1.8/examples/13.RenderToTexture/tutorial.html index 26340a3..051a251 100644 --- a/libraries/irrlicht-1.8/examples/13.RenderToTexture/tutorial.html +++ b/libraries/irrlicht-1.8/examples/13.RenderToTexture/tutorial.html | |||
@@ -1,244 +1,244 @@ | |||
1 | <html> | 1 | <html> |
2 | <head> | 2 | <head> |
3 | <title>Irrlicht Engine Tutorial</title> | 3 | <title>Irrlicht Engine Tutorial</title> |
4 | <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> | 4 | <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> |
5 | </head> | 5 | </head> |
6 | 6 | ||
7 | <body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"> | 7 | <body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"> |
8 | <br> | 8 | <br> |
9 | <table width="95%" border="0" cellspacing="0" cellpadding="2" align="center"> | 9 | <table width="95%" border="0" cellspacing="0" cellpadding="2" align="center"> |
10 | <tr> | 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> | 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%"> | 12 | <td bgcolor="#666699" width="100%"> |
13 | <div align="center"> | 13 | <div align="center"> |
14 | <div align="left"><b><font color="#FFFFFF">Tutorial 13. Render to Texture</font></b></div> | 14 | <div align="left"><b><font color="#FFFFFF">Tutorial 13. Render to Texture</font></b></div> |
15 | </div> | 15 | </div> |
16 | </td> | 16 | </td> |
17 | </tr> | 17 | </tr> |
18 | <tr bgcolor="#eeeeff"> | 18 | <tr bgcolor="#eeeeff"> |
19 | <td height="90" colspan="2"> | 19 | <td height="90" colspan="2"> |
20 | <div align="left"> | 20 | <div align="left"> |
21 | <p> This tutorial shows how to render to a texture using Irrlicht. Render | 21 | <p> This tutorial shows how to render to a texture using Irrlicht. Render |
22 | to texture is a feature with which it is possible to create nice special | 22 | to texture is a feature with which it is possible to create nice special |
23 | effects. In addition, this tutorial shows how to enable specular highlights.</p> | 23 | effects. In addition, this tutorial shows how to enable specular highlights.</p> |
24 | <p>The program which is described here will look like this:</p> | 24 | <p>The program which is described here will look like this:</p> |
25 | <p align="center"><img src="../../media/013shot.jpg" width="256" height="200"><br> | 25 | <p align="center"><img src="../../media/013shot.jpg" width="256" height="200"><br> |
26 | </p> | 26 | </p> |
27 | </div> | 27 | </div> |
28 | </td> | 28 | </td> |
29 | </tr> | 29 | </tr> |
30 | </table> | 30 | </table> |
31 | <br> | 31 | <br> |
32 | <table width="95%" border="0" cellspacing="0" cellpadding="2" align="center"> | 32 | <table width="95%" border="0" cellspacing="0" cellpadding="2" align="center"> |
33 | <tr> | 33 | <tr> |
34 | <td bgcolor="#666699"> <b><font color="#FFFFFF">Lets start!</font></b></td> | 34 | <td bgcolor="#666699"> <b><font color="#FFFFFF">Lets start!</font></b></td> |
35 | </tr> | 35 | </tr> |
36 | <tr> | 36 | <tr> |
37 | <td height="90" bgcolor="#eeeeff" valign="top"> <div align="left"> | 37 | <td height="90" bgcolor="#eeeeff" valign="top"> <div align="left"> |
38 | <div align="left"> | 38 | <div align="left"> |
39 | <p>In the beginning, everything as usual. Include the needed headers, | 39 | <p>In the beginning, everything as usual. Include the needed headers, |
40 | ask the user for the rendering driver, create the Irrlicht Device:</p> | 40 | ask the user for the rendering driver, create the Irrlicht Device:</p> |
41 | <table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center"> | 41 | <table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center"> |
42 | <tr> | 42 | <tr> |
43 | <td><pre>#include <irrlicht.h> | 43 | <td><pre>#include <irrlicht.h> |
44 | #include <iostream> | 44 | #include <iostream> |
45 | 45 | ||
46 | using namespace irr; | 46 | using namespace irr; |
47 | 47 | ||
48 | #pragma comment(lib, "Irrlicht.lib") | 48 | #pragma comment(lib, "Irrlicht.lib") |
49 | 49 | ||
50 | int main() | 50 | int main() |
51 | { | 51 | { |
52 | // let user select driver type | 52 | // let user select driver type |
53 | 53 | ||
54 | video::E_DRIVER_TYPE driverType = video::EDT_DIRECT3D9; | 54 | video::E_DRIVER_TYPE driverType = video::EDT_DIRECT3D9; |
55 | 55 | ||
56 | printf("Please select the driver you want for this example:\n"\<br> " (a) Direct3D 9.0c\n (b) Direct3D 8.1\n (c) OpenGL 1.5\n"\<br> " (d) Software Renderer\n (e) Apfelbaum Software Renderer\n"\<br> " (f) NullDevice\n (otherKey) exit\n\n"); | 56 | printf("Please select the driver you want for this example:\n"\<br> " (a) Direct3D 9.0c\n (b) Direct3D 8.1\n (c) OpenGL 1.5\n"\<br> " (d) Software Renderer\n (e) Apfelbaum Software Renderer\n"\<br> " (f) NullDevice\n (otherKey) exit\n\n"); |
57 | 57 | ||
58 | char i; | 58 | char i; |
59 | std::cin >> i; | 59 | std::cin >> i; |
60 | 60 | ||
61 | 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 1;<br> } | 61 | 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 1;<br> } |
62 | 62 | ||
63 | // create device and exit if creation failed | 63 | // create device and exit if creation failed |
64 | 64 | ||
65 | IrrlichtDevice *device = | 65 | IrrlichtDevice *device = |
66 | createDevice(driverType, core::dimension2d<s32>(640, 480), | 66 | createDevice(driverType, core::dimension2d<s32>(640, 480), |
67 | 16, false, false); | 67 | 16, false, false); |
68 | 68 | ||
69 | if (device == 0) | 69 | if (device == 0) |
70 | return 1; // could not create selected driver. | 70 | return 1; // could not create selected driver. |
71 | 71 | ||
72 | video::IVideoDriver* driver = device->getVideoDriver(); | 72 | video::IVideoDriver* driver = device->getVideoDriver(); |
73 | scene::ISceneManager* smgr = device->getSceneManager(); | 73 | scene::ISceneManager* smgr = device->getSceneManager(); |
74 | gui::IGUIEnvironment* env = device->getGUIEnvironment();</pre></td> | 74 | gui::IGUIEnvironment* env = device->getGUIEnvironment();</pre></td> |
75 | </tr> | 75 | </tr> |
76 | </table> | 76 | </table> |
77 | <p>Now, we load an animated mesh to be displayed. As in most examples, | 77 | <p>Now, we load an animated mesh to be displayed. As in most examples, |
78 | we'll take the fairy md2 model. The difference here: We set the shininess<br> | 78 | we'll take the fairy md2 model. The difference here: We set the shininess<br> |
79 | of the model to a value other than 0 which is the default value. This | 79 | of the model to a value other than 0 which is the default value. This |
80 | enables specular highlights on the model if dynamic lighting is on. | 80 | enables specular highlights on the model if dynamic lighting is on. |
81 | The value influences the size of the highlights.</p> | 81 | The value influences the size of the highlights.</p> |
82 | <table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center"> | 82 | <table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center"> |
83 | <tr> | 83 | <tr> |
84 | <td><pre>// load and display animated fairy mesh | 84 | <td><pre>// load and display animated fairy mesh |
85 | 85 | ||
86 | scene::IAnimatedMeshSceneNode* fairy = smgr->addAnimatedMeshSceneNode( | 86 | scene::IAnimatedMeshSceneNode* fairy = smgr->addAnimatedMeshSceneNode( |
87 | smgr->getMesh("../../media/faerie.md2")); | 87 | smgr->getMesh("../../media/faerie.md2")); |
88 | 88 | ||
89 | if (fairy) | 89 | if (fairy) |
90 | { | 90 | { |
91 | fairy->setMaterialTexture(0, driver->getTexture("../../media/faerie2.bmp")); // set diffuse texture | 91 | fairy->setMaterialTexture(0, driver->getTexture("../../media/faerie2.bmp")); // set diffuse texture |
92 | fairy->setMaterialFlag(video::EMF_LIGHTING, true); // enable dynamic lighting | 92 | fairy->setMaterialFlag(video::EMF_LIGHTING, true); // enable dynamic lighting |
93 | fairy->getMaterial(0).Shininess = 20.0f; // set size of specular highlights | 93 | fairy->getMaterial(0).Shininess = 20.0f; // set size of specular highlights |
94 | fairy->setPosition(core::vector3df(-10,0,-100)); | 94 | fairy->setPosition(core::vector3df(-10,0,-100)); |
95 | }</pre></td> | 95 | }</pre></td> |
96 | </tr> | 96 | </tr> |
97 | </table> | 97 | </table> |
98 | <p> To make specular highlights appear on the model, we need a dynamic | 98 | <p> To make specular highlights appear on the model, we need a dynamic |
99 | light in the scene. We add one directly in vicinity of the model. | 99 | light in the scene. We add one directly in vicinity of the model. |
100 | In addition, to make the model not that dark, we set the ambient light | 100 | In addition, to make the model not that dark, we set the ambient light |
101 | to gray. </p> | 101 | to gray. </p> |
102 | <table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center"> | 102 | <table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center"> |
103 | <tr> | 103 | <tr> |
104 | <td><pre> | 104 | <td><pre> |
105 | // add white light | 105 | // add white light |
106 | scene::ILightSceneNode* light = smgr->addLightSceneNode(0, | 106 | scene::ILightSceneNode* light = smgr->addLightSceneNode(0, |
107 | core::vector3df(-15,5,-105), video::SColorf(1.0f, 1.0f, 1.0f)); | 107 | core::vector3df(-15,5,-105), video::SColorf(1.0f, 1.0f, 1.0f)); |
108 | 108 | ||
109 | // set ambient light | 109 | // set ambient light |
110 | driver->setAmbientLight(video::SColor(0,60,60,60));</pre></td> | 110 | driver->setAmbientLight(video::SColor(0,60,60,60));</pre></td> |
111 | </tr> | 111 | </tr> |
112 | </table> | 112 | </table> |
113 | <p>The next is just some standard stuff: Add a user controlled camera | 113 | <p>The next is just some standard stuff: Add a user controlled camera |
114 | to the scene, disable mouse cursor, and add a test cube and let it | 114 | to the scene, disable mouse cursor, and add a test cube and let it |
115 | rotate to make the scene more interesting.</p> | 115 | rotate to make the scene more interesting.</p> |
116 | <table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center"> | 116 | <table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center"> |
117 | <tr> | 117 | <tr> |
118 | <td><pre> | 118 | <td><pre> |
119 | // add fps camera | 119 | // add fps camera |
120 | scene::ICameraSceneNode* fpsCamera = smgr->addCameraSceneNodeFPS(); | 120 | scene::ICameraSceneNode* fpsCamera = smgr->addCameraSceneNodeFPS(); |
121 | fpsCamera->setPosition(core::vector3df(-50,50,-150)); | 121 | fpsCamera->setPosition(core::vector3df(-50,50,-150)); |
122 | 122 | ||
123 | // disable mouse cursor | 123 | // disable mouse cursor |
124 | device->getCursorControl()->setVisible(false); | 124 | device->getCursorControl()->setVisible(false); |
125 | 125 | ||
126 | // create test cube | 126 | // create test cube |
127 | scene::ISceneNode* test = smgr->addCubeSceneNode(60); | 127 | scene::ISceneNode* test = smgr->addCubeSceneNode(60); |
128 | 128 | ||
129 | // let the cube rotate and set some light settings | 129 | // let the cube rotate and set some light settings |
130 | scene::ISceneNodeAnimator* anim = smgr->createRotationAnimator( | 130 | scene::ISceneNodeAnimator* anim = smgr->createRotationAnimator( |
131 | core::vector3df(0.3f, 0.3f,0)); | 131 | core::vector3df(0.3f, 0.3f,0)); |
132 | 132 | ||
133 | test->setPosition(core::vector3df(-100,0,-100)); | 133 | test->setPosition(core::vector3df(-100,0,-100)); |
134 | test->setMaterialFlag(video::EMF_LIGHTING, false); // disable dynamic lighting | 134 | test->setMaterialFlag(video::EMF_LIGHTING, false); // disable dynamic lighting |
135 | test->addAnimator(anim); | 135 | test->addAnimator(anim); |
136 | anim->drop(); | 136 | anim->drop(); |
137 | 137 | ||
138 | // set window caption | 138 | // set window caption |
139 | device->setWindowCaption(L"Irrlicht Engine - Render to Texture and Specular Highlights example");</pre></td> | 139 | device->setWindowCaption(L"Irrlicht Engine - Render to Texture and Specular Highlights example");</pre></td> |
140 | </tr> | 140 | </tr> |
141 | </table> | 141 | </table> |
142 | <p> To test out the render to texture feature, we need a render target | 142 | <p> To test out the render to texture feature, we need a render target |
143 | texture. These are not like standard textures, but need to be created | 143 | texture. These are not like standard textures, but need to be created |
144 | first. To create one, we call IVideoDriver::createRenderTargetTexture() | 144 | first. To create one, we call IVideoDriver::createRenderTargetTexture() |
145 | and specify the size of the texture. Please don't use sizes bigger | 145 | and specify the size of the texture. Please don't use sizes bigger |
146 | than the frame buffer for this, because the render target shares the | 146 | than the frame buffer for this, because the render target shares the |
147 | zbuffer with the frame buffer. And because we want to render the scene | 147 | zbuffer with the frame buffer. And because we want to render the scene |
148 | not from the user camera into the texture, we add another, fixed camera | 148 | not from the user camera into the texture, we add another, fixed camera |
149 | to the scene. But before we do all this, we check if the current running | 149 | to the scene. But before we do all this, we check if the current running |
150 | driver is able to render to textures. If it is not, we simply display | 150 | driver is able to render to textures. If it is not, we simply display |
151 | a warning text.</p> | 151 | a warning text.</p> |
152 | <table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center"> | 152 | <table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center"> |
153 | <tr> | 153 | <tr> |
154 | <td><pre>// create render target | 154 | <td><pre>// create render target |
155 | video::ITexture* rt = 0; | 155 | video::ITexture* rt = 0; |
156 | scene::ICameraSceneNode* fixedCam = 0; | 156 | scene::ICameraSceneNode* fixedCam = 0; |
157 | 157 | ||
158 | 158 | ||
159 | if (driver->queryFeature(video::EVDF_RENDER_TO_TARGET)) | 159 | if (driver->queryFeature(video::EVDF_RENDER_TO_TARGET)) |
160 | { | 160 | { |
161 | rt = driver->createRenderTargetTexture(core::dimension2d<s32>(256,256)); | 161 | rt = driver->createRenderTargetTexture(core::dimension2d<s32>(256,256)); |
162 | test->setMaterialTexture(0, rt); // set material of cube to render target | 162 | test->setMaterialTexture(0, rt); // set material of cube to render target |
163 | 163 | ||
164 | // add fixed camera | 164 | // add fixed camera |
165 | fixedCam = smgr->addCameraSceneNode(0, core::vector3df(10,10,-80), | 165 | fixedCam = smgr->addCameraSceneNode(0, core::vector3df(10,10,-80), |
166 | core::vector3df(-10,10,-100)); | 166 | core::vector3df(-10,10,-100)); |
167 | } | 167 | } |
168 | else | 168 | else |
169 | { | 169 | { |
170 | // create problem text | 170 | // create problem text |
171 | gui::IGUISkin* skin = env->getSkin(); | 171 | gui::IGUISkin* skin = env->getSkin(); |
172 | gui::IGUIFont* font = env->getFont("../../media/fonthaettenschweiler.bmp"); | 172 | gui::IGUIFont* font = env->getFont("../../media/fonthaettenschweiler.bmp"); |
173 | if (font) | 173 | if (font) |
174 | skin->setFont(font); | 174 | skin->setFont(font); |
175 | 175 | ||
176 | gui::IGUIStaticText* text = env->addStaticText( | 176 | gui::IGUIStaticText* text = env->addStaticText( |
177 | L"Your hardware or this renderer is not able to use the "\ | 177 | L"Your hardware or this renderer is not able to use the "\ |
178 | L"render to texture feature. RTT Disabled.", | 178 | L"render to texture feature. RTT Disabled.", |
179 | core::rect<s32>(150,20,470,60)); | 179 | core::rect<s32>(150,20,470,60)); |
180 | 180 | ||
181 | text->setOverrideColor(video::SColor(100,255,255,255)); | 181 | text->setOverrideColor(video::SColor(100,255,255,255)); |
182 | }</pre></td> | 182 | }</pre></td> |
183 | </tr> | 183 | </tr> |
184 | </table> | 184 | </table> |
185 | <p> Nearly finished. Now we need to draw everything. Every frame, we | 185 | <p> Nearly finished. Now we need to draw everything. Every frame, we |
186 | draw the scene twice. Once from the fixed camera into the render target | 186 | draw the scene twice. Once from the fixed camera into the render target |
187 | texture and once as usual. When rendering into the render target, | 187 | texture and once as usual. When rendering into the render target, |
188 | we need to disable the visibilty of the test cube, because it has | 188 | we need to disable the visibilty of the test cube, because it has |
189 | the render target texture applied to it.<br> | 189 | the render target texture applied to it.<br> |
190 | That's, wasn't quite complicated I hope. :)</p> | 190 | That's, wasn't quite complicated I hope. :)</p> |
191 | <table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center"> | 191 | <table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center"> |
192 | <tr> | 192 | <tr> |
193 | <td><pre>while(device->run()) | 193 | <td><pre>while(device->run()) |
194 | if (device->isWindowActive()) | 194 | if (device->isWindowActive()) |
195 | { | 195 | { |
196 | driver->beginScene(true, true, 0); | 196 | driver->beginScene(true, true, 0); |
197 | 197 | ||
198 | if (rt) | 198 | if (rt) |
199 | { | 199 | { |
200 | // draw scene into render target | 200 | // draw scene into render target |
201 | 201 | ||
202 | // set render target texture | 202 | // set render target texture |
203 | driver->setRenderTarget(rt, true, true, video::SColor(0,0,0,255)); | 203 | driver->setRenderTarget(rt, true, true, video::SColor(0,0,0,255)); |
204 | 204 | ||
205 | // make cube invisible and set fixed camera as active camera | 205 | // make cube invisible and set fixed camera as active camera |
206 | test->setVisible(false); | 206 | test->setVisible(false); |
207 | smgr->setActiveCamera(fixedCam); | 207 | smgr->setActiveCamera(fixedCam); |
208 | 208 | ||
209 | // draw whole scene into render buffer | 209 | // draw whole scene into render buffer |
210 | smgr->drawAll(); | 210 | smgr->drawAll(); |
211 | 211 | ||
212 | // set back old render target | 212 | // set back old render target |
213 | driver->setRenderTarget(0); | 213 | driver->setRenderTarget(0); |
214 | 214 | ||
215 | // make the cube visible and set the user controlled camera as active one | 215 | // make the cube visible and set the user controlled camera as active one |
216 | test->setVisible(true); | 216 | test->setVisible(true); |
217 | smgr->setActiveCamera(fpsCamera); | 217 | smgr->setActiveCamera(fpsCamera); |
218 | } | 218 | } |
219 | 219 | ||
220 | // draw scene normally | 220 | // draw scene normally |
221 | smgr->drawAll(); | 221 | smgr->drawAll(); |
222 | env->drawAll(); | 222 | env->drawAll(); |
223 | 223 | ||
224 | driver->endScene(); | 224 | driver->endScene(); |
225 | } | 225 | } |
226 | 226 | ||
227 | if (rt) | 227 | if (rt) |
228 | rt->drop(); // drop render target because we created if with a create() method | 228 | rt->drop(); // drop render target because we created if with a create() method |
229 | 229 | ||
230 | device->drop(); // drop device | 230 | device->drop(); // drop device |
231 | return 0; | 231 | return 0; |
232 | } | 232 | } |
233 | </pre></td> | 233 | </pre></td> |
234 | </tr> | 234 | </tr> |
235 | </table> | 235 | </table> |
236 | 236 | ||
237 | <p> </p></div> | 237 | <p> </p></div> |
238 | </div> | 238 | </div> |
239 | </td> | 239 | </td> |
240 | </tr> | 240 | </tr> |
241 | </table> | 241 | </table> |
242 | <p> </p> | 242 | <p> </p> |
243 | </body> | 243 | </body> |
244 | </html> | 244 | </html> |