Maybe this isn't new, but I'll post it. Could be easy extended.
irrlichthelper.h
Code: Select all
#pragma once
#include <irrlicht.h>
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
class IrrlichtHelper {
private:
static IrrlichtDevice *_irrlichtDevice;
static IVideoDriver *_videoDriver;
static ISceneManager *_sceneManager;
static s32 _width;
static s32 _height;
static s32 _bpp;
static bool _fullscreen;
protected:
public:
IrrlichtHelper(void);
~IrrlichtHelper(void);
static bool Init(s32 width, s32 height, s32 bpp, bool fullscreen, IEventReceiver *eventReceiver) {
IrrlichtHelper::_width = width;
IrrlichtHelper::_height = height;
IrrlichtHelper::_bpp = bpp;
IrrlichtHelper::_fullscreen = fullscreen;
if (Device(eventReceiver) == 0) {
return false;
}
if (Driver() == 0) {
return false;
}
return true;
}
static IrrlichtDevice *Device() {
return Device(0);
}
static IrrlichtDevice *Device(IEventReceiver *eventReceiver) {
if (IrrlichtHelper::_irrlichtDevice == 0) {
IrrlichtHelper::_irrlichtDevice = createDevice(video::EDT_OPENGL, dimension2d<u32>(_width, _height), _bpp, _fullscreen, false, false, eventReceiver);
}
return IrrlichtHelper::_irrlichtDevice;
}
static IVideoDriver *Driver() {
if (IrrlichtHelper::_videoDriver == 0) {
IrrlichtHelper::_videoDriver = IrrlichtHelper::Device()->getVideoDriver();
}
return IrrlichtHelper::_videoDriver;
}
static ISceneManager *Smgr() {
if (IrrlichtHelper::_sceneManager == 0) {
IrrlichtHelper::_sceneManager = IrrlichtHelper::Device()->getSceneManager();
}
return IrrlichtHelper::_sceneManager;
}
static int Width() {
return IrrlichtHelper::_width;
}
static int Height() {
return IrrlichtHelper::_height;
}
static int Bpp() {
return IrrlichtHelper::_bpp;
}
static bool Fullscreen() {
return IrrlichtHelper::_fullscreen;
}
};
Code: Select all
#include "IrrlichtHelper.h"
IrrlichtDevice *IrrlichtHelper::_irrlichtDevice = 0;
IVideoDriver *IrrlichtHelper::_videoDriver = 0;
ISceneManager *IrrlichtHelper::_sceneManager = 0;
int IrrlichtHelper::_width = 0;
int IrrlichtHelper::_height = 0;
int IrrlichtHelper::_bpp = 0;
bool IrrlichtHelper::_fullscreen = false;
//! constructor
IrrlichtHelper::IrrlichtHelper(void) {
}
//! destructor
IrrlichtHelper::~IrrlichtHelper(void) {
}
Code: Select all
if (!IrrlichtHelper::Init(1024, 768, 16, false, this)) {
return false;
}
while(IrrlichtHelper::Device()->run()) {
if (IrrlichtHelper::Device()->isWindowActive()) {
// render something
} else {
IrrlichtHelper::Device()->yield();
}
}
IrrlichtHelper::Device()->drop();