Code: Select all
#include <irrlicht.h>
#pragma comment(lib, "Irrlicht.lib")
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
bool resize = false, stop = false;
int width = 640, height = 480, bpp = 16;
class Receiver : public IEventReceiver
{
protected:
virtual bool OnEvent (const SEvent& event);
};
bool Receiver::OnEvent (const SEvent& event)
{
if (event.EventType == EET_KEY_INPUT_EVENT)
{
if (event.KeyInput.Key == KEY_ESCAPE && event.KeyInput.PressedDown)
{
stop = true;
return true;
}
else if (event.KeyInput.Key == KEY_SPACE && event.KeyInput.PressedDown)
{
width = 800, height = 600, bpp = 32;
resize = true;
return true;
}
}
return false;
}
int main (void)
{
Receiver* receiver = NULL;
while (!stop)
{
IrrlichtDevice* device = createDevice (EDT_OPENGL, dimension2d<s32>(width, height), bpp, false, false, false, NULL);
if (!device)
return 0;
IVideoDriver* driver = device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();
receiver = new Receiver;
device->setEventReceiver(receiver);
while (device->run() && !resize)
{
driver->beginScene(true, true, SColor(255,100,101,140));
smgr->drawAll();
driver->endScene();
}
resize = false;
if (receiver)
{
delete receiver;
receiver = NULL;
}
if (device)
{
device->closeDevice();
device->run(); // Very important to do this here!
device->drop();
}
}
return 0;
}