Code is here:
Code: Select all
#include <irrlicht.h>
#include <iostream>
using namespace irr;
using namespace scene;
using namespace io;
using namespace gui;
using namespace video;
using namespace core;
#pragma comment(lib, "Irrlicht.lib")
IrrlichtDevice* device = 0;
class MyEventReceiver : public IEventReceiver
{
public:
virtual bool OnEvent(SEvent event)
{
if (event.EventType == EET_GUI_EVENT)
{
s32 id = event.GUIEvent.Caller->getID();
IGUIEnvironment* env = device->getGUIEnvironment();
switch(event.GUIEvent.EventType)
{
case EGET_BUTTON_CLICKED:
if (id == 105)
{
device->closeDevice();
return true;
}
break;
}
}
return false;
}
};
int main()
{
E_DRIVER_TYPE driverType = EDT_OPENGL;
IrrlichtDevice* device = createDevice(driverType, dimension2d<s32>(1024, 768), 32, true);
if (device == 0)
return 1;
MyEventReceiver receiver;
device->setEventReceiver(&receiver);
IVideoDriver* driver = device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();
IGUIEnvironment* env = device->getGUIEnvironment();
env->addButton(rect<s32>(50,200,200,240), 0, 101, L"Uus mang"); //New game
env->addButton(rect<s32>(50,250,200,290), 0, 102, L"Lae mang"); //Load game
env->addButton(rect<s32>(50,300,200,340), 0, 103, L"Seaded"); //Options
env->addButton(rect<s32>(50,350,200,390), 0, 105, L"Valja"); //Quit
IGUIImage* img = env->addImage(driver->getTexture("/dev-cpp/mang/irrlichtlogoalpha.tga"), position2d<int>(10,700));
IGUISkin* skin = env->getSkin();
IGUIFont* font = env->getFont("/dev-cpp/mang/font/fontcourier.bmp");
if (font)
skin->setFont(font);
while(device->run() && driver)
if (device->isWindowActive())
{
driver->beginScene(true, true, SColor(0,200,200,200));
env->drawAll();
driver->endScene();
}
device->drop();
return 0;
}