This tutorial show how to create a more complex application with the engine. We construct a simple mesh viewer using the user interface API and the scene management of Irrlicht. The tutorial show how to create and use Buttons, Windows, Toolbars, Menus, ComboBoxes, Tabcontrols, Editboxes, Images, MessageBoxes, SkyBoxes, and how to parse XML files with the integrated XML reader of the engine.
We start like in most other tutorials: Include all necessary header files, add a comment to let the engine be linked with the right .lib file in Visual Studio, and declare some global variables. We also add two 'using namespace' 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.
using namespace gui;
#ifdef _MSC_VER
#pragma comment(lib, "Irrlicht.lib")
#endif
Main header file of the irrlicht, the only file needed to include.
Everything in the Irrlicht Engine can be found in this namespace.
Some global variables used later on
bool Octree=false;
bool UseLight=false;
enum
{
GUI_ID_DIALOG_ROOT_WINDOW = 0x10000,
GUI_ID_X_SCALE,
GUI_ID_Y_SCALE,
GUI_ID_Z_SCALE,
GUI_ID_OPEN_MODEL,
GUI_ID_SET_MODEL_ARCHIVE,
GUI_ID_LOAD_AS_OCTREE,
GUI_ID_SKY_BOX_VISIBLE,
GUI_ID_TOGGLE_DEBUG_INFO,
GUI_ID_DEBUG_OFF,
GUI_ID_DEBUG_BOUNDING_BOX,
GUI_ID_DEBUG_NORMALS,
GUI_ID_DEBUG_SKELETON,
GUI_ID_DEBUG_WIRE_OVERLAY,
GUI_ID_DEBUG_HALF_TRANSPARENT,
GUI_ID_DEBUG_BUFFERS_BOUNDING_BOXES,
GUI_ID_DEBUG_ALL,
GUI_ID_MODEL_MATERIAL_SOLID,
GUI_ID_MODEL_MATERIAL_TRANSPARENT,
GUI_ID_MODEL_MATERIAL_REFLECTION,
GUI_ID_CAMERA_MAYA,
GUI_ID_CAMERA_FIRST_PERSON,
GUI_ID_POSITION_TEXT,
GUI_ID_ABOUT,
GUI_ID_QUIT,
GUI_ID_TEXTUREFILTER,
GUI_ID_SKIN_TRANSPARENCY,
GUI_ID_SKIN_ANIMATION_FPS,
GUI_ID_BUTTON_SET_SCALE,
GUI_ID_BUTTON_SCALE_MUL10,
GUI_ID_BUTTON_SCALE_DIV10,
GUI_ID_BUTTON_OPEN_MODEL,
GUI_ID_BUTTON_SHOW_ABOUT,
GUI_ID_BUTTON_SHOW_TOOLBOX,
GUI_ID_BUTTON_SELECT_ARCHIVE,
GUI_ID_ANIMATION_INFO,
MAX_FRAMERATE = 80,
DEFAULT_FRAMERATE = 30
};
The Irrlicht device. You can create it with createDevice() or createDeviceEx().
Axis aligned bounding box in 3d dimensional space.
Scene Node which is a (controlable) camera.
Toggle between various cameras
{
if (0 == Device)
return;
}
virtual scene::ISceneManager * getSceneManager()=0
Provides access to the scene manager.
virtual void setInputReceiverEnabled(bool enabled)=0
Disables or enables the camera to get key or mouse inputs.
virtual ICameraSceneNode * getActiveCamera() const =0
Get the current active camera.
virtual void setActiveCamera(ICameraSceneNode *camera)=0
Sets the currently active camera.
Set the skin transparency by changing the alpha values of all skin-colors
{
{
skin->
setColor((EGUI_DEFAULT_COLOR)i, col);
}
}
A skin modifies the look of the GUI elements.
virtual void setColor(EGUI_DEFAULT_COLOR which, video::SColor newColor)=0
sets a default color
virtual video::SColor getColor(EGUI_DEFAULT_COLOR color) const =0
returns default color
Class representing a 32 bit ARGB color.
void setAlpha(u32 a)
Sets the alpha component of the Color.
signed int s32
32 bit signed variable.
Update the display of the model scaling
{
if (!toolboxWnd)
return;
if (!model)
{
toolboxWnd->getElementFromId(GUI_ID_Y_SCALE, true)->setText( L"-" );
toolboxWnd->getElementFromId(GUI_ID_Z_SCALE, true)->setText( L"-" );
}
else
{
toolboxWnd->getElementFromId(GUI_ID_X_SCALE,
true)->setText(
core::stringw(scale.
X).c_str() );
toolboxWnd->getElementFromId(GUI_ID_Y_SCALE,
true)->setText(
core::stringw(scale.
Y).c_str() );
toolboxWnd->getElementFromId(GUI_ID_Z_SCALE,
true)->setText(
core::stringw(scale.
Z).c_str() );
}
}
virtual gui::IGUIEnvironment * getGUIEnvironment()=0
Provides access to the 2d user interface environment.
T X
X coordinate of the vector.
T Z
Z coordinate of the vector.
T Y
Y coordinate of the vector.
virtual void setText(const wchar_t *text)
Sets the new caption of this element.
virtual IGUIElement * getElementFromId(s32 id, bool searchchildren=false) const
Finds the first element with the given id.
virtual IGUIElement * getRootGUIElement()=0
Returns the root gui element.
virtual const core::vector3df & getScale() const
Gets the scale of the scene node relative to its parent.
Function showAboutText() displays a messagebox with a caption and a message text. The texts will be stored in the MessageText and Caption variables at startup.
void showAboutText()
{
Caption.c_str(), MessageText.c_str());
}
virtual IGUIWindow * addMessageBox(const wchar_t *caption, const wchar_t *text=0, bool modal=true, s32 flags=EMBF_OK, IGUIElement *parent=0, s32 id=-1, video::ITexture *image=0)=0
Adds a message box.
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.
void loadModel(
const c8* fn)
{
core::getFileNameExtension(extension, filename);
if (extension == ".jpg" || extension == ".pcx" ||
extension == ".png" || extension == ".ppm" ||
extension == ".pgm" || extension == ".pbm" ||
extension == ".psd" || extension == ".tga" ||
extension == ".bmp" || extension == ".wal" ||
extension == ".rgb" || extension == ".rgba")
{
if ( texture && Model )
{
}
return;
}
else if (extension == ".pk3" || extension == ".zip" || extension == ".pak" || extension == ".npk")
{
return;
}
if (Model)
Model = 0;
if (extension==".irr")
{
Model = outNodes[0];
return;
}
if (!m)
{
if (StartUpModelFile != filename)
Caption.c_str(), L"The model could not be loaded. " \
L"Maybe it is not a supported file format.");
return;
}
if (Octree)
else
{
Model = animModel;
}
if (menu)
for(int item = 1; item < 6; ++item)
updateScaleInfo(Model);
}
virtual video::IVideoDriver * getVideoDriver()=0
Provides access to the video driver for drawing 3d and 2d geometry.
virtual io::IFileSystem * getFileSystem()=0
Provides access to the virtual file system.
u32 size() const
Get number of occupied elements of the array.
string< T, TAlloc > & make_lower()
Makes the string lower case.
virtual bool addFileArchive(const path &filename, bool ignoreCase=true, bool ignorePaths=true, E_FILE_ARCHIVE_TYPE archiveType=EFAT_UNKNOWN, const core::stringc &password="", IFileArchive **retArchive=0)=0
Adds an archive to the file system.
Interface for an animated mesh.
virtual IMesh * getMesh(s32 frame, s32 detailLevel=255, s32 startFrameLoop=-1, s32 endFrameLoop=-1)=0
Returns the IMesh interface for a frame.
Scene node capable of displaying an animated mesh and its shadow.
virtual void setAnimationSpeed(f32 framesPerSecond)=0
Sets the speed with which the animation is played.
virtual IAnimatedMesh * getMesh(const io::path &filename)=0
Get pointer to an animateable mesh. Loads the file if not loaded already.
virtual void getSceneNodesFromType(ESCENE_NODE_TYPE type, core::array< scene::ISceneNode * > &outNodes, ISceneNode *start=0)=0
Get scene nodes by type.
virtual bool loadScene(const io::path &filename, ISceneUserDataSerializer *userDataSerializer=0, ISceneNode *rootNode=0)=0
Loads a scene. Note that the current scene is not cleared before.
virtual IAnimatedMeshSceneNode * addAnimatedMeshSceneNode(IAnimatedMesh *mesh, ISceneNode *parent=0, s32 id=-1, const core::vector3df &position=core::vector3df(0, 0, 0), const core::vector3df &rotation=core::vector3df(0, 0, 0), const core::vector3df &scale=core::vector3df(1.0f, 1.0f, 1.0f), bool alsoAddIfMeshPointerZero=false)=0
Adds a scene node for rendering an animated mesh model.
virtual IMeshSceneNode * addOctreeSceneNode(IAnimatedMesh *mesh, ISceneNode *parent=0, s32 id=-1, s32 minimalPolysPerNode=512, bool alsoAddIfMeshPointerZero=false)=0
Adds a scene node for rendering using a octree to the scene graph.
void setMaterialTexture(u32 textureLayer, video::ITexture *texture)
Sets the texture of the specified layer in all materials of this scene node to the new texture.
void setMaterialFlag(video::E_MATERIAL_FLAG flag, bool newvalue)
Sets all material flags at once to a new value.
virtual void remove()
Removes this scene node from the scene.
virtual void setDebugDataVisible(u32 state)
Sets if debug data like bounding boxes should be drawn.
Interface of a Video Driver dependent Texture.
virtual ITexture * getTexture(const io::path &filename)=0
Get access to a named texture.
virtual void removeTexture(ITexture *texture)=0
Removes a texture from the texture cache and deletes it.
char c8
8 bit character variable.
Function createToolBox() 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.
void createToolBox()
{
if (e)
false, L"Toolset", 0, GUI_ID_DIALOG_ROOT_WINDOW);
IGUITabControl* tab = env->addTabControl(
IGUITab* t1 = tab->addTab(L"Config");
env->addStaticText(L"Scale:",
env->addEditBox(L
"1.0",
core::rect<s32>(40,46,130,66),
true, t1, GUI_ID_X_SCALE);
env->addEditBox(L
"1.0",
core::rect<s32>(40,76,130,96),
true, t1, GUI_ID_Y_SCALE);
env->addStaticText(L
"Z:",
core::rect<s32>(22,108,40,126),
false,
false, t1);
env->addEditBox(L
"1.0",
core::rect<s32>(40,106,130,126),
true, t1, GUI_ID_Z_SCALE);
env->addButton(
core::rect<s32>(10,134,85,165), t1, GUI_ID_BUTTON_SET_SCALE, L
"Set");
env->addButton(
core::rect<s32>(65,20,95,40), t1, GUI_ID_BUTTON_SCALE_MUL10, L
"* 10");
env->addButton(
core::rect<s32>(100,20,130,40), t1, GUI_ID_BUTTON_SCALE_DIV10, L
"* 0.1");
updateScaleInfo(Model);
env->addStaticText(L"GUI Transparency Control:",
IGUIScrollBar* scrollbar = env->addScrollBar(true,
scrollbar->setMax(255);
scrollbar->setPos(255);
env->addStaticText(L
":",
core::rect<s32>(10,240,150,265),
true,
false, t1);
env->addStaticText(L"Framerate:",
GUI_ID_ANIMATION_INFO);
scrollbar = env->addScrollBar(true,
scrollbar->setMax(MAX_FRAMERATE);
scrollbar->setMin(-MAX_FRAMERATE);
scrollbar->setPos(DEFAULT_FRAMERATE);
scrollbar->setSmallStep(1);
}
virtual void remove()
Removes this element from its parent.
Function updateToolBox() is called each frame to update dynamic information in the toolbox.
void updateToolBox()
{
if (!dlg )
return;
IGUIStaticText * aniInfo = (IGUIStaticText *)(dlg->getElementFromId(GUI_ID_ANIMATION_INFO, true));
if (aniInfo)
{
if ( Model && scene::ESNT_ANIMATED_MESH == Model->
getType() )
{
str += L" Frame: ";
aniInfo->setText(str.c_str());
}
else
aniInfo->setText(L"");
}
}
void onKillFocus()
{
while ( iter != animators.
end() )
{
if ( (*iter)->getType() == scene::ESNAT_CAMERA_FPS )
{
{
event.KeyInput.Key = keyMap[i].KeyCode;
event.KeyInput.PressedDown = false;
}
}
++iter;
}
}
List iterator for const access.
Iterator end()
Gets end node.
Iterator begin()
Gets first node.
virtual f32 getAnimationSpeed() const =0
Gets the speed with which the animation is played.
virtual f32 getFrameNr() const =0
Returns the currently displayed frame number.
Special scene node animator for FPS cameras.
virtual const core::array< SKeyMap > & getKeyMap() const =0
Gets the keyboard mapping for this animator.
virtual bool OnEvent(const SEvent &event)
Event receiver, override this function for camera controlling animators.
virtual ESCENE_NODE_TYPE getType() const
Returns type of the scene node.
const core::list< ISceneNodeAnimator * > & getAnimators() const
Get a list of all scene node animators.
unsigned int u32
32 bit unsigned variable.
@ EET_KEY_INPUT_EVENT
A key input event.
SEvents hold information about an event. See irr::IEventReceiver for details on event handling.
Function hasModalDialog() checks if we currently have a modal dialog open.
bool hasModalDialog()
{
if ( !Device )
return false;
IGUIElement * focused = env->
getFocus();
while ( focused )
{
if ( focused->isVisible() && focused->hasType(EGUIET_MODAL_SCREEN) )
return true;
}
return false;
}
IGUIElement * getParent() const
Returns parent of this element.
virtual IGUIElement * getFocus() const =0
Returns the element which holds the focus.
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 GUI_ID_OPEN_MODEL was selected, it opens a file-open-dialog.
{
public:
virtual bool OnEvent(
const SEvent& event)
{
if (event.
EventType == EET_KEY_INPUT_EVENT &&
{
return true;
}
{
s32 id =
event.GUIEvent.Caller->getID();
{
case EGET_MENU_ITEM_SELECTED:
break;
case EGET_FILE_SELECTED:
{
IGUIFileOpenDialog* dialog =
}
break;
if (id == GUI_ID_SKIN_TRANSPARENCY)
{
setSkinTransparency(pos, env->getSkin());
}
else if (id == GUI_ID_SKIN_ANIMATION_FPS)
{
if (scene::ESNT_ANIMATED_MESH == Model->
getType())
}
break;
if (id == GUI_ID_TEXTUREFILTER)
{
}
break;
switch(id)
{
case GUI_ID_BUTTON_SET_SCALE:
{
scale.
X = (
f32)atof(s.c_str());
scale.
Y = (
f32)atof(s.c_str());
scale.
Z = (
f32)atof(s.c_str());
if (Model)
updateScaleInfo(Model);
}
break;
case GUI_ID_BUTTON_SCALE_MUL10:
if (Model)
updateScaleInfo(Model);
break;
case GUI_ID_BUTTON_SCALE_DIV10:
if (Model)
updateScaleInfo(Model);
break;
case GUI_ID_BUTTON_OPEN_MODEL:
env->addFileOpenDialog(L"Please select a model file to open");
break;
case GUI_ID_BUTTON_SHOW_ABOUT:
showAboutText();
break;
case GUI_ID_BUTTON_SHOW_TOOLBOX:
createToolBox();
break;
case GUI_ID_BUTTON_SELECT_ARCHIVE:
env->addFileOpenDialog(L"Please select your game archive/directory");
break;
}
break;
default:
break;
}
}
return false;
}
Interface of an object which can receive events.
Base class of all GUI elements.
virtual const wchar_t * getText() const
Returns caption of this element.
virtual void setScale(const core::vector3df &scale)
Sets the relative scale of the scene node.
@ EGET_SCROLL_BAR_CHANGED
A scrollbar has changed its position.
@ EGET_BUTTON_CLICKED
A button was clicked.
@ EGET_COMBO_BOX_CHANGED
The selection in a combo box has been changed.
float f32
32 bit floating point variable.
gui::IGUIElement * Caller
IGUIElement who called the event.
gui::EGUI_EVENT_TYPE EventType
Type of GUI Event.
struct SGUIEvent GUIEvent
struct SKeyInput KeyInput
Handle key-up events
{
if ( hasModalDialog() )
return false;
{
if (Device)
{
if (camera)
{
}
return true;
}
}
{
if (Device)
{
if (elem)
}
}
{
if (Device)
}
{
UseLight=!UseLight;
if (Model)
{
}
}
return false;
}
virtual void minimizeWindow()=0
Minimizes the window if possible.
virtual void setVisible(bool visible)
Sets the visible state of this element.
virtual bool isInputReceiverEnabled() const =0
Checks if the input receiver of the camera is currently enabled.
Handle "menu item clicked" events.
void OnMenuItemSelected( IGUIContextMenu* menu )
{
s32 id = menu->getItemCommandId(menu->getSelectedItem());
switch(id)
{
case GUI_ID_OPEN_MODEL:
break;
case GUI_ID_SET_MODEL_ARCHIVE:
env->addFileOpenDialog(L"Please select your game archive/directory");
break;
case GUI_ID_LOAD_AS_OCTREE:
Octree = !Octree;
menu->setItemChecked(menu->getSelectedItem(), Octree);
break;
case GUI_ID_QUIT:
break;
case GUI_ID_SKY_BOX_VISIBLE:
menu->setItemChecked(menu->getSelectedItem(), !menu->isItemChecked(menu->getSelectedItem()));
break;
case GUI_ID_DEBUG_OFF:
menu->setItemChecked(menu->getSelectedItem()+1, false);
menu->setItemChecked(menu->getSelectedItem()+2, false);
menu->setItemChecked(menu->getSelectedItem()+3, false);
menu->setItemChecked(menu->getSelectedItem()+4, false);
menu->setItemChecked(menu->getSelectedItem()+5, false);
menu->setItemChecked(menu->getSelectedItem()+6, false);
if (Model)
break;
case GUI_ID_DEBUG_BOUNDING_BOX:
menu->setItemChecked(menu->getSelectedItem(), !menu->isItemChecked(menu->getSelectedItem()));
if (Model)
break;
case GUI_ID_DEBUG_NORMALS:
menu->setItemChecked(menu->getSelectedItem(), !menu->isItemChecked(menu->getSelectedItem()));
if (Model)
break;
case GUI_ID_DEBUG_SKELETON:
menu->setItemChecked(menu->getSelectedItem(), !menu->isItemChecked(menu->getSelectedItem()));
if (Model)
break;
case GUI_ID_DEBUG_WIRE_OVERLAY:
menu->setItemChecked(menu->getSelectedItem(), !menu->isItemChecked(menu->getSelectedItem()));
if (Model)
break;
case GUI_ID_DEBUG_HALF_TRANSPARENT:
menu->setItemChecked(menu->getSelectedItem(), !menu->isItemChecked(menu->getSelectedItem()));
if (Model)
break;
case GUI_ID_DEBUG_BUFFERS_BOUNDING_BOXES:
menu->setItemChecked(menu->getSelectedItem(), !menu->isItemChecked(menu->getSelectedItem()));
if (Model)
break;
case GUI_ID_DEBUG_ALL:
menu->setItemChecked(menu->getSelectedItem()-1, true);
menu->setItemChecked(menu->getSelectedItem()-2, true);
menu->setItemChecked(menu->getSelectedItem()-3, true);
menu->setItemChecked(menu->getSelectedItem()-4, true);
menu->setItemChecked(menu->getSelectedItem()-5, true);
menu->setItemChecked(menu->getSelectedItem()-6, true);
if (Model)
break;
case GUI_ID_ABOUT:
showAboutText();
break;
case GUI_ID_MODEL_MATERIAL_SOLID:
if (Model)
break;
case GUI_ID_MODEL_MATERIAL_TRANSPARENT:
if (Model)
break;
case GUI_ID_MODEL_MATERIAL_REFLECTION:
if (Model)
break;
case GUI_ID_CAMERA_MAYA:
setActiveCamera(Camera[0]);
break;
case GUI_ID_CAMERA_FIRST_PERSON:
setActiveCamera(Camera[1]);
break;
}
}
virtual void closeDevice()=0
Notifies the device that it should close itself.
virtual IGUIFileOpenDialog * addFileOpenDialog(const wchar_t *title=0, bool modal=true, IGUIElement *parent=0, s32 id=-1, bool restoreCWD=false, io::path::char_type *startDir=0)=0
Adds a file open dialog.
virtual void setVisible(bool isVisible)
Sets if the node should be visible or not.
void setMaterialType(video::E_MATERIAL_TYPE newType)
Sets the material type of all materials in this scene node to a new material type.
virtual bool isVisible() const
Returns whether the node should be visible (if all of its parents are visible).
u32 isDebugDataVisible() const
Returns if debug data like bounding boxes are drawn.
E_DEBUG_SCENE_TYPE
An enumeration for all types of debug data for built-in scene nodes (flags)
Handle the event that one of the texture-filters was selected in the corresponding combobox.
void OnTextureFilterSelected( IGUIComboBox* combo )
{
s32 pos = combo->getSelected();
switch (pos)
{
case 0:
if (Model)
{
}
break;
case 1:
if (Model)
{
}
break;
case 2:
if (Model)
{
}
break;
case 3:
if (Model)
{
}
break;
case 4:
if (Model)
{
}
break;
}
}
};
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. As you can see, there is also a call to IrrlichtDevice::setResizeable(). This makes the render window resizeable, which is quite useful for a mesh viewer.
int main(int argc, char* argv[])
{
if (driverType==video::EDT_COUNT)
return 1;
MyEventReceiver receiver;
16, false, false, false, &receiver);
if (Device == 0)
return 1;
virtual void setWindowCaption(const wchar_t *text)=0
Sets the caption of the window.
virtual void setResizable(bool resize=false)=0
Sets if the window should be resizable in windowed mode.
virtual void setAttribute(const c8 *attributeName, s32 value)=0
Sets an attribute as integer value.
The Scene Manager manages scene nodes, mesh recources, cameras and all the other stuff.
virtual void setAmbientLight(const video::SColorf &ambientColor)=0
Sets ambient color of the scene.
virtual io::IAttributes * getParameters()=0
Get interface to the parameters set in this scene.
virtual ILightSceneNode * addLightSceneNode(ISceneNode *parent=0, const core::vector3df &position=core::vector3df(0, 0, 0), video::SColorf color=video::SColorf(1.0f, 1.0f, 1.0f), f32 radius=100.0f, s32 id=-1)=0
Adds a dynamic light scene node to the scene graph.
Interface to driver which is able to perform 2d and 3d graphics functions.
virtual void setTextureCreationFlag(E_TEXTURE_CREATION_FLAG flag, bool enabled=true)=0
Enables or disables a texture creation flag.
Class representing a color with four floats.
E_DRIVER_TYPE
An enum for all types of drivers the Irrlicht Engine supports.
The next step is to read the configuration file. It is stored in the xml format and looks a little bit like this:
<?xml version="1.0"?>
<config>
<startUpModel file="some filename" />
<messageText caption="Irrlicht Engine Mesh Viewer">
Hello!
</messageText>
</config>
We need the data stored in there to be written into the global variables StartUpModelFile, MessageText and Caption. This is now done using the Irrlicht Engine integrated XML parser:
while(xml && xml->
read())
{
{
case io::EXN_TEXT:
break;
case io::EXN_ELEMENT:
{
else
}
break;
default:
break;
}
}
if (xml)
xml->drop();
if (argc > 1)
StartUpModelFile = argv[1];
virtual IXMLReader * createXMLReader(const path &filename)=0
Creates a XML Reader from a file which returns all parsed strings as wide characters (wchar_t*).
Interface providing easy read access to a XML file.
virtual bool read()=0
Reads forward to the next xml node.
virtual EXML_NODE getNodeType() const =0
Returns the type of the current XML node.
virtual const char_type * getNodeName() const =0
Returns the name of the current node.
virtual const char_type * getAttributeValue(int idx) const =0
Returns the value of an attribute.
virtual const char_type * getNodeData() const =0
Returns data of the current node.
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.
IGUISkin* skin = env->getSkin();
IGUIFont* font = env->
getFont(
"fonthaettenschweiler.bmp");
if (font)
skin->setFont(font);
menu->
addItem(L
"File", -1,
true,
true);
menu->
addItem(L
"View", -1,
true,
true);
menu->
addItem(L
"Camera", -1,
true,
true);
menu->
addItem(L
"Help", -1,
true,
true);
submenu->
addItem(L
"Open Model File & Texture...", GUI_ID_OPEN_MODEL);
submenu->
addItem(L
"Set Model Archive...", GUI_ID_SET_MODEL_ARCHIVE);
submenu->
addItem(L
"Load as Octree", GUI_ID_LOAD_AS_OCTREE);
submenu->
addItem(L
"Quit", GUI_ID_QUIT);
submenu->
addItem(L
"sky box visible", GUI_ID_SKY_BOX_VISIBLE,
true,
false,
true);
submenu->
addItem(L
"toggle model debug information", GUI_ID_TOGGLE_DEBUG_INFO,
true,
true);
submenu->
addItem(L
"model material", -1,
true,
true );
submenu->
addItem(L
"Off", GUI_ID_DEBUG_OFF);
submenu->
addItem(L
"Bounding Box", GUI_ID_DEBUG_BOUNDING_BOX);
submenu->
addItem(L
"Normals", GUI_ID_DEBUG_NORMALS);
submenu->
addItem(L
"Skeleton", GUI_ID_DEBUG_SKELETON);
submenu->
addItem(L
"Wire overlay", GUI_ID_DEBUG_WIRE_OVERLAY);
submenu->
addItem(L
"Half-Transparent", GUI_ID_DEBUG_HALF_TRANSPARENT);
submenu->
addItem(L
"Buffers bounding boxes", GUI_ID_DEBUG_BUFFERS_BOUNDING_BOXES);
submenu->
addItem(L
"All", GUI_ID_DEBUG_ALL);
submenu->
addItem(L
"Solid", GUI_ID_MODEL_MATERIAL_SOLID);
submenu->
addItem(L
"Transparent", GUI_ID_MODEL_MATERIAL_TRANSPARENT);
submenu->
addItem(L
"Reflection", GUI_ID_MODEL_MATERIAL_REFLECTION);
submenu->
addItem(L
"Maya Style", GUI_ID_CAMERA_MAYA);
submenu->
addItem(L
"First Person", GUI_ID_CAMERA_FIRST_PERSON);
submenu->
addItem(L
"About", GUI_ID_ABOUT);
virtual IGUIFont * getFont(EGUI_DEFAULT_FONT which=EGDF_DEFAULT) const =0
returns the default font
Below the menu we want a toolbar, onto which we can place colored buttons and important looking stuff like a senseless combobox.
bar->
addButton(GUI_ID_BUTTON_OPEN_MODEL, 0, L
"Open a model",image, 0,
false,
true);
bar->
addButton(GUI_ID_BUTTON_SHOW_TOOLBOX, 0, L
"Open Toolset",image, 0,
false,
true);
bar->
addButton(GUI_ID_BUTTON_SELECT_ARCHIVE, 0, L
"Set Model Archive",image, 0,
false,
true);
bar->
addButton(GUI_ID_BUTTON_SHOW_ABOUT, 0, L
"Open Help", image, 0,
false,
true);
virtual u32 addItem(const wchar_t *text, u32 data=0)=0
Adds an item and returns the index of it.
To make the editor look a little bit better, we disable transparent gui elements, and add an Irrlicht Engine logo. In addition, a text showing the current frames per second value is created and the window caption is changed.
for (
s32 i=0; i<gui::EGDC_COUNT ; ++i)
{
}
createToolBox();
IGUIStaticText* fpstext = env->addStaticText(L"",
IGUIStaticText* postext = env->addStaticText(L"",
postext->setVisible(false);
Caption += " - [";
Caption += "]";
virtual const wchar_t * getName() const =0
Gets name of this video driver.
EGUI_DEFAULT_COLOR
Enumeration for skin colors.
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 controlled camera, to make the application a little bit more interactive. Finally, everything is drawn in a standard drawing loop.
if (argc==1)
showAboutText();
loadModel(StartUpModelFile.c_str());
setActiveCamera(Camera[0]);
IGUIImage *img =
env->addImage(driver->
getTexture(
"irrlichtlogo2.png"),
img->setAlignment(EGUIA_UPPERLEFT, EGUIA_UPPERLEFT,
EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT);
while(Device->
run() && driver)
{
if ( hasFocus && !focused )
onKillFocus();
hasFocus = focused;
{
env->drawAll();
str += L" Tris: ";
fpstext->setText(str.c_str());
str = L"Pos: ";
str += L" ";
str += L" ";
str += L" Tgt: ";
str += L" ";
str += L" ";
postext->setText(str.c_str());
updateToolBox();
}
else
}
return 0;
}
bool drop() const
Drops the object. Decrements the reference counter by one.
virtual bool run()=0
Runs the device.
virtual void yield()=0
Cause the device to temporarily pause execution and let other processes run.
virtual bool isWindowFocused() const =0
Checks if the Irrlicht window has the input focus.
virtual bool isWindowActive() const =0
Returns if the window is active.
T Height
Height of the dimension.
virtual const core::vector3df & getTarget() const =0
Gets the current look at target of the camera.
virtual void setTarget(const core::vector3df &pos)=0
Sets the look at target of the camera.
virtual void setFarValue(f32 zf)=0
Sets the value of the far clipping plane (default: 2000.0f)
virtual void drawAll()=0
Draws all the scene nodes.
virtual ISceneNode * addSkyBoxSceneNode(video::ITexture *top, video::ITexture *bottom, video::ITexture *left, video::ITexture *right, video::ITexture *front, video::ITexture *back, ISceneNode *parent=0, s32 id=-1)=0
Adds a skybox scene node to the scene graph.
virtual ICameraSceneNode * addCameraSceneNodeFPS(ISceneNode *parent=0, f32 rotateSpeed=100.0f, f32 moveSpeed=0.5f, s32 id=-1, SKeyMap *keyMapArray=0, s32 keyMapSize=0, bool noVerticalMovement=false, f32 jumpSpeed=0.f, bool invertMouse=false, bool makeActive=true)=0
Adds a camera scene node with an animator which provides mouse and keyboard control appropriate for f...
virtual ICameraSceneNode * addCameraSceneNodeMaya(ISceneNode *parent=0, f32 rotateSpeed=-1500.f, f32 zoomSpeed=200.f, f32 translationSpeed=1500.f, s32 id=-1, f32 distance=70.f, bool makeActive=true)=0
Adds a maya style user controlled camera scene node to the scene graph.
virtual void setPosition(const core::vector3df &newpos)
Sets the position of the node relative to its parent.
virtual const core::vector3df & getPosition() const
Gets the position of the node relative to its parent.
virtual bool beginScene(bool backBuffer=true, bool zBuffer=true, SColor color=SColor(255, 0, 0, 0), const SExposedVideoData &videoData=SExposedVideoData(), core::rect< s32 > *sourceRect=0)=0
Applications must call this method before performing any rendering.
virtual u32 getPrimitiveCountDrawn(u32 mode=0) const =0
Returns amount of primitives (mostly triangles) which were drawn in the last frame.
virtual s32 getFPS() const =0
Returns current frames per second value.
virtual bool endScene()=0
Presents the rendered image to the screen.
virtual const core::dimension2d< u32 > & getScreenSize() const =0
Get the size of the screen or render window.