diff options
author | David Walter Seikel | 2013-01-13 17:24:39 +1000 |
---|---|---|
committer | David Walter Seikel | 2013-01-13 17:24:39 +1000 |
commit | 393b5cd1dc438872af89d334ef6e5fcc59f27d47 (patch) | |
tree | 6a14521219942a08a1b95cb2f5a923a9edd60f63 /libraries/irrlicht-1.8/examples/09.Meshviewer/tutorial.html | |
parent | Add a note about rasters suggested start up code. (diff) | |
download | SledjHamr-393b5cd1dc438872af89d334ef6e5fcc59f27d47.zip SledjHamr-393b5cd1dc438872af89d334ef6e5fcc59f27d47.tar.gz SledjHamr-393b5cd1dc438872af89d334ef6e5fcc59f27d47.tar.bz2 SledjHamr-393b5cd1dc438872af89d334ef6e5fcc59f27d47.tar.xz |
Added Irrlicht 1.8, but without all the Windows binaries.
Diffstat (limited to 'libraries/irrlicht-1.8/examples/09.Meshviewer/tutorial.html')
-rw-r--r-- | libraries/irrlicht-1.8/examples/09.Meshviewer/tutorial.html | 182 |
1 files changed, 182 insertions, 0 deletions
diff --git a/libraries/irrlicht-1.8/examples/09.Meshviewer/tutorial.html b/libraries/irrlicht-1.8/examples/09.Meshviewer/tutorial.html new file mode 100644 index 0000000..d296b6c --- /dev/null +++ b/libraries/irrlicht-1.8/examples/09.Meshviewer/tutorial.html | |||
@@ -0,0 +1,182 @@ | |||
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="left"><b><font color="#FFFFFF">Tutorial 9. Mesh Viewer</font></b></div> | ||
15 | </div> | ||
16 | </td> | ||
17 | </tr> | ||
18 | <tr bgcolor="#eeeeff"> | ||
19 | <td height="90" colspan="2"> | ||
20 | <div align="left"> | ||
21 | <p> This tutorial shows how to create a more complex application with | ||
22 | the engine. We construct a simple mesh viewer using the user interface | ||
23 | API and the scenemanagement of Irrlicht.<br> | ||
24 | The tutorial shows how to create and use Buttons, Windows, Toolbars, | ||
25 | Menus, ComboBoxes, Tabcontrols, Editboxes, Images, MessageBoxes, SkyBoxes, | ||
26 | and how to parse XML files with the integrated XML reader of the engine.</p> | ||
27 | <p>The program which is described here will look like this:</p> | ||
28 | <p align="center"><img src="../../media/009shot.jpg" width="260" height="203"><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"> <b><font color="#FFFFFF">Lets start!</font></b></td> | ||
38 | </tr> | ||
39 | <tr> | ||
40 | <td height="90" bgcolor="#eeeeff" valign="top"> <div align="left"> | ||
41 | <div align="left"> | ||
42 | <p>We start like in most other tutorials: Include all nesessary header | ||
43 | files, add a comment to let the engine be linked with the right .lib | ||
44 | file in Visual Studio, and deklare some global variables. We also | ||
45 | add two 'using namespece' statements, so we do not need to write the | ||
46 | whole names of all classes. In this tutorial, we use a lot stuff from | ||
47 | the gui namespace.</p> | ||
48 | <table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center"> | ||
49 | <tr> | ||
50 | <td> <pre>#include <irrlicht.h><br>#include <iostream><br><br>using namespace irr;<br>using namespace gui;<br><br>#pragma comment(lib, "Irrlicht.lib")<br><br>IrrlichtDevice *Device = 0;<br>core::stringc StartUpModelFile;<br>core::stringw MessageText;<br>core::stringw Caption;<br>scene::IAnimatedMeshSceneNode* Model = 0;<br>scene::ISceneNode* SkyBox = 0;<br></pre></td> | ||
51 | </tr> | ||
52 | </table> | ||
53 | <p> The three following functions do several stuff used by the mesh | ||
54 | viewer. The first function showAboutText() simply displays a messagebox | ||
55 | with a caption and a message text. The texts will be stored in the | ||
56 | MessageText and Caption variables at startup.</p> | ||
57 | <table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center"> | ||
58 | <tr> | ||
59 | <td> <pre>void showAboutText()<br>{<br><font color="#006600"> // create modal message box with the text<br> // loaded from the xml file</font><font color="#00CC00">.</font><br> Device->getGUIEnvironment()->addMessageBox(<br> Caption.c_str(), MessageText.c_str());<br>}</pre></td> | ||
60 | </tr> | ||
61 | </table> | ||
62 | <p> The second function loadModel() loads a model and displays it using | ||
63 | an addAnimatedMeshSceneNode and the scene manager. Nothing difficult. | ||
64 | It also displays a short message box, if the model could not be loaded. | ||
65 | </p> | ||
66 | <table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center"> | ||
67 | <tr> | ||
68 | <td> <pre>void loadModel(const c8* filename)<br>{<br> <font color="#006600">// load a model into the engine</font><br> if (Model)<br> Model->remove();<br> Model = 0;<br><br> scene::IAnimatedMesh* m = Device->getSceneManager()->getMesh(filename);<br> if (!m) <br> {<br> <font color="#006600">// model could not be loaded</font><br> if (StartUpModelFile != filename)<br> Device->getGUIEnvironment()->addMessageBox(<br> Caption.c_str(), L"The model could not be loaded. " \<br> L"Maybe it is not a supported file format.");<br> return;<br> }<br><br><font color="#006600"> // set default material properties</font><br> Model = Device->getSceneManager()->addAnimatedMeshSceneNode(m);<br> Model->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR);<br> Model->setMaterialFlag(video::EMF_LIGHTING, false);<br> Model->setDebugDataVisible(true);<br>}</pre></td> | ||
69 | </tr> | ||
70 | </table> | ||
71 | <p> Finally, the third function creates a toolbox window. In this simple | ||
72 | mesh viewer, this toolbox only contains a tab control with three edit | ||
73 | boxes for changing the scale of the displayed model.</p> | ||
74 | <table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center"> | ||
75 | <tr> | ||
76 | <td> <pre>void createToolBox()<br>{<br> <font color="#006600">// remove tool box if already there</font><br> IGUIEnvironment* env = Device->getGUIEnvironment();<br> IGUIElement* root = env->getRootGUIElement();<br> IGUIElement* e = root->getElementFromId(5000, true);<br> if (e) e->remove();<br><br> <font color="#006600">// create the toolbox window</font><br> IGUIWindow* wnd = env->addWindow(core::rect<s32>(450,25,640,480),<br> false, L"Toolset", 0, 5000);<br><br> <font color="#006600">// create tab control and tabs</font><br> IGUITabControl* tab = env->addTabControl(<br> core::rect<s32>(2,20,640-452,480-7), wnd, true, true);<br> IGUITab* t1 = tab->addTab(L"Scale");<br> IGUITab* t2 = tab->addTab(L"Empty Tab");<br><br> <font color="#006600">// add some edit boxes and a button to tab one</font><br> env->addEditBox(L"1.0", core::rect<s32>(40,50,130,70), true, t1, 901);<br> env->addEditBox(L"1.0", core::rect<s32>(40,80,130,100), true, t1, 902);<br> env->addEditBox(L"1.0", core::rect<s32>(40,110,130,130), true, t1, 903);<br> env->addButton(core::rect<s32>(10,150,100,190), t1, 1101, L"set");<br><br> // bring irrlicht engine logo to front, because it<br> // now may be below the newly created toolbox<br> root->bringToFront(root->getElementFromId(666, true));<br>}</pre></td> | ||
77 | </tr> | ||
78 | </table> | ||
79 | <p> To get all the events sent by the GUI Elements, we need to create | ||
80 | an event receiver. This one is really simple. If an event occurs, | ||
81 | it checks the id of the caller and the event type, and starts an action | ||
82 | based on these values. For example, if a menu item with id 100 was | ||
83 | selected, if opens a file-open-dialog. </p> | ||
84 | </div> | ||
85 | <table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center"> | ||
86 | <tr> | ||
87 | <td> <pre><font size="2">class MyEventReceiver : public IEventReceiver<br>{<br>public:<br> virtual bool OnEvent(const SEvent& event)<br> {<br> if (event.EventType == EET_GUI_EVENT)<br> {<br> s32 id = event.GUIEvent.Caller->getID();<br> IGUIEnvironment* env = Device->getGUIEnvironment();<br> switch(event.GUIEvent.EventType)<br> {<br> case EGET_MENU_ITEM_SELECTED:<br> {<br> <font color="#006600"> // a menu item was clicked</font><br> IGUIContextMenu* menu = (IGUIContextMenu*)event.GUIEvent.Caller;<br> s32 id = menu->getItemCommandId(menu->getSelectedItem());<br> <br> switch(id)<br> {<br> case 100<font color="#006600">: // File -> Open Mode</font>l<br> env->addFileOpenDialog(L"Please select a model file to open");<br> break;<br> case 200<font color="#006600">: // File -> Quit</font><br> Device->closeDevice();<br> break;<br> case 300<font color="#006600">: // View -> Skybox</font><br> SkyBox->setVisible(!SkyBox->isVisible());<br> break;<br> case 400<font color="#006600">: // View -> Debug Informatio</font>n<br> if (Model)<br> Model->setDebugDataVisible(!Model->isDebugDataVisible());<br> break;<br> case 500<font color="#006600">: // Help->About</font><br> showAboutText();<br> break;<br> case 610<font color="#006600">: // View -> Material -> Soli</font>d<br> if (Model)<br> Model->setMaterialType(video::EMT_SOLID);<br> break;<br> case 620<font color="#006600">: // View -> Material -> Transparen</font>t<br> if (Model)<br> Model->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR);<br> break;<br> case 630<font color="#006600">: // View -> Material -> Reflectio</font>n<br> if (Model)<br> Model->setMaterialType(video::EMT_SPHERE_MAP);<br> break;<br> }<br> break;<br> }<br> case EGET_FILE_SELECTED:<br> {<br> <font color="#006600"> // load the model file, selected in the file open dialo</font>g<br> IGUIFileOpenDialog* dialog = <br> (IGUIFileOpenDialog*)event.GUIEvent.Caller;<br> loadModel(core::stringc(dialog->getFilename()).c_str());<br> }<br> case EGET_BUTTON_CLICKED:<br> switch(id)<br> {<br> case 1101:<br> {<br> <font color="#006600"> // set scal</font>e<br> gui::IGUIElement* root = env->getRootGUIElement();<br> core::vector3df scale;<br> core::stringc s;<br> s = root->getElementFromId(901, true)->getText();<br> scale.X = (f32)atof(s.c_str());<br> s = root->getElementFromId(902, true)->getText();<br> scale.Y = (f32)atof(s.c_str());<br> s = root->getElementFromId(903, true)->getText();<br> scale.Z = (f32)atof(s.c_str());<br> if (Model)<br> Model->setScale(scale);<br> }<br> break;<br> case 1102:<br> env->addFileOpenDialog(L"Please select a model file to open");<br> break;<br> case 1103:<br> showAboutText();<br> break;<br> case 1104:<br> createToolBox();<br> break;<br> }<br> break;<br> }<br> }<br> return false;<br> }<br>};</font></pre></td> | ||
88 | </tr> | ||
89 | </table> | ||
90 | <p> Most of the hard work is done. We only need to create the Irrlicht | ||
91 | Engine device and all the buttons, menus and toolbars. We start up the | ||
92 | engine as usual, using createDevice(). To make our application catch | ||
93 | events, we set our eventreceiver as parameter. The #ifdef WIN32 preprocessor | ||
94 | commands are not necesarry, but I included them to make the tutorial | ||
95 | use DirectX on Windows and OpenGL on all other platforms like Linux. | ||
96 | As you can see, there is also a unusual call to IrrlichtDevice::setResizeAble(). | ||
97 | This makes the render window resizeable, which is quite useful for a | ||
98 | mesh viewer. </p> | ||
99 | <table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center"> | ||
100 | <tr> | ||
101 | <td><pre>int main()<br>{<br> // ask user for driver | ||
102 | <br> video::E_DRIVER_TYPE driverType; | ||
103 | <br> 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");<br><br> char key;<br> std::cin >> key;<br><br> switch(key)<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> } | ||
104 | <br> // create device and exit if creation failed | ||
105 | <br> MyEventReceiver receiver;<br> Device = createDevice(driverType, core::dimension2d<s32>(640, 480),<br> 16, false, false, false, &receiver); | ||
106 | <br> if (Device == 0)<br> return 1; // could not create selected driver.<br><br> Device->setResizable(true);<br> Device->setWindowCaption(L"Irrlicht Engine - Loading...");<br><br> video::IVideoDriver* driver = Device->getVideoDriver();<br> IGUIEnvironment* env = Device->getGUIEnvironment();<br> scene::ISceneManager* smgr = Device->getSceneManager();<br></pre></td> | ||
107 | </tr> | ||
108 | </table> | ||
109 | <p> The next step is to read the configuration file. It is stored in the | ||
110 | xml format and looks a little bit like this:<br> | ||
111 | <br> | ||
112 | <font face="Courier New, Courier, mono"><?xml version="1.0"?><br> | ||
113 | <config><br> | ||
114 | <startUpModel file="some filename" /><br> | ||
115 | <messageText caption="Irrlicht Engine Mesh Viewer"><br> | ||
116 | Hello!<br> | ||
117 | </messageText><br> | ||
118 | </config></font><br> | ||
119 | <br> | ||
120 | We need the data stored in there to be written into the global variables | ||
121 | StartUpModelFile, MessageText and Caption. This is now done using the | ||
122 | Irrlicht Engine integrated XML parser: </p> | ||
123 | <table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center"> | ||
124 | <tr> | ||
125 | <td><pre> <font color="#006600">// read configuration from xml file</font><br> io::IXMLReader* xml =<br> Device->getFileSystem()->createXMLReader("../../media/config.xml");<br> while(xml && xml->read())<br> {<br> switch(xml->getNodeType())<br> {<br> case io::EXN_TEXT:<br> <font color="#006600">// in this xml file, the only text which occurs is the messageText</font><br> MessageText = xml->getNodeData();<br> break;<br> case io::EXN_ELEMENT:<br> {<br> if (core::stringw("startUpModel") == xml->getNodeName())<br> StartUpModelFile = xml->getAttributeValue(L"file");<br> else<br> if (core::stringw("messageText") == xml->getNodeName())<br> Caption = xml->getAttributeValue(L"caption");<br> }<br> break;<br> }<br> }<br> if (xml)<br> xml->drop(); <font color="#006600">// don't forget to delete the xml reader </font><br> | ||
126 | </pre></td> | ||
127 | </tr> | ||
128 | </table> | ||
129 | <p> That wasn't difficult. Now we'll set a nicer font and create the Menu. | ||
130 | It is possible to create submenus for every menu item. The call menu->addItem(L"File", | ||
131 | -1, true, true); for example adds a new menu Item with the name "File" | ||
132 | and the id -1. The following parameter says that the menu item should | ||
133 | be enabled, and the last one says, that there should be a submenu. The | ||
134 | submenu can now be accessed with menu->getSubMenu(0), because the | ||
135 | "File" entry is the menu item with index 0. </p> | ||
136 | <table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center"> | ||
137 | <tr> | ||
138 | <td><pre> <font color="#006600">// set a nicer font</font><br> IGUISkin* skin = env->getSkin();<br> IGUIFont* font = env->getFont("../../media/fonthaettenschweiler.bmp");<br> if (font)<br> skin->setFont(font);<br><br><font color="#006600"> // create menu</font><br> gui::IGUIContextMenu* menu = env->addMenu();<br> menu->addItem(L"File", -1, true, true);<br> menu->addItem(L"View", -1, true, true);<br> menu->addItem(L"Help", -1, true, true);<br><br> gui::IGUIContextMenu* submenu;<br> submenu = menu->getSubMenu(0);<br> submenu->addItem(L"Open Model File...", 100);<br> submenu->addSeparator();<br> submenu->addItem(L"Quit", 200);<br><br> submenu = menu->getSubMenu(1);<br> submenu->addItem(L"toggle sky box visibility", 300);<br> submenu->addItem(L"toggle model debug information", 400);<br> submenu->addItem(L"model material", -1, true, true );<br><br> submenu = submenu->getSubMenu(2);<br> submenu->addItem(L"Solid", 610);<br> submenu->addItem(L"Transparent", 620);<br> submenu->addItem(L"Reflection", 630);<br><br> submenu = menu->getSubMenu(2);<br> submenu->addItem(L"About", 500); | ||
139 | </pre></td> | ||
140 | </tr> | ||
141 | </table> | ||
142 | <br> | ||
143 | We want a toolbar, onto which we can place colored buttons and important | ||
144 | looking stuff like a senseless combobox.<br> | ||
145 | <br> | ||
146 | <table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center"> | ||
147 | <tr> | ||
148 | <td><pre><font color="#006600"> // create toolbar</font><br> gui::IGUIToolBar* bar = env->addToolBar();<br> bar->addButton(1102, 0, driver->getTexture("../../media/open.bmp"));<br> bar->addButton(1103, 0, driver->getTexture("../../media/help.bmp"));<br> bar->addButton(1104, 0, driver->getTexture("../../media/tools.bmp"));<br><br><font color="#006600"> // create a combobox with some senseless texts</font><br> gui::IGUIComboBox* box = env->addComboBox(core::rect<s32>(100,5,200,25), bar);<br> box->addItem(L"Bilinear");<br> box->addItem(L"Trilinear");<br> box->addItem(L"Anisotropic");<br> box->addItem(L"Isotropic");<br> box->addItem(L"Psychedelic");<br> box->addItem(L"No filtering");</pre></td> | ||
149 | </tr> | ||
150 | </table> | ||
151 | <br> | ||
152 | To make the editor look a little bit better, we disable transparent gui | ||
153 | elements, and add a Irrlicht Engine logo. In addition, a text, which will | ||
154 | show the current frame per second value is created, and the window caption | ||
155 | changed.<br> | ||
156 | <br> | ||
157 | <table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center"> | ||
158 | <tr> | ||
159 | <td><pre> <font color="#006600">// disable alpha</font><br> for (s32 i=0; i<gui::EGDC_COUNT ; ++i)<br> {<br> video::SColor col = env->getSkin()->getColor((gui::EGUI_DEFAULT_COLOR)i);<br> col.setAlpha(255);<br> env->getSkin()->setColor((gui::EGUI_DEFAULT_COLOR)i, col);<br> }<br><br><font color="#006600"> // add a tabcontrol</font><br> createToolBox();<br><br> <font color="#006600">// add the irrlicht engine logo</font><br> IGUIImage* img = env->addImage(core::rect<s32>(22,429,108,460), 0, 666);<br> img->setImage(driver->getTexture("../../media/irrlichtlogoaligned.jpg"));<br><br> <font color="#006600">// create fps text </font><br> IGUIStaticText* fpstext =<br> env->addStaticText(L"", core::rect<s32>(210,26,270,41), true);<br><br> <font color="#006600">// set window caption</font><br> Caption += " - [";<br> Caption += driver->getName();<br> Caption += "]";<br> Device->setWindowCaption(Caption.c_str());</pre></td> | ||
160 | </tr> | ||
161 | </table> | ||
162 | <br> | ||
163 | That's nearly the whole application. We simply show the about message | ||
164 | box at start up, and load the first model. To make everything look better, | ||
165 | a skybox is created and a user controled camera, to make the application | ||
166 | a little bit more interactive. Finally, everything is drawed in a standard | ||
167 | drawing loop.<br> | ||
168 | <br> | ||
169 | <table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center"> | ||
170 | <tr> | ||
171 | <td><pre> <font color="#006600">// show about message box and load default model</font><br> showAboutText();<br> loadModel(StartUpModelFile.c_str());<br><font color="#006600"><br> // add skybox</font> <br> SkyBox = smgr->addSkyBoxSceneNode(<br> driver->getTexture("../../media/irrlicht2_up.bmp"),<br> driver->getTexture("../../media/irrlicht2_dn.bmp"),<br> driver->getTexture("../../media/irrlicht2_lf.bmp"),<br> driver->getTexture("../../media/irrlicht2_rt.bmp"),<br> driver->getTexture("../../media/irrlicht2_ft.bmp"),<br> driver->getTexture("../../media/irrlicht2_bk.bmp"));<br><br><font color="#006600"> // add a camera scene node </font><br> smgr->addCameraSceneNodeMaya();<br> <br> <font color="#006600">// draw everything</font><br> while(Device->run() && driver)<br> if (Device->isWindowActive())<br> {<br> driver->beginScene(true, true, video::SColor(150,50,50,50));<br> smgr->drawAll();<br> env->drawAll();<br> <br> driver->endScene();<br><br> core::stringw str = L"FPS: ";<br> str += driver->getFPS();<br> fpstext->setText(str.c_str());<br> }<br> Device->drop();<br> return 0;<br>}<br></pre></td> | ||
172 | </tr> | ||
173 | </table> | ||
174 | <br> | ||
175 | Compile and run this, and you have a fully functional 3d Mesh viewer.<br> | ||
176 | </div> | ||
177 | </td> | ||
178 | </tr> | ||
179 | </table> | ||
180 | <p> </p> | ||
181 | </body> | ||
182 | </html> | ||