Irrlicht 3D Engine
 
Loading...
Searching...
No Matches
Tutorial 11: Per-Pixel Lighting

This tutorial shows how to use one of the built in more complex materials in irrlicht: Per pixel lighted surfaces using normal maps and parallax mapping. It will also show how to use fog and moving particle systems. And don't panic: You do not need any experience with shaders to use these materials in Irrlicht.

At first, we need to include all headers and do the stuff we always do, like in nearly all other tutorials.

#include <irrlicht.h>
#include "driverChoice.h"
using namespace irr;
#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.
Definition aabbox3d.h:13

For this example, we need an event receiver, to make it possible for the user to switch between the three available material types. In addition, the event receiver will create some small GUI window which displays what material is currently being used. There is nothing special done in this class, so maybe you want to skip reading it.

class MyEventReceiver : public IEventReceiver
{
public:
MyEventReceiver(scene::ISceneNode* room,scene::ISceneNode* earth,
{
// store pointer to room so we can change its drawing mode
Room = room;
Earth = earth;
Driver = driver;
// set a nicer font
gui::IGUISkin* skin = env->getSkin();
gui::IGUIFont* font = env->getFont("../../media/fonthaettenschweiler.bmp");
if (font)
skin->setFont(font);
// add window and listbox
gui::IGUIWindow* window = env->addWindow(
core::rect<s32>(460,375,630,470), false, L"Use 'E' + 'R' to change");
ListBox = env->addListBox(
core::rect<s32>(2,22,165,88), window);
ListBox->addItem(L"Diffuse");
ListBox->addItem(L"Bump mapping");
ListBox->addItem(L"Parallax mapping");
ListBox->setSelected(1);
// create problem text
ProblemText = env->addStaticText(
L"Your hardware or this renderer is not able to use the "\
L"needed shaders for this material. Using fall back materials.",
core::rect<s32>(150,20,470,80));
ProblemText->setOverrideColor(video::SColor(100,255,255,255));
// set start material (prefer parallax mapping if available)
Driver->getMaterialRenderer(video::EMT_PARALLAX_MAP_SOLID);
if (renderer && renderer->getRenderCapability() == 0)
ListBox->setSelected(2);
// set the material which is selected in the listbox
setMaterial();
}
bool OnEvent(const SEvent& event)
{
// check if user presses the key 'E' or 'R'
!event.KeyInput.PressedDown && Room && ListBox)
{
// change selected item in listbox
int sel = ListBox->getSelected();
if (event.KeyInput.Key == irr::KEY_KEY_R)
++sel;
else
if (event.KeyInput.Key == irr::KEY_KEY_E)
--sel;
else
return false;
if (sel > 2) sel = 0;
if (sel < 0) sel = 2;
ListBox->setSelected(sel);
// set the material which is selected in the listbox
setMaterial();
}
return false;
}
private:
// sets the material of the room mesh the the one set in the
// list box.
void setMaterial()
{
video::E_MATERIAL_TYPE type = video::EMT_SOLID;
// change material setting
switch(ListBox->getSelected())
{
case 0: type = video::EMT_SOLID;
break;
case 1: type = video::EMT_NORMAL_MAP_SOLID;
break;
case 2: type = video::EMT_PARALLAX_MAP_SOLID;
break;
}
Room->setMaterialType(type);
// change material setting
switch(ListBox->getSelected())
{
case 0: type = video::EMT_TRANSPARENT_VERTEX_ALPHA;
break;
case 1: type = video::EMT_NORMAL_MAP_TRANSPARENT_VERTEX_ALPHA;
break;
case 2: type = video::EMT_PARALLAX_MAP_TRANSPARENT_VERTEX_ALPHA;
break;
}
Earth->setMaterialType(type);
Interface of an object which can receive events.
Axis aligned bounding box in 3d dimensional space.
Definition aabbox3d.h:22
GUI Environment. Used as factory and manager of all other GUI elements.
virtual IGUIFont * getFont(const io::path &filename)=0
Returns pointer to the font with the specified filename.
virtual IGUIListBox * addListBox(const core::rect< s32 > &rectangle, IGUIElement *parent=0, s32 id=-1, bool drawBackground=false)=0
Adds a list box element.
virtual IGUIStaticText * addStaticText(const wchar_t *text, const core::rect< s32 > &rectangle, bool border=false, bool wordWrap=true, IGUIElement *parent=0, s32 id=-1, bool fillBackground=false)=0
Adds a static text.
virtual IGUISkin * getSkin() const =0
Returns pointer to the current gui skin.
virtual IGUIWindow * addWindow(const core::rect< s32 > &rectangle, bool modal=false, const wchar_t *text=0, IGUIElement *parent=0, s32 id=-1)=0
Adds an empty window element.
Font interface.
Definition IGUIFont.h:40
virtual u32 addItem(const wchar_t *text)=0
adds an list item, returns id of item
A skin modifies the look of the GUI elements.
Definition IGUISkin.h:379
virtual void setFont(IGUIFont *font, EGUI_DEFAULT_FONT which=EGDF_DEFAULT)=0
sets a default font
virtual void setOverrideColor(video::SColor color)=0
Sets another color for the text.
Default moveable window GUI element with border, caption and close icons.
Definition IGUIWindow.h:22
Scene node interface.
Definition ISceneNode.h:41
Interface for material rendering.
virtual s32 getRenderCapability() const
Returns the render capability of the material.
Interface to driver which is able to perform 2d and 3d graphics functions.
Class representing a 32 bit ARGB color.
Definition SColor.h:202
E_MATERIAL_TYPE
Abstracted and easy to use fixed function/programmable pipeline material modes.
@ KEY_KEY_R
Definition Keycodes.h:83
@ KEY_KEY_E
Definition Keycodes.h:70
@ EET_KEY_INPUT_EVENT
A key input event.
EKEY_CODE Key
Key which has been pressed or released.
bool PressedDown
If not true, then the key was left up.
SEvents hold information about an event. See irr::IEventReceiver for details on event handling.
EEVENT_TYPE EventType
struct SKeyInput KeyInput

We need to add a warning if the materials will not be able to be displayed 100% correctly. This is no problem, they will be rendered using fall back materials, but at least the user should know that it would look better on better hardware. We simply check if the material renderer is able to draw at full quality on the current hardware. The IMaterialRenderer::getRenderCapability() returns 0 if this is the case.

video::IMaterialRenderer* renderer = Driver->getMaterialRenderer(type);
// display some problem text when problem
if (!renderer || renderer->getRenderCapability() != 0)
ProblemText->setVisible(true);
else
ProblemText->setVisible(false);
}
private:
gui::IGUIStaticText* ProblemText;
gui::IGUIListBox* ListBox;
};
Default list box GUI element.
Definition IGUIListBox.h:39
Multi or single line text label.

Now for the real fun. We create an Irrlicht Device and start to setup the scene.

int main()
{
// ask user for driver
video::E_DRIVER_TYPE driverType=driverChoiceConsole();
if (driverType==video::EDT_COUNT)
return 1;
// create device
IrrlichtDevice* device = createDevice(driverType,
if (device == 0)
return 1; // could not create selected driver.
The Irrlicht device. You can create it with createDevice() or createDeviceEx().
E_DRIVER_TYPE
An enum for all types of drivers the Irrlicht Engine supports.

Before we start with the interesting stuff, we do some simple things: Store pointers to the most important parts of the engine (video driver, scene manager, gui environment) to safe us from typing too much, add an irrlicht engine logo to the window and a user controlled first person shooter style camera. Also, we let the engine know that it should store all textures in 32 bit. This necessary because for parallax mapping, we need 32 bit textures.

video::IVideoDriver* driver = device->getVideoDriver();
driver->setTextureCreationFlag(video::ETCF_ALWAYS_32_BIT, true);
// add irrlicht logo
env->addImage(driver->getTexture("../../media/irrlichtlogo3.png"),
// add camera
camera->setPosition(core::vector3df(-200,200,-200));
// disable mouse cursor
device->getCursorControl()->setVisible(false);
virtual gui::ICursorControl * getCursorControl()=0
Provides access to the cursor control.
virtual scene::ISceneManager * getSceneManager()=0
Provides access to the scene manager.
virtual video::IVideoDriver * getVideoDriver()=0
Provides access to the video driver for drawing 3d and 2d geometry.
virtual gui::IGUIEnvironment * getGUIEnvironment()=0
Provides access to the 2d user interface environment.
virtual void setVisible(bool visible)=0
Changes the visible state of the mouse cursor.
virtual IGUIImage * addImage(video::ITexture *image, core::position2d< s32 > pos, bool useAlphaChannel=true, IGUIElement *parent=0, s32 id=-1, const wchar_t *text=0)=0
Adds an image element.
Scene Node which is a (controlable) camera.
The Scene Manager manages scene nodes, mesh recources, cameras and all the other stuff.
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 void setPosition(const core::vector3df &newpos)
Sets the position of the node relative to its parent.
Definition ISceneNode.h:507
virtual ITexture * getTexture(const io::path &filename)=0
Get access to a named texture.
virtual void setTextureCreationFlag(E_TEXTURE_CREATION_FLAG flag, bool enabled=true)=0
Enables or disables a texture creation flag.

Because we want the whole scene to look a little bit scarier, we add some fog to it. This is done by a call to IVideoDriver::setFog(). There you can set various fog settings. In this example, we use pixel fog, because it will work well with the materials we'll use in this example. Please note that you will have to set the material flag EMF_FOG_ENABLE to 'true' in every scene node which should be affected by this fog.

driver->setFog(video::SColor(0,138,125,81), video::EFT_FOG_LINEAR, 250, 1000, .003f, true, false);
virtual void setFog(SColor color=SColor(0, 255, 255, 255), E_FOG_TYPE fogType=EFT_FOG_LINEAR, f32 start=50.0f, f32 end=100.0f, f32 density=0.01f, bool pixelFog=false, bool rangeFog=false)=0
Sets the fog mode.

To be able to display something interesting, we load a mesh from a .3ds file which is a room I modeled with anim8or. It is the same room as from the specialFX example. Maybe you remember from that tutorial, I am no good modeler at all and so I totally messed up the texture mapping in this model, but we can simply repair it with the IMeshManipulator::makePlanarTextureMapping() method.

scene::IAnimatedMesh* roomMesh = smgr->getMesh("../../media/room.3ds");
scene::ISceneNode* earth = 0;
if (roomMesh)
{
// The Room mesh doesn't have proper Texture Mapping on the
// floor, so we can recreate them on runtime
roomMesh->getMesh(0), 0.003f);
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.
virtual void makePlanarTextureMapping(IMesh *mesh, f32 resolution=0.001f) const =0
Creates a planar texture mapping on the mesh.
virtual IAnimatedMesh * getMesh(const io::path &filename)=0
Get pointer to an animateable mesh. Loads the file if not loaded already.
virtual IMeshManipulator * getMeshManipulator()=0
Get pointer to the mesh manipulator.

Now for the first exciting thing: If we successfully loaded the mesh we need to apply textures to it. Because we want this room to be displayed with a very cool material, we have to do a little bit more than just set the textures. Instead of only loading a color map as usual, we also load a height map which is simply a grayscale texture. From this height map, we create a normal map which we will set as second texture of the room. If you already have a normal map, you could directly set it, but I simply didn't find a nice normal map for this texture. The normal map texture is being generated by the makeNormalMapTexture method of the VideoDriver. The second parameter specifies the height of the heightmap. If you set it to a bigger value, the map will look more rocky.

video::ITexture* normalMap =
driver->getTexture("../../media/rockwall_height.bmp");
if (normalMap)
driver->makeNormalMapTexture(normalMap, 9.0f);
Interface of a Video Driver dependent Texture.
Definition ITexture.h:99
virtual void makeNormalMapTexture(video::ITexture *texture, f32 amplitude=1.0f) const =0
Creates a normal map from a height map texture.

The Normal Map and the displacement map/height map in the alpha channel video::ITexture* normalMap = driver->getTexture("../../media/rockwall_NRM.tga");

But just setting color and normal map is not everything. The material we want to use needs some additional informations per vertex like tangents and binormals. Because we are too lazy to calculate that information now, we let Irrlicht do this for us. That's why we call IMeshManipulator::createMeshWithTangents(). It creates a mesh copy with tangents and binormals from another mesh. After we've done that, we simply create a standard mesh scene node with this mesh copy, set color and normal map and adjust some other material settings. Note that we set EMF_FOG_ENABLE to true to enable fog in the room.

scene::IMesh* tangentMesh = smgr->getMeshManipulator()->
createMeshWithTangents(roomMesh->getMesh(0));
room = smgr->addMeshSceneNode(tangentMesh);
driver->getTexture("../../media/rockwall.jpg"));
room->setMaterialTexture(1, normalMap);
// Stones don't glitter..
room->getMaterial(0).SpecularColor.set(0,0,0,0);
room->getMaterial(0).Shininess = 0.f;
room->setMaterialFlag(video::EMF_FOG_ENABLE, true);
room->setMaterialType(video::EMT_PARALLAX_MAP_SOLID);
// adjust height for parallax effect
room->getMaterial(0).MaterialTypeParam = 1.f / 64.f;
// drop mesh because we created it with a create.. call.
tangentMesh->drop();
}
bool drop() const
Drops the object. Decrements the reference counter by one.
Class which holds the geometry of an object.
Definition IMesh.h:24
virtual IMeshSceneNode * addMeshSceneNode(IMesh *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 a static mesh.
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.
Definition ISceneNode.h:436
void setMaterialFlag(video::E_MATERIAL_FLAG flag, bool newvalue)
Sets all material flags at once to a new value.
Definition ISceneNode.h:425
void setMaterialType(video::E_MATERIAL_TYPE newType)
Sets the material type of all materials in this scene node to a new material type.
Definition ISceneNode.h:448
virtual video::SMaterial & getMaterial(u32 num)
Returns the material based on the zero based index i.
Definition ISceneNode.h:406
void set(u32 a, u32 r, u32 g, u32 b)
Sets all four components of the color at once.
Definition SColor.h:307
SColor SpecularColor
How much specular light (highlights from a light) is reflected.
Definition SMaterial.h:318
f32 Shininess
Value affecting the size of specular highlights.
Definition SMaterial.h:350
f32 MaterialTypeParam
Free parameter, dependent on the material type.
Definition SMaterial.h:355

After we've created a room shaded by per pixel lighting, we add a sphere into it with the same material, but we'll make it transparent. In addition, because the sphere looks somehow like a familiar planet, we make it rotate. The procedure is similar as before. The difference is that we are loading the mesh from an .x file which already contains a color map so we do not need to load it manually. But the sphere is a little bit too small for our needs, so we scale it by the factor 50.

// add earth sphere
scene::IAnimatedMesh* earthMesh = smgr->getMesh("../../media/earth.x");
if (earthMesh)
{
//perform various task with the mesh manipulator
// create mesh copy with tangent informations from original earth.x mesh
scene::IMesh* tangentSphereMesh =
manipulator->createMeshWithTangents(earthMesh->getMesh(0));
// set the alpha value of all vertices to 200
manipulator->setVertexColorAlpha(tangentSphereMesh, 200);
// scale the mesh by factor 50
m.setScale ( core::vector3df(50,50,50) );
manipulator->transform( tangentSphereMesh, m );
earth = smgr->addMeshSceneNode(tangentSphereMesh);
earth->setPosition(core::vector3df(-70,130,45));
// load heightmap, create normal map from it and set it
video::ITexture* earthNormalMap = driver->getTexture("../../media/earthbump.jpg");
if (earthNormalMap)
{
driver->makeNormalMapTexture(earthNormalMap, 20.0f);
earth->setMaterialTexture(1, earthNormalMap);
earth->setMaterialType(video::EMT_NORMAL_MAP_TRANSPARENT_VERTEX_ALPHA);
}
// adjust material settings
earth->setMaterialFlag(video::EMF_FOG_ENABLE, true);
// add rotation animator
earth->addAnimator(anim);
anim->drop();
// drop mesh because we created it with a create.. call.
tangentSphereMesh->drop();
}
4x4 matrix. Mostly used as transformation matrix for 3d calculations.
Definition matrix4.h:46
CMatrix4< T > & setScale(const vector3d< T > &scale)
Set Scale.
Definition matrix4.h:775
An interface for easy manipulation of meshes.
void setVertexColorAlpha(IMesh *mesh, s32 alpha) const
Sets the alpha vertex color value of the whole mesh to a new value.
void transform(IMesh *mesh, const core::matrix4 &m) const
Applies a transformation to a mesh.
virtual IMesh * createMeshWithTangents(IMesh *mesh, bool recalculateNormals=false, bool smooth=false, bool angleWeighted=false, bool recalculateTangents=true) const =0
Creates a copy of the mesh, which will only consist of S3DVertexTangents vertices.
virtual ISceneNodeAnimator * createRotationAnimator(const core::vector3df &rotationSpeed)=0
Creates a rotation animator, which rotates the attached scene node around itself.
Animates a scene node. Can animate position, rotation, material, and so on.
virtual void addAnimator(ISceneNodeAnimator *animator)
Adds an animator which should animate this node.
Definition ISceneNode.h:348

Per pixel lighted materials only look cool when there are moving lights. So we add some. And because moving lights alone are so boring, we add billboards to them, and a whole particle system to one of them. We start with the first light which is red and has only the billboard attached.

// add light 1 (more green)
video::SColorf(0.5f, 1.0f, 0.5f, 0.0f), 800.0f);
light1->setDebugDataVisible ( scene::EDS_BBOX );
// add fly circle animator to light 1
smgr->createFlyCircleAnimator (core::vector3df(50,300,0),190.0f, -0.003f);
light1->addAnimator(anim);
anim->drop();
// attach billboard to the light
bill->setMaterialFlag(video::EMF_LIGHTING, false);
bill->setMaterialFlag(video::EMF_ZWRITE_ENABLE, false);
bill->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR);
bill->setMaterialTexture(0, driver->getTexture("../../media/particlegreen.jpg"));
Scene node which is a dynamic light.
virtual IBillboardSceneNode * addBillboardSceneNode(ISceneNode *parent=0, const core::dimension2d< f32 > &size=core::dimension2d< f32 >(10.0f, 10.0f), const core::vector3df &position=core::vector3df(0, 0, 0), s32 id=-1, video::SColor colorTop=0xFFFFFFFF, video::SColor colorBottom=0xFFFFFFFF)=0
Adds a billboard scene node to the scene graph.
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.
virtual ISceneNodeAnimator * createFlyCircleAnimator(const core::vector3df &center=core::vector3df(0.f, 0.f, 0.f), f32 radius=100.f, f32 speed=0.001f, const core::vector3df &direction=core::vector3df(0.f, 1.f, 0.f), f32 startPosition=0.f, f32 radiusEllipsoid=0.f)=0
Creates a fly circle animator, which lets the attached scene node fly around a center.
virtual void setDebugDataVisible(u32 state)
Sets if debug data like bounding boxes should be drawn.
Definition ISceneNode.h:552
Class representing a color with four floats.
Definition SColor.h:459

Now the same again, with the second light. The difference is that we add a particle system to it too. And because the light moves, the particles of the particlesystem will follow. If you want to know more about how particle systems are created in Irrlicht, take a look at the specialFx example. Maybe you will have noticed that we only add 2 lights, this has a simple reason: The low end version of this material was written in ps1.1 and vs1.1, which doesn't allow more lights. You could add a third light to the scene, but it won't be used to shade the walls. But of course, this will change in future versions of Irrlicht where higher versions of pixel/vertex shaders will be implemented too.

// add light 2 (red)
video::SColorf(1.0f, 0.2f, 0.2f, 0.0f), 800.0f);
// add fly circle animator to light 2
anim = smgr->createFlyCircleAnimator(core::vector3df(0,150,0), 200.0f,
0.001f, core::vector3df(0.2f, 0.9f, 0.f));
light2->addAnimator(anim);
anim->drop();
// attach billboard to light
bill = smgr->addBillboardSceneNode(light2, core::dimension2d<f32>(120, 120));
bill->setMaterialFlag(video::EMF_LIGHTING, false);
bill->setMaterialFlag(video::EMF_ZWRITE_ENABLE, false);
bill->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR);
bill->setMaterialTexture(0, driver->getTexture("../../media/particlered.bmp"));
// add particle system
smgr->addParticleSystemSceneNode(false, light2);
// create and set emitter
core::aabbox3d<f32>(-3,0,-3,3,1,3),
core::vector3df(0.0f,0.03f,0.0f),
80,100,
video::SColor(10,255,255,255), video::SColor(10,255,255,255),
400,1100);
ps->setEmitter(em);
em->drop();
// create and set affector
ps->addAffector(paf);
paf->drop();
// adjust some material settings
ps->setMaterialFlag(video::EMF_LIGHTING, false);
ps->setMaterialFlag(video::EMF_ZWRITE_ENABLE, false);
ps->setMaterialTexture(0, driver->getTexture("../../media/fireball.bmp"));
ps->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR);
MyEventReceiver receiver(room, earth, env, driver);
device->setEventReceiver(&receiver);
virtual void setEventReceiver(IEventReceiver *receiver)=0
Sets a new user event receiver which will receive events from the engine.
A particle affector modifies particles.
A particle emitter for using with particle systems.
virtual void setMinStartSize(const core::dimension2df &size)=0
Set the minimum starting size for particles.
virtual void setMaxStartSize(const core::dimension2df &size)=0
Set the maximum starting size for particles.
A particle system scene node for creating snow, fire, exlosions, smoke...
virtual IParticleFadeOutAffector * createFadeOutParticleAffector(const video::SColor &targetColor=video::SColor(0, 0, 0, 0), u32 timeNeededToFadeOut=1000)=0
Creates a fade out particle affector.
virtual void addAffector(IParticleAffector *affector)=0
Adds new particle effector to the particle system.
virtual IParticleBoxEmitter * createBoxEmitter(const core::aabbox3df &box=core::aabbox3df(-10, 28,-10, 10, 30, 10), const core::vector3df &direction=core::vector3df(0.0f, 0.03f, 0.0f), u32 minParticlesPerSecond=5, u32 maxParticlesPerSecond=10, const video::SColor &minStartColor=video::SColor(255, 0, 0, 0), const video::SColor &maxStartColor=video::SColor(255, 255, 255, 255), u32 lifeTimeMin=2000, u32 lifeTimeMax=4000, s32 maxAngleDegrees=0, const core::dimension2df &minStartSize=core::dimension2df(5.0f, 5.0f), const core::dimension2df &maxStartSize=core::dimension2df(5.0f, 5.0f))=0
Creates a box particle emitter.
virtual void setEmitter(IParticleEmitter *emitter)=0
Sets the particle emitter, which creates the particles.
virtual IParticleSystemSceneNode * addParticleSystemSceneNode(bool withDefaultEmitter=true, 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))=0
Adds a particle system scene node to the scene graph.

Finally, draw everything. That's it.

int lastFPS = -1;
while(device->run())
if (device->isWindowActive())
{
driver->beginScene(true, true, 0);
smgr->drawAll();
env->drawAll();
driver->endScene();
int fps = driver->getFPS();
if (lastFPS != fps)
{
core::stringw str = L"Per pixel lighting example - Irrlicht Engine [";
str += driver->getName();
str += "] FPS:";
str += fps;
device->setWindowCaption(str.c_str());
lastFPS = fps;
}
}
device->drop();
return 0;
}
virtual bool run()=0
Runs the device.
virtual void setWindowCaption(const wchar_t *text)=0
Sets the caption of the window.
virtual bool isWindowActive() const =0
Returns if the window is active.
virtual void drawAll()=0
Draws all gui elements by traversing the GUI environment starting at the root node.
virtual void drawAll()=0
Draws all the scene nodes.
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 s32 getFPS() const =0
Returns current frames per second value.
virtual const wchar_t * getName() const =0
Gets name of this video driver.
virtual bool endScene()=0
Presents the rendered image to the screen.