Code: Select all
#include <iostream.h>
#include <irrlicht.h>
#include "definitions.h"
#pragma comment(lib, "Irrlicht.lib")
using namespace irr;
//////////////////////////////
//Globals
//////////////////////////////
IrrlichtDevice* device = NULL;
video::IVideoDriver* driver = NULL;
scene::ISceneManager* smgr = NULL;
gui::IGUIEnvironment* guienv = NULL;
GAMESTATE state = MENU;
///////////////////////////////
//Menu Event Receiver
///////////////////////////////
class MenuEventReceiver : public IEventReceiver
{
public:
virtual bool OnEvent(SEvent event)
{
if (event.EventType == EET_GUI_EVENT)
{
s32 id = event.GUIEvent.Caller->getID();
switch(event.GUIEvent.EventType)
{
case gui::EGET_BUTTON_CLICKED:
if (id == MENU_QUIT)
{
device->closeDevice();
return true;
}
if (id == MENU_NEWGAME)
{
//does nothing yet!
return true;
}
break;
}
}
return false;
}
};
////////////////////////////
//Forward Declarations
////////////////////////////
bool init();
void initMenu();
void render();
void cleanup();
////////////////////////////
//Main loop
////////////////////////////
int main()
{
init();
initMenu();
while(device->run())
{
render();
}
cleanup();
return 0;
}
///////////////////////
//Init
///////////////////////
bool init()
{
device = createDevice(video::EDT_DIRECTX8,
core::dimension2d<s32>(WINDOW_WIDTH, WINDOW_HEIGHT),
BITRATE, false, false, false, 0);
device->setWindowCaption(L"Window Caption");
driver = device->getVideoDriver();
smgr = device->getSceneManager();
guienv = device->getGUIEnvironment();
MenuEventReceiver receiver;
device->setEventReceiver(&receiver);
return true;
}
///////////////////////
//Cleanup
////////////////////////
void cleanup()
{
device->drop();
}
///////////////////////
//InitMenu
///////////////////////
void initMenu()
{
guienv->addButton(core::rect<s32>(10, 210, 100, 240), 0, MENU_QUIT, L"QUIT");
guienv->addButton(core::rect<s32>(10, 300, 100, 340), 0, MENU_NEWGAME, L"NEWGAME");
}
///////////////////////
//Render
///////////////////////
void render()
{
//Begin rendering
driver->beginScene(true, true, video::SColor(255, 89, 68, 43));
//Do rendering
smgr->drawAll();
guienv->drawAll();
//End rendering
driver->endScene();
}
In addition to helping solve the problem can someone tell me how I go about detecting errors and outputting them in irrlicht as im sure that would help!
Thanks!