i didn't post all the source code from the beginning as i was afraid it is too much of a trouble for you (those who want to help) to look through all of it
i posted what i thought it was relevant
anyways here's the code, so if anybody has any idea what i'm doing wrong please help
thank you
I'm compileing on windows xp using visual studio 2003, and irrlicht 1.4
main.cpp
Code: Select all
#include <irrlicht.h>
#ifdef _IRR_WINDOWS_
#include <windows.h>
#endif
#include "CApplication.h"
#ifdef _WIN32
#pragma comment(lib, "Irrlicht.lib")
INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
#else
int main(int argc, char* argv[])
#endif
{
CApplication app;
app.Run();
return 0;
}
CApplication.h
Code: Select all
#ifndef __C_APPLICATION_H_INCLUDED__
#define __C_APPLICATION_H_INCLUDED__
#include <irrlicht.h>
#include <irrXML.h>
#include "CStateManager.h"
using namespace irr;
using namespace io;
using namespace video;
using namespace gui;
using namespace core;
class CApplication
{
public:
CApplication();
~CApplication();
void Run();
IrrlichtDevice *irrDevice;
IVideoDriver *videoDriver;
IGUIEnvironment *guiEnv;
IGUIInOutFader *inOutFader;
IFileSystem *irrFS;
private:
/* BEGIN CONFIG */
bool cfgFullScreen;
E_DRIVER_TYPE cfgVideoDriver;
void LoadConfig();
/* END CONFIG */
};
#endif
CApplication.cpp
Code: Select all
#include "CApplication.h"
CApplication::CApplication()
: irrDevice(0), videoDriver(0), guiEnv(0), irrFS(0),
cfgFullScreen(false), cfgVideoDriver(EDT_BURNINGSVIDEO)
{
}
CApplication::~CApplication()
{
}
void CApplication::Run()
{
LoadConfig();
irrDevice = createDevice(cfgVideoDriver, dimension2d<s32>(1024, 768), 32, cfgFullScreen);
if (!irrDevice)
{
irrDevice = createDevice(EDT_BURNINGSVIDEO, dimension2d<s32>(1024, 768), 32, cfgFullScreen);
}
irrDevice->setWindowCaption(L"Imnuri Crestine v1.0 - Daniel Anechitoaie");
videoDriver = irrDevice->getVideoDriver();
irrFS = irrDevice->getFileSystem();
guiEnv = irrDevice->getGUIEnvironment();
inOutFader = guiEnv->addInOutFader();
inOutFader->setColor(SColor(0, 0, 0, 0));
CStateManager *stateManager = new CStateManager(this);
stateManager->Init();
while (irrDevice->run() && videoDriver)
{
stateManager->Run();
//irrDevice->yield();
}
irrDevice->drop();
delete stateManager;
}
void CApplication::LoadConfig()
{
IrrXMLReader* xml = createIrrXMLReader("ImnuriCrestine.conf");
while(xml && xml->read())
{
switch(xml->getNodeType())
{
case EXN_ELEMENT:
{
if (!strcmp("FullScreen", xml->getNodeName()))
{
if (!strcmp("true", xml->getAttributeValue("value")))
{
cfgFullScreen = true;
}
}
else
if (!strcmp("VideoDriver", xml->getNodeName()))
{
if (!strcmp("DirectX8", xml->getAttributeValue("value")))
{
cfgVideoDriver = EDT_DIRECT3D8;
}
else
if (!strcmp("DirectX9", xml->getAttributeValue("value")))
{
cfgVideoDriver = EDT_DIRECT3D9;
}
else
if (!strcmp("OpenGL", xml->getAttributeValue("value")))
{
cfgVideoDriver = EDT_OPENGL;
}
}
}
break;
}
}
delete xml;
}
CState.h
Code: Select all
#ifndef __C_STATE_H_INCLUDED__
#define __C_STATE_H_INCLUDED__
class CState
{
public:
virtual void Init() = 0;
virtual void Enter() = 0;
virtual void Run() = 0;
virtual void Exit() = 0;
};
#endif
CStateManager.h
Code: Select all
#ifndef __C_STATE_MANAGER_H_INCLUDED__
#define __C_STATE_MANAGER_H_INCLUDED__
#include <irrlicht.h>
#include "CState.h"
#include "CStateSplash.h"
#include "CStateMenu.h"
using namespace irr;
using namespace video;
class CApplication;
class CStateManager
{
public:
CStateManager(CApplication *pApplication);
~CStateManager();
void Init();
void Run();
void ChangeState(CState *pNewState);
CState *pCurrentState;
CState *pStateSplash;
CState *pStateMenu;
CState *pStateHymn;
CState *pStateAbout;
CApplication *pApplication;
};
#endif
CStateManager.cpp
Code: Select all
#include "CStateManager.h"
#include "CApplication.h"
CStateManager::CStateManager(CApplication *pApplication)
{
this->pApplication = pApplication;
pStateSplash = new CStateSplash(this);
pStateMenu = new CStateMenu(this);
//pStateHymn = new CStateHymn(this);
//pStateAbout = new CStateAbout(this);
}
CStateManager::~CStateManager()
{
delete pStateSplash;
delete pStateMenu;
//delete pStateHymn;
//delete pStateAbout;
}
void CStateManager::Init()
{
pStateSplash->Init();
pStateMenu->Init();
//pStateHymn->Init();
//pStateAbout->Init();
pCurrentState = pStateSplash;
pCurrentState->Enter();
}
void CStateManager::Run()
{
pCurrentState->Run();
}
void CStateManager::ChangeState(CState *pNewState)
{
pCurrentState->Exit();
pCurrentState = pNewState;
pCurrentState->Enter();
}
CStateMenu.h
Code: Select all
#ifndef __C_STATE_MENU_H_INCLUDED__
#define __C_STATE_MENU_H_INCLUDED__
#include <irrlicht.h>
#include "CState.h"
using namespace irr;
using namespace video;
using namespace core;
using namespace gui;
using namespace io;
class CStateManager;
class CStateMenu : public CState, public IEventReceiver
{
public:
CStateMenu(CStateManager *pStateManager);
~CStateMenu();
virtual void Init();
virtual void Enter();
virtual void Run();
virtual void Exit();
virtual bool OnEvent(const SEvent& event);
private:
ITexture *textureMenu;
IVideoDriver *videoDriver;
IGUIEnvironment *guiEnv;
IGUIInOutFader *inOutFader;
IFileSystem *irrFS;
rect<s32> menuBackground;
//array< rect<s32> > splashLoadingBar;
u32 timeLastFrame;
u32 timeTotalFrames;
bool faderSet;
CStateManager *pStateManager;
};
#endif
CStateMenu.cpp
Code: Select all
#include "CStateMenu.h"
#include "CStateManager.h"
#include "CApplication.h"
#include "TextureMenu.h"
CStateMenu::CStateMenu(CStateManager *pStateManager)
: textureMenu(0), irrFS(0), videoDriver(0), guiEnv(0), inOutFader(0),
timeLastFrame(0), timeTotalFrames(0),
faderSet(false)
{
this->pStateManager = pStateManager;
this->videoDriver = pStateManager->pApplication->videoDriver;
this->irrFS = pStateManager->pApplication->irrFS;
this->guiEnv = pStateManager->pApplication->guiEnv;
this->inOutFader = pStateManager->pApplication->inOutFader;
}
CStateMenu::~CStateMenu()
{
}
void CStateMenu::Init()
{
menuBackground = rect<s32>(0, 256, 1024, 1024);
IReadFile* file;
const c8* fileNameTextureMenu = "#TextureMenu";
file = irrFS->createMemoryReadFile(textureMenuBuff, textureMenuBuffSize, fileNameTextureMenu, false);
textureMenu = videoDriver->getTexture(file);
}
void CStateMenu::Enter()
{
pStateManager->pApplication->irrDevice->setEventReceiver(this);
inOutFader->fadeIn(400);
}
void CStateMenu::Run()
{
//u32 cTime = pStateManager->pApplication->irrDevice->getTimer()->getTime();
//if (cTime >= (timeLastFrame + 35))
//{
// splashLoadingBarFrame++;
// if (splashLoadingBarFrame > 9)
// {
// splashLoadingBarFrame = 0;
// }
// timeTotalFrames += (cTime - timeLastFrame);
// timeLastFrame = cTime;
//}
//if (timeTotalFrames >= 6400)
//{
// if(!faderSet)
// {
// inOutFader->fadeOut(400);
// faderSet = true;
// }
// //if (timeTotalFrames >= 7000)
// // splashOver = true;
//}
videoDriver->beginScene(true, true, video::SColor(0, 0, 0, 0));
videoDriver->draw2DImage(textureMenu, position2d<s32>(0, 0), menuBackground);
guiEnv->drawAll();
videoDriver->endScene();
}
void CStateMenu::Exit()
{
}
bool CStateMenu::OnEvent(const SEvent& event)
{
if (!pStateManager->pApplication->irrDevice)
return false;
if (event.EventType == EET_KEY_INPUT_EVENT &&
event.KeyInput.Key == KEY_ESCAPE &&
event.KeyInput.PressedDown == false)
{
pStateManager->pApplication->irrDevice->closeDevice();
}
return false;
}
CStateSplash.h
Code: Select all
#ifndef __C_STATE_SPLASH_H_INCLUDED__
#define __C_STATE_SPLASH_H_INCLUDED__
#include <irrlicht.h>
#include "CState.h"
using namespace irr;
using namespace video;
using namespace core;
using namespace gui;
using namespace io;
class CStateManager;
class CStateSplash : public CState, public IEventReceiver
{
public:
CStateSplash(CStateManager *pStateManager);
~CStateSplash();
virtual void Init();
virtual void Enter();
virtual void Run();
virtual void Exit();
virtual bool OnEvent(const SEvent& event);
private:
ITexture *textureSplash;
IVideoDriver *videoDriver;
IGUIEnvironment *guiEnv;
IGUIInOutFader *inOutFader;
IFileSystem *irrFS;
rect<s32> splashBackground;
array< rect<s32> > splashLoadingBar;
u32 timeLastFrame;
u32 timeTotalFrames;
u32 splashLoadingBarFrame;
bool faderSet;
CStateManager *pStateManager;
};
#endif
CStateSplash.cpp
Code: Select all
#include "CStateSplash.h"
#include "CStateManager.h"
#include "CApplication.h"
#include "TextureSplash.h"
CStateSplash::CStateSplash(CStateManager *pStateManager)
: textureSplash(0), irrFS(0), videoDriver(0), guiEnv(0), inOutFader(0),
timeLastFrame(0), timeTotalFrames(0), splashLoadingBarFrame(0),
faderSet(false)
{
this->pStateManager = pStateManager;
this->videoDriver = pStateManager->pApplication->videoDriver;
this->irrFS = pStateManager->pApplication->irrFS;
this->guiEnv = pStateManager->pApplication->guiEnv;
this->inOutFader = pStateManager->pApplication->inOutFader;
}
CStateSplash::~CStateSplash()
{
}
void CStateSplash::Init()
{
splashBackground = rect<s32>(0, 256, 1024, 1024);
splashLoadingBar.push_back(rect<s32>(0, 0, 208, 13));
splashLoadingBar.push_back(rect<s32>(0, 13, 208, 26));
splashLoadingBar.push_back(rect<s32>(0, 26, 208, 39));
splashLoadingBar.push_back(rect<s32>(0, 39, 208, 52));
splashLoadingBar.push_back(rect<s32>(0, 52, 208, 65));
splashLoadingBar.push_back(rect<s32>(0, 65, 208, 78));
splashLoadingBar.push_back(rect<s32>(0, 78, 208, 91));
splashLoadingBar.push_back(rect<s32>(0, 91, 208, 104));
splashLoadingBar.push_back(rect<s32>(0, 104, 208, 117));
splashLoadingBar.push_back(rect<s32>(0, 117, 208, 130));
IReadFile* file;
const c8* fileNameTextureSplash = "#TextureSplash";
file = irrFS->createMemoryReadFile(textureSplashBuff, textureSplashBuffSize, fileNameTextureSplash, false);
textureSplash = videoDriver->getTexture(file);
}
void CStateSplash::Enter()
{
pStateManager->pApplication->irrDevice->setEventReceiver(this);
}
void CStateSplash::Run()
{
u32 cTime = pStateManager->pApplication->irrDevice->getTimer()->getTime();
if (cTime >= (timeLastFrame + 35))
{
splashLoadingBarFrame++;
if (splashLoadingBarFrame > 9)
{
splashLoadingBarFrame = 0;
}
timeTotalFrames += (cTime - timeLastFrame);
timeLastFrame = cTime;
}
if (timeTotalFrames >= 6400)
{
if(!faderSet)
{
inOutFader->fadeOut(400);
faderSet = true;
}
if (timeTotalFrames >= 7000)
pStateManager->ChangeState(pStateManager->pStateMenu);
}
videoDriver->beginScene(true, true, video::SColor(0, 0, 0, 0));
videoDriver->draw2DImage(textureSplash, position2d<s32>(0, 0), splashBackground);
videoDriver->draw2DImage(textureSplash, position2d<s32>(411, 644), splashLoadingBar[splashLoadingBarFrame]);
guiEnv->drawAll();
videoDriver->endScene();
}
void CStateSplash::Exit()
{
}
bool CStateSplash::OnEvent(const SEvent& event)
{
if (!pStateManager->pApplication->irrDevice)
return false;
if (event.EventType == EET_KEY_INPUT_EVENT &&
event.KeyInput.Key == KEY_ESCAPE &&
event.KeyInput.PressedDown == false)
{
pStateManager->pApplication->irrDevice->closeDevice();
}
return false;
}
TextureMenu.h
Code: Select all
unsigned int textureMenuBuffSize = 692809;
unsigned char textureMenuBuff[] = {
0x89,0x50,0x4e,0x47,0x0d,0x0a
.......
Not relevant, file generated from a png using bin2h
.......
};
TextureSplash.h
Code: Select all
same as TextureMenu, different data