Lets start! | -|||||||||||
-
-
-
- We start like in most other tutorials: Include all nesessary header - files, add a comment to let the engine be linked with the right .lib - file in Visual Studio, and deklare some global variables. We also - add two 'using namespece' statements, so we do not need to write the - whole names of all classes. In this tutorial, we use a lot stuff from - the gui namespace. -
The three following functions do several stuff used by the mesh - viewer. The first function showAboutText() simply displays a messagebox - with a caption and a message text. The texts will be stored in the - MessageText and Caption variables at startup. -
The second function loadModel() loads a model and displays it using - an addAnimatedMeshSceneNode and the scene manager. Nothing difficult. - It also displays a short message box, if the model could not be loaded. - -
Finally, the third function creates a toolbox window. In this simple - mesh viewer, this toolbox only contains a tab control with three edit - boxes for changing the scale of the displayed model. -
To get all the events sent by the GUI Elements, we need to create - an event receiver. This one is really simple. If an event occurs, - it checks the id of the caller and the event type, and starts an action - based on these values. For example, if a menu item with id 100 was - selected, if opens a file-open-dialog. -
Most of the hard work is done. We only need to create the Irrlicht - Engine device and all the buttons, menus and toolbars. We start up the - engine as usual, using createDevice(). To make our application catch - events, we set our eventreceiver as parameter. The #ifdef WIN32 preprocessor - commands are not necesarry, but I included them to make the tutorial - use DirectX on Windows and OpenGL on all other platforms like Linux. - As you can see, there is also a unusual call to IrrlichtDevice::setResizeAble(). - This makes the render window resizeable, which is quite useful for a - mesh viewer. -
The next step is to read the configuration file. It is stored in the
- xml format and looks a little bit like this:
That wasn't difficult. Now we'll set a nicer font and create the Menu. - It is possible to create submenus for every menu item. The call menu->addItem(L"File", - -1, true, true); for example adds a new menu Item with the name "File" - and the id -1. The following parameter says that the menu item should - be enabled, and the last one says, that there should be a submenu. The - submenu can now be accessed with menu->getSubMenu(0), because the - "File" entry is the menu item with index 0. -
- We want a toolbar, onto which we can place colored buttons and important - looking stuff like a senseless combobox. - -
- To make the editor look a little bit better, we disable transparent gui - elements, and add a Irrlicht Engine logo. In addition, a text, which will - show the current frame per second value is created, and the window caption - changed. - -
- That's nearly the whole application. We simply show the about message - box at start up, and load the first model. To make everything look better, - a skybox is created and a user controled camera, to make the application - a little bit more interactive. Finally, everything is drawed in a standard - drawing loop. - -
- Compile and run this, and you have a fully functional 3d Mesh viewer. - |
-
- - + + +
Lets start! | +|||||||||||
+
+
+
+ We start like in most other tutorials: Include all nesessary header + files, add a comment to let the engine be linked with the right .lib + file in Visual Studio, and deklare some global variables. We also + add two 'using namespece' statements, so we do not need to write the + whole names of all classes. In this tutorial, we use a lot stuff from + the gui namespace. +
The three following functions do several stuff used by the mesh + viewer. The first function showAboutText() simply displays a messagebox + with a caption and a message text. The texts will be stored in the + MessageText and Caption variables at startup. +
The second function loadModel() loads a model and displays it using + an addAnimatedMeshSceneNode and the scene manager. Nothing difficult. + It also displays a short message box, if the model could not be loaded. + +
Finally, the third function creates a toolbox window. In this simple + mesh viewer, this toolbox only contains a tab control with three edit + boxes for changing the scale of the displayed model. +
To get all the events sent by the GUI Elements, we need to create + an event receiver. This one is really simple. If an event occurs, + it checks the id of the caller and the event type, and starts an action + based on these values. For example, if a menu item with id 100 was + selected, if opens a file-open-dialog. +
Most of the hard work is done. We only need to create the Irrlicht + Engine device and all the buttons, menus and toolbars. We start up the + engine as usual, using createDevice(). To make our application catch + events, we set our eventreceiver as parameter. The #ifdef WIN32 preprocessor + commands are not necesarry, but I included them to make the tutorial + use DirectX on Windows and OpenGL on all other platforms like Linux. + As you can see, there is also a unusual call to IrrlichtDevice::setResizeAble(). + This makes the render window resizeable, which is quite useful for a + mesh viewer. +
The next step is to read the configuration file. It is stored in the
+ xml format and looks a little bit like this:
That wasn't difficult. Now we'll set a nicer font and create the Menu. + It is possible to create submenus for every menu item. The call menu->addItem(L"File", + -1, true, true); for example adds a new menu Item with the name "File" + and the id -1. The following parameter says that the menu item should + be enabled, and the last one says, that there should be a submenu. The + submenu can now be accessed with menu->getSubMenu(0), because the + "File" entry is the menu item with index 0. +
+ We want a toolbar, onto which we can place colored buttons and important + looking stuff like a senseless combobox. + +
+ To make the editor look a little bit better, we disable transparent gui + elements, and add a Irrlicht Engine logo. In addition, a text, which will + show the current frame per second value is created, and the window caption + changed. + +
+ That's nearly the whole application. We simply show the about message + box at start up, and load the first model. To make everything look better, + a skybox is created and a user controled camera, to make the application + a little bit more interactive. Finally, everything is drawed in a standard + drawing loop. + +
+ Compile and run this, and you have a fully functional 3d Mesh viewer. + |
+
+ + -- cgit v1.1