aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/irrlicht-1.8/examples/01.HelloWorld/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/irrlicht-1.8/examples/01.HelloWorld/main.cpp')
-rw-r--r--libraries/irrlicht-1.8/examples/01.HelloWorld/main.cpp472
1 files changed, 236 insertions, 236 deletions
diff --git a/libraries/irrlicht-1.8/examples/01.HelloWorld/main.cpp b/libraries/irrlicht-1.8/examples/01.HelloWorld/main.cpp
index a53483c..9ca21e5 100644
--- a/libraries/irrlicht-1.8/examples/01.HelloWorld/main.cpp
+++ b/libraries/irrlicht-1.8/examples/01.HelloWorld/main.cpp
@@ -1,236 +1,236 @@
1/** Example 001 HelloWorld 1/** Example 001 HelloWorld
2 2
3This Tutorial shows how to set up the IDE for using the Irrlicht Engine and how 3This Tutorial shows how to set up the IDE for using the Irrlicht Engine and how
4to write a simple HelloWorld program with it. The program will show how to use 4to write a simple HelloWorld program with it. The program will show how to use
5the basics of the VideoDriver, the GUIEnvironment, and the SceneManager. 5the basics of the VideoDriver, the GUIEnvironment, and the SceneManager.
6Microsoft Visual Studio is used as an IDE, but you will also be able to 6Microsoft Visual Studio is used as an IDE, but you will also be able to
7understand everything if you are using a different one or even another 7understand everything if you are using a different one or even another
8operating system than windows. 8operating system than windows.
9 9
10You have to include the header file <irrlicht.h> in order to use the engine. The 10You have to include the header file <irrlicht.h> in order to use the engine. The
11header file can be found in the Irrlicht Engine SDK directory \c include. To let 11header file can be found in the Irrlicht Engine SDK directory \c include. To let
12the compiler find this header file, the directory where it is located has to be 12the compiler find this header file, the directory where it is located has to be
13specified. This is different for every IDE and compiler you use. Let's explain 13specified. This is different for every IDE and compiler you use. Let's explain
14shortly how to do this in Microsoft Visual Studio: 14shortly how to do this in Microsoft Visual Studio:
15 15
16- If you use Version 6.0, select the Menu Extras -> Options. 16- If you use Version 6.0, select the Menu Extras -> Options.
17 Select the directories tab, and select the 'Include' Item in the combo box. 17 Select the directories tab, and select the 'Include' Item in the combo box.
18 Add the \c include directory of the irrlicht engine folder to the list of 18 Add the \c include directory of the irrlicht engine folder to the list of
19 directories. Now the compiler will find the Irrlicht.h header file. We also 19 directories. Now the compiler will find the Irrlicht.h header file. We also
20 need the irrlicht.lib to be found, so stay in that dialog, select 'Libraries' 20 need the irrlicht.lib to be found, so stay in that dialog, select 'Libraries'
21 in the combo box and add the \c lib/VisualStudio directory. 21 in the combo box and add the \c lib/VisualStudio directory.
22 \image html "vc6optionsdir.jpg" 22 \image html "vc6optionsdir.jpg"
23 \image latex "vc6optionsdir.jpg" 23 \image latex "vc6optionsdir.jpg"
24 \image html "vc6include.jpg" 24 \image html "vc6include.jpg"
25 \image latex "vc6include.jpg" 25 \image latex "vc6include.jpg"
26 26
27- If your IDE is Visual Studio .NET, select Tools -> Options. 27- If your IDE is Visual Studio .NET, select Tools -> Options.
28 Select the projects entry and then select VC++ directories. Select 'show 28 Select the projects entry and then select VC++ directories. Select 'show
29 directories for include files' in the combo box, and add the \c include 29 directories for include files' in the combo box, and add the \c include
30 directory of the irrlicht engine folder to the list of directories. Now the 30 directory of the irrlicht engine folder to the list of directories. Now the
31 compiler will find the Irrlicht.h header file. We also need the irrlicht.lib 31 compiler will find the Irrlicht.h header file. We also need the irrlicht.lib
32 to be found, so stay in that dialog, select 'show directories for Library 32 to be found, so stay in that dialog, select 'show directories for Library
33 files' and add the \c lib/VisualStudio directory. 33 files' and add the \c lib/VisualStudio directory.
34 \image html "vcnetinclude.jpg" 34 \image html "vcnetinclude.jpg"
35 \image latex "vcnetinclude.jpg" 35 \image latex "vcnetinclude.jpg"
36 36
37That's it. With your IDE set up like this, you will now be able to develop 37That's it. With your IDE set up like this, you will now be able to develop
38applications with the Irrlicht Engine. 38applications with the Irrlicht Engine.
39 39
40Lets start! 40Lets start!
41 41
42After we have set up the IDE, the compiler will know where to find the Irrlicht 42After we have set up the IDE, the compiler will know where to find the Irrlicht
43Engine header files so we can include it now in our code. 43Engine header files so we can include it now in our code.
44*/ 44*/
45#include <irrlicht.h> 45#include <irrlicht.h>
46 46
47/* 47/*
48In the Irrlicht Engine, everything can be found in the namespace 'irr'. So if 48In the Irrlicht Engine, everything can be found in the namespace 'irr'. So if
49you want to use a class of the engine, you have to write irr:: before the name 49you want to use a class of the engine, you have to write irr:: before the name
50of the class. For example to use the IrrlichtDevice write: irr::IrrlichtDevice. 50of the class. For example to use the IrrlichtDevice write: irr::IrrlichtDevice.
51To get rid of the irr:: in front of the name of every class, we tell the 51To get rid of the irr:: in front of the name of every class, we tell the
52compiler that we use that namespace from now on, and we will not have to write 52compiler that we use that namespace from now on, and we will not have to write
53irr:: anymore. 53irr:: anymore.
54*/ 54*/
55using namespace irr; 55using namespace irr;
56 56
57/* 57/*
58There are 5 sub namespaces in the Irrlicht Engine. Take a look at them, you can 58There are 5 sub namespaces in the Irrlicht Engine. Take a look at them, you can
59read a detailed description of them in the documentation by clicking on the top 59read a detailed description of them in the documentation by clicking on the top
60menu item 'Namespace List' or by using this link: 60menu item 'Namespace List' or by using this link:
61http://irrlicht.sourceforge.net/docu/namespaces.html 61http://irrlicht.sourceforge.net/docu/namespaces.html
62Like the irr namespace, we do not want these 5 sub namespaces now, to keep this 62Like the irr namespace, we do not want these 5 sub namespaces now, to keep this
63example simple. Hence, we tell the compiler again that we do not want always to 63example simple. Hence, we tell the compiler again that we do not want always to
64write their names. 64write their names.
65*/ 65*/
66using namespace core; 66using namespace core;
67using namespace scene; 67using namespace scene;
68using namespace video; 68using namespace video;
69using namespace io; 69using namespace io;
70using namespace gui; 70using namespace gui;
71 71
72/* 72/*
73To be able to use the Irrlicht.DLL file, we need to link with the Irrlicht.lib. 73To be able to use the Irrlicht.DLL file, we need to link with the Irrlicht.lib.
74We could set this option in the project settings, but to make it easy, we use a 74We could set this option in the project settings, but to make it easy, we use a
75pragma comment lib for VisualStudio. On Windows platforms, we have to get rid 75pragma comment lib for VisualStudio. On Windows platforms, we have to get rid
76of the console window, which pops up when starting a program with main(). This 76of the console window, which pops up when starting a program with main(). This
77is done by the second pragma. We could also use the WinMain method, though 77is done by the second pragma. We could also use the WinMain method, though
78losing platform independence then. 78losing platform independence then.
79*/ 79*/
80#ifdef _IRR_WINDOWS_ 80#ifdef _IRR_WINDOWS_
81#pragma comment(lib, "Irrlicht.lib") 81#pragma comment(lib, "Irrlicht.lib")
82#pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup") 82#pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")
83#endif 83#endif
84 84
85 85
86/* 86/*
87This is the main method. We can now use main() on every platform. 87This is the main method. We can now use main() on every platform.
88*/ 88*/
89int main() 89int main()
90{ 90{
91 /* 91 /*
92 The most important function of the engine is the createDevice() 92 The most important function of the engine is the createDevice()
93 function. The IrrlichtDevice is created by it, which is the root 93 function. The IrrlichtDevice is created by it, which is the root
94 object for doing anything with the engine. createDevice() has 7 94 object for doing anything with the engine. createDevice() has 7
95 parameters: 95 parameters:
96 96
97 - deviceType: Type of the device. This can currently be the Null-device, 97 - deviceType: Type of the device. This can currently be the Null-device,
98 one of the two software renderers, D3D8, D3D9, or OpenGL. In this 98 one of the two software renderers, D3D8, D3D9, or OpenGL. In this
99 example we use EDT_SOFTWARE, but to try out, you might want to 99 example we use EDT_SOFTWARE, but to try out, you might want to
100 change it to EDT_BURNINGSVIDEO, EDT_NULL, EDT_DIRECT3D8, 100 change it to EDT_BURNINGSVIDEO, EDT_NULL, EDT_DIRECT3D8,
101 EDT_DIRECT3D9, or EDT_OPENGL. 101 EDT_DIRECT3D9, or EDT_OPENGL.
102 102
103 - windowSize: Size of the Window or screen in FullScreenMode to be 103 - windowSize: Size of the Window or screen in FullScreenMode to be
104 created. In this example we use 640x480. 104 created. In this example we use 640x480.
105 105
106 - bits: Amount of color bits per pixel. This should be 16 or 32. The 106 - bits: Amount of color bits per pixel. This should be 16 or 32. The
107 parameter is often ignored when running in windowed mode. 107 parameter is often ignored when running in windowed mode.
108 108
109 - fullscreen: Specifies if we want the device to run in fullscreen mode 109 - fullscreen: Specifies if we want the device to run in fullscreen mode
110 or not. 110 or not.
111 111
112 - stencilbuffer: Specifies if we want to use the stencil buffer (for 112 - stencilbuffer: Specifies if we want to use the stencil buffer (for
113 drawing shadows). 113 drawing shadows).
114 114
115 - vsync: Specifies if we want to have vsync enabled, this is only useful 115 - vsync: Specifies if we want to have vsync enabled, this is only useful
116 in fullscreen mode. 116 in fullscreen mode.
117 117
118 - eventReceiver: An object to receive events. We do not want to use this 118 - eventReceiver: An object to receive events. We do not want to use this
119 parameter here, and set it to 0. 119 parameter here, and set it to 0.
120 120
121 Always check the return value to cope with unsupported drivers, 121 Always check the return value to cope with unsupported drivers,
122 dimensions, etc. 122 dimensions, etc.
123 */ 123 */
124 IrrlichtDevice *device = 124 IrrlichtDevice *device =
125 createDevice( video::EDT_SOFTWARE, dimension2d<u32>(640, 480), 16, 125 createDevice( video::EDT_SOFTWARE, dimension2d<u32>(640, 480), 16,
126 false, false, false, 0); 126 false, false, false, 0);
127 127
128 if (!device) 128 if (!device)
129 return 1; 129 return 1;
130 130
131 /* 131 /*
132 Set the caption of the window to some nice text. Note that there is an 132 Set the caption of the window to some nice text. Note that there is an
133 'L' in front of the string. The Irrlicht Engine uses wide character 133 'L' in front of the string. The Irrlicht Engine uses wide character
134 strings when displaying text. 134 strings when displaying text.
135 */ 135 */
136 device->setWindowCaption(L"Hello World! - Irrlicht Engine Demo"); 136 device->setWindowCaption(L"Hello World! - Irrlicht Engine Demo");
137 137
138 /* 138 /*
139 Get a pointer to the VideoDriver, the SceneManager and the graphical 139 Get a pointer to the VideoDriver, the SceneManager and the graphical
140 user interface environment, so that we do not always have to write 140 user interface environment, so that we do not always have to write
141 device->getVideoDriver(), device->getSceneManager(), or 141 device->getVideoDriver(), device->getSceneManager(), or
142 device->getGUIEnvironment(). 142 device->getGUIEnvironment().
143 */ 143 */
144 IVideoDriver* driver = device->getVideoDriver(); 144 IVideoDriver* driver = device->getVideoDriver();
145 ISceneManager* smgr = device->getSceneManager(); 145 ISceneManager* smgr = device->getSceneManager();
146 IGUIEnvironment* guienv = device->getGUIEnvironment(); 146 IGUIEnvironment* guienv = device->getGUIEnvironment();
147 147
148 /* 148 /*
149 We add a hello world label to the window, using the GUI environment. 149 We add a hello world label to the window, using the GUI environment.
150 The text is placed at the position (10,10) as top left corner and 150 The text is placed at the position (10,10) as top left corner and
151 (260,22) as lower right corner. 151 (260,22) as lower right corner.
152 */ 152 */
153 guienv->addStaticText(L"Hello World! This is the Irrlicht Software renderer!", 153 guienv->addStaticText(L"Hello World! This is the Irrlicht Software renderer!",
154 rect<s32>(10,10,260,22), true); 154 rect<s32>(10,10,260,22), true);
155 155
156 /* 156 /*
157 To show something interesting, we load a Quake 2 model and display it. 157 To show something interesting, we load a Quake 2 model and display it.
158 We only have to get the Mesh from the Scene Manager with getMesh() and add 158 We only have to get the Mesh from the Scene Manager with getMesh() and add
159 a SceneNode to display the mesh with addAnimatedMeshSceneNode(). We 159 a SceneNode to display the mesh with addAnimatedMeshSceneNode(). We
160 check the return value of getMesh() to become aware of loading problems 160 check the return value of getMesh() to become aware of loading problems
161 and other errors. 161 and other errors.
162 162
163 Instead of writing the filename sydney.md2, it would also be possible 163 Instead of writing the filename sydney.md2, it would also be possible
164 to load a Maya object file (.obj), a complete Quake3 map (.bsp) or any 164 to load a Maya object file (.obj), a complete Quake3 map (.bsp) or any
165 other supported file format. By the way, that cool Quake 2 model 165 other supported file format. By the way, that cool Quake 2 model
166 called sydney was modelled by Brian Collins. 166 called sydney was modelled by Brian Collins.
167 */ 167 */
168 IAnimatedMesh* mesh = smgr->getMesh("../../media/sydney.md2"); 168 IAnimatedMesh* mesh = smgr->getMesh("../../media/sydney.md2");
169 if (!mesh) 169 if (!mesh)
170 { 170 {
171 device->drop(); 171 device->drop();
172 return 1; 172 return 1;
173 } 173 }
174 IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( mesh ); 174 IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( mesh );
175 175
176 /* 176 /*
177 To let the mesh look a little bit nicer, we change its material. We 177 To let the mesh look a little bit nicer, we change its material. We
178 disable lighting because we do not have a dynamic light in here, and 178 disable lighting because we do not have a dynamic light in here, and
179 the mesh would be totally black otherwise. Then we set the frame loop, 179 the mesh would be totally black otherwise. Then we set the frame loop,
180 such that the predefined STAND animation is used. And last, we apply a 180 such that the predefined STAND animation is used. And last, we apply a
181 texture to the mesh. Without it the mesh would be drawn using only a 181 texture to the mesh. Without it the mesh would be drawn using only a
182 color. 182 color.
183 */ 183 */
184 if (node) 184 if (node)
185 { 185 {
186 node->setMaterialFlag(EMF_LIGHTING, false); 186 node->setMaterialFlag(EMF_LIGHTING, false);
187 node->setMD2Animation(scene::EMAT_STAND); 187 node->setMD2Animation(scene::EMAT_STAND);
188 node->setMaterialTexture( 0, driver->getTexture("../../media/sydney.bmp") ); 188 node->setMaterialTexture( 0, driver->getTexture("../../media/sydney.bmp") );
189 } 189 }
190 190
191 /* 191 /*
192 To look at the mesh, we place a camera into 3d space at the position 192 To look at the mesh, we place a camera into 3d space at the position
193 (0, 30, -40). The camera looks from there to (0,5,0), which is 193 (0, 30, -40). The camera looks from there to (0,5,0), which is
194 approximately the place where our md2 model is. 194 approximately the place where our md2 model is.
195 */ 195 */
196 smgr->addCameraSceneNode(0, vector3df(0,30,-40), vector3df(0,5,0)); 196 smgr->addCameraSceneNode(0, vector3df(0,30,-40), vector3df(0,5,0));
197 197
198 /* 198 /*
199 Ok, now we have set up the scene, lets draw everything: We run the 199 Ok, now we have set up the scene, lets draw everything: We run the
200 device in a while() loop, until the device does not want to run any 200 device in a while() loop, until the device does not want to run any
201 more. This would be when the user closes the window or presses ALT+F4 201 more. This would be when the user closes the window or presses ALT+F4
202 (or whatever keycode closes a window). 202 (or whatever keycode closes a window).
203 */ 203 */
204 while(device->run()) 204 while(device->run())
205 { 205 {
206 /* 206 /*
207 Anything can be drawn between a beginScene() and an endScene() 207 Anything can be drawn between a beginScene() and an endScene()
208 call. The beginScene() call clears the screen with a color and 208 call. The beginScene() call clears the screen with a color and
209 the depth buffer, if desired. Then we let the Scene Manager and 209 the depth buffer, if desired. Then we let the Scene Manager and
210 the GUI Environment draw their content. With the endScene() 210 the GUI Environment draw their content. With the endScene()
211 call everything is presented on the screen. 211 call everything is presented on the screen.
212 */ 212 */
213 driver->beginScene(true, true, SColor(255,100,101,140)); 213 driver->beginScene(true, true, SColor(255,100,101,140));
214 214
215 smgr->drawAll(); 215 smgr->drawAll();
216 guienv->drawAll(); 216 guienv->drawAll();
217 217
218 driver->endScene(); 218 driver->endScene();
219 } 219 }
220 220
221 /* 221 /*
222 After we are done with the render loop, we have to delete the Irrlicht 222 After we are done with the render loop, we have to delete the Irrlicht
223 Device created before with createDevice(). In the Irrlicht Engine, you 223 Device created before with createDevice(). In the Irrlicht Engine, you
224 have to delete all objects you created with a method or function which 224 have to delete all objects you created with a method or function which
225 starts with 'create'. The object is simply deleted by calling ->drop(). 225 starts with 'create'. The object is simply deleted by calling ->drop().
226 See the documentation at irr::IReferenceCounted::drop() for more 226 See the documentation at irr::IReferenceCounted::drop() for more
227 information. 227 information.
228 */ 228 */
229 device->drop(); 229 device->drop();
230 230
231 return 0; 231 return 0;
232} 232}
233 233
234/* 234/*
235That's it. Compile and run. 235That's it. Compile and run.
236**/ 236**/