Everything is linked correctly (I believe), and my program compiles, but when I try and run it it gives me the old "Windows needs to close ...." message.
As a test, I compiled and ran a few of the tutorials successfully. I also compiled and ran an irrKlang tutorial successfully.
I have no idea what's going on here. Can anyone help?
Code: Select all
/*
Heroes of Western Keep v0.01
*/
#include <irrlicht.h>
#include <irrKlang.h>
#include <iostream>
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
using namespace irrklang;
#ifdef _MSC_VER
#pragma comment(lib, "Irrlicht.lib")
#pragma comment(lib, "irrKlang.lib")
#pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")
#endif
class MyEventReceiver : public IEventReceiver
{
public:
// This is the one method that we have to implement
virtual bool OnEvent(const SEvent& event)
{
// Remember whether each key is down or up
if (event.EventType == EET_KEY_INPUT_EVENT)
KeyIsDown[event.KeyInput.Key] = event.KeyInput.PressedDown;
return false;
}
// This is used to check whether a key is being held down
virtual bool IsKeyDown(EKEY_CODE keyCode) const
{
return KeyIsDown[keyCode];
}
MyEventReceiver()
{
for (u32 i=0; i<KEY_KEY_CODES_COUNT; ++i)
KeyIsDown[i] = false;
}
private:
// We use this array to store the current state of each key
bool KeyIsDown[KEY_KEY_CODES_COUNT];
};
int main()
{
E_DRIVER_TYPE videoType = EDT_SOFTWARE;
dimension2d<u32> resolution = dimension2d<u32>(800,600);
// Set up devices and event receiver
MyEventReceiver receiver;
IrrlichtDevice *device = createDevice(videoType,resolution, 32, false, false, false, &receiver);
if (!device)
return 1; // could not create driver.
// start the sound engine with default parameters
ISoundEngine* audioEng = createIrrKlangDevice();
if (!audioEng)
return 1; // could not start audio.
ISceneManager* smgr = device->getSceneManager();
device->setWindowCaption(L"Heroes of Western Keep");
device->getCursorControl()->setVisible(false);
IVideoDriver* driver = device->getVideoDriver();
ITexture* images = driver->getTexture("media/sprites.png"); //Load sprites
ITexture* GUIimage = driver->getTexture("media/interface.png"); // Load interface texture
ITexture* GUIbg = driver->getTexture("media/uibackground.png"); // Load background texture
driver->makeColorKeyTexture(images, position2d<s32>(0,0)); //Set alpha color
driver->makeColorKeyTexture(GUIimage, position2d<s32>(200,100)); //Set alpha color
// Set up fonts
IGUIFont* biFont = device->getGUIEnvironment()->getBuiltInFont();
IGUIFont* displayFont = device->getGUIEnvironment()->getFont("media/DisplayFont.png");
IGUIFont* menuFont = device->getGUIEnvironment()->getFont("media/MenuFont.png");
int counter = 0;
audioEng->play2D("media/stepintothelight.mp3",true);
while(device->run() && driver)
{
if (device->isWindowActive())
{
u32 time = device->getTimer()->getTime();
if (counter > -1200 && (time % 50 == 0))
counter--;
driver->beginScene(true, true, SColor(255,120,102,136));
// draw background
driver->draw2DImage(GUIbg,position2d<s32>(0,counter),rect<s32>(0,0,800,2000),0,SColor(255,255,255,255),true);
// draw gui
driver->draw2DImage(GUIimage,position2d<s32>(0,0),rect<s32>(0,0,800,600),0,SColor(255,255,255,255),true);
// draw some text
if (menuFont)
menuFont->draw(L"Start Game",
rect<s32>(275,410,400,450),
SColor(255,255,255,255));
// draw transparent rect under cursor
position2d<s32> m = device->getCursorControl()->getPosition();
driver->draw2DImage(images,m,rect<s32>(2,68,45,110),0,SColor(255,255,255,255), true);
driver->endScene();
}
if(receiver.IsKeyDown(KEY_KEY_Q))
device->closeDevice();
}
audioEng->drop();
device->drop();
return 0;
}