I've released a simple tool to manage the Irrlicht device's configuration.
The tool (at this moment it's only an header file with static function) shows an Irrlicht Interface to manage device's parameters in a visual way.
It stores and loads data to/from a text file, so it's possible to run an Irrlicht application with the possibility to change device's parameters on-the-fly.
So:
1) in the main.cpp file, simply run a new function to create the Irrlicht Device
2) this function will show a GUI: you can choose Driver Type, resolution, antialiasing...and so on
3) then the new Device will be passed to your main file to use
4) every "launch" action will save your configuration to file ("irrlicht.ini" file)
This is a simple "launcher", it compiles and runs in windows_xp_pro and ubuntu 10.04 (should works in other environments...I suppose)
Here's the code.
main.cpp
Code: Select all
#include <irrlicht.h>
#include "selectdevice.h"
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace gui;
using namespace io;
int main(int argc, char** argv) {
IrrlichtDevice* device = selectDevice();
if (!device) {
return 1;
}
device->setWindowCaption(L"SelectDevice test");
IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
IGUIEnvironment* guienv = device->getGUIEnvironment();
device->getCursorControl()->setVisible(false);
ISceneNode* cube = smgr->addCubeSceneNode();
cube->setPosition(vector3df(0, 0, 50));
cube->setMaterialTexture(0, device->getVideoDriver()->getTexture("wood.jpg"));
cube->setMaterialFlag(video::EMF_LIGHTING, false);
smgr->addCameraSceneNodeFPS();
while (device->run()) {
driver->beginScene(true, true, SColor(255, 100, 101, 140));
smgr->drawAll();
guienv->drawAll();
driver->endScene();
}
device->drop();
return 0;
}
Note: This is a simple-standard main.cpp file, that includes the "selectdevice.h" file and runs the selectDevice() function.
This function will manage the device parameters for you, and it'll show the last configuration before create the Device.
Take a look into "selectdevice.h" source:
"selectdevice.h"
Code: Select all
/* =================
* SELECTDEVICE TOOL
* =================
*
* Overview:
* this source provides a device configuration tool for an
* Irrlicht application
*
* The static irr::IrrlichtDevice* selectDevice() function,
* loads a ini file (if exists) and shows a configuration
* interface where the user can set the following variables:
*
* - Driver Type
* - Resolution
* - Driver params:
* Bits, Fullscreen, Stencilbuffer, Vsync, AntiAlias
* HighPrecisionFPU, Doublebuffer
*
* When the user click on "Launch" button, this configuration
* is saved to file, for next loading.
*
* On the next run of the "selectDevice()" function, the
* configuration saved is loaded from file and shown in the
* configuration gui.
* In this way, the main program will always show the last
* configuration loaded from file.
*
*
* USAGE
* =====
* 1) copy the selectdevice.h in your source directory
* 2) add in your main c++ file the include:
*
* #include "selectdevice.h"
*
* 3) use following code to show the gui and let the user choose
* video parameters:
*
* IrrlichtDevice* device = selectDevice();
*
* 4) enjoy
*
* NOTE
* ====
* - tested on Ubuntu 10.04 and Windows XP PRO
* - this file uses the built-in font (which is small), but
* there's no need to use external files
* - the resolution listbox is just an example, fill it with
* your resolutions
*
* LICENCE
* =======
* This file is free and open: it can be used for free and commercial purpose.
* If you modify this file you must keep the original author in this note
* If you use it in your projects (commercial or free) a credit to me is very
* appreciated (but not mandatory).
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the author be held liable for any damages arising
* from the use of this software.
*
* AUTHOR
* ======
* SelectDevice version 0.1 (2011-05-01)
* Author: silver.slade
* Email: silver.slade@tiscali.it
* Web: http://www.slade.altervista.org
*
*/
#ifndef SELECTDEVICE_H_
#define SELECTDEVICE_H_
#include <irrlicht.h>
#define CONFIGURATION_FILE "irrlicht.ini"
enum
{
GUI_ID_QUIT_BUTTON = 101,
GUI_ID_LAUNCH_BUTTON,
GUI_ID_ABOUT_BUTTON
};
bool quit = false;
bool launch = false;
irr::IrrlichtDevice *nulldevice;
/**
* ConfiguratorEventReceiver
* Managed Action only for "Quit","Launch"
* and "About" buttons
*/
class ConfiguratorEventReceiver : public irr::IEventReceiver
{
public:
virtual bool OnEvent(const irr::SEvent& event)
{
if (event.EventType == irr::EET_GUI_EVENT)
{
irr::s32 id = event.GUIEvent.Caller->getID();
switch(event.GUIEvent.EventType)
{
case irr::gui::EGET_BUTTON_CLICKED:
{
switch(id)
{
case GUI_ID_QUIT_BUTTON:
quit=true;
return true;
case GUI_ID_LAUNCH_BUTTON:
launch=true;
nulldevice->closeDevice();
return true;
case GUI_ID_ABOUT_BUTTON:
nulldevice->getGUIEnvironment()->addMessageBox(L"SelectDevice Utility", L"SelectDevice by silver.slade");
return true;
default:
return false;
}
}
default:
return false;
}
}
return false;
}
};
namespace irr
{
// Type Driver ------------------------------
const wchar_t* const driverstrings[] = {
L"NullDriver",
L"Software Renderer",
L"Burning's Video",
L"Direct3D 8.1",
L"Direct3D 9.0c",
L"OpenGL 1.x/2.x/3.x"
};
irr::video::E_DRIVER_TYPE drivervalues[]= {
irr::video::EDT_NULL,
irr::video::EDT_SOFTWARE,
irr::video::EDT_BURNINGSVIDEO,
irr::video::EDT_DIRECT3D8,
irr::video::EDT_DIRECT3D9,
irr::video::EDT_OPENGL
};
// Video Resolutions -------------------------
const wchar_t* const resolutionstrings[] = {
L"640x480",
L"800x600",
L"1280x800"
};
core::dimension2d<u32> const resolutionvalues[] = {
core::dimension2d<u32>(640,480),
core::dimension2d<u32>(800,600),
core::dimension2d<u32>(1280,800)
};
// Bits -------------------------------------
const wchar_t* const bitsstrings[] = {
L"16",
L"32"
};
int const bitsvalues[] = {
16,
32,
};
// Gui Checkbox -----------------------------
gui::IGUICheckBox* cfullscreen;
gui::IGUICheckBox* cstencilbuffer;
gui::IGUICheckBox* cvsync;
gui::IGUICheckBox* cantialiasing;
gui::IGUICheckBox* chpf;
gui::IGUICheckBox* cdoublebuffer;
// Configuration variables ------------------
int drivercount=0;
int resolutioncount=0;
int bitscount=0;
int bfullscreen=0;
int bstencilbuffer=0;
int bvsync=0;
int bantialiasing=0;
int bhpf=0;
int bdoublebuffer=0;
static irr::IrrlichtDevice* selectDevice()
{
// Try to Load configuration from file is exits
FILE *fp;
if((fp=fopen(CONFIGURATION_FILE, "r"))!=NULL) {
fscanf(fp, "driver=%d\n", &drivercount);
fscanf(fp, "resolution=%d\n", &resolutioncount);
fscanf(fp, "bits=%d\n", &bitscount);
fscanf(fp, "fullscreen=%d\n", &bfullscreen);
fscanf(fp, "stencilbuffer=%d\n", &bstencilbuffer);
fscanf(fp, "vsync=%d\n", &bvsync);
fscanf(fp, "antialiasing=%d\n", &bantialiasing);
fscanf(fp, "hpf=%d\n", &bhpf);
fscanf(fp, "doublebuffer=%d\n", &bdoublebuffer);
fclose(fp);
}
// Main Configuration Gui
nulldevice = createDevice(video::EDT_SOFTWARE,
core::dimension2d<u32>(500, 260), 32, false, false, false);
nulldevice->setWindowCaption(L"Irrlicht SelectDevice Utility");
ConfiguratorEventReceiver* cer = new ConfiguratorEventReceiver();
nulldevice->setEventReceiver(cer);
video::IVideoDriver* driver = nulldevice->getVideoDriver();
gui::IGUIEnvironment* guienv = nulldevice->getGUIEnvironment();
// Gui - Buttons
guienv->addButton(core::rect<s32>(10,220,110,220 + 30), 0, GUI_ID_QUIT_BUTTON,L"Quit", L"Exits Program");
guienv->addButton(core::rect<s32>(120,220,220,220 + 30), 0, GUI_ID_LAUNCH_BUTTON,L"Launch", L"Launch Program");
guienv->addButton(core::rect<s32>(230,220,330,220 + 30), 0, GUI_ID_ABOUT_BUTTON,L"About", L"About SelectDevice Utility");
// GUI - driver listbox
guienv->addStaticText(L"Choose driver:",core::rect<int>(10,10,120,30));
gui::IGUIListBox* ldriver = guienv->addListBox(core::rect<int>(10,30,120,200));
for (int var = 0; var < irr::video::EDT_COUNT; ++var) {
ldriver->addItem(driverstrings[var]);
}
ldriver->setSelected(drivercount);
ldriver->setDrawBackground(true);
// GUI - resolution listbox
guienv->addStaticText(L"Choose resolution:",core::rect<int>(130,10,230,30));
gui::IGUIListBox* lresolution = guienv->addListBox(core::rect<int>(140,30,220,200));
for (int var = 0; var < 3; ++var) {
lresolution->addItem(resolutionstrings[var]);
}
lresolution->setSelected(resolutioncount);
lresolution->setDrawBackground(true);
// GUI - bits listbox
guienv->addStaticText(L"Choose bits:",core::rect<int>(240,10,330,30));
gui::IGUIListBox* lbits = guienv->addListBox(core::rect<int>(240,30,320,200));
for (int var = 0; var < 2; ++var) {
lbits->addItem(bitsstrings[var]);
}
lbits->setSelected(bitscount);
lbits->setDrawBackground(true);
// GUI - Checkboxes
int x = 20; // offset over x
int y = 340; // offset over y for checkboxes
guienv->addStaticText(L"Choose flags:",core::rect<int>(y,10,y+90,30));
cfullscreen = guienv->addCheckBox(bfullscreen, core::rect<int>(y,30,y+100,30+x),0, 1, L"Fullscreen");
cstencilbuffer = guienv->addCheckBox(bstencilbuffer, core::rect<int>(y,60,y+100,60+x),0, 2, L"Stencilbuffer");
cvsync = guienv->addCheckBox(bvsync, core::rect<int>(y,90,y+100,90+x),0, 3, L"Vsync");
cantialiasing = guienv->addCheckBox(bantialiasing, core::rect<int>(y,120,y+100,120+x),0, 4, L"AntiAliasin");
chpf = guienv->addCheckBox(bhpf, core::rect<int>(y,150,y+100,150+x),0, 5, L"HighPrecisionFPU");
cdoublebuffer = guienv->addCheckBox(bdoublebuffer, core::rect<int>(y,180,y+100,180+x),0, 6, L"Doublebuffer");
while (nulldevice->run() && !quit)
{
if (nulldevice->isWindowActive())
{
driver->beginScene(true, true, video::SColor(0,200,200,200));
guienv->drawAll();
driver->endScene();
}
}
if (quit)
{
nulldevice->drop();
return 0;
}
if (launch)
{
// Saving configuration to file...
bfullscreen = cfullscreen->isChecked();
bstencilbuffer = cstencilbuffer->isChecked();
bvsync = cvsync->isChecked();
bantialiasing = cantialiasing->isChecked();
bhpf = chpf->isChecked();
bdoublebuffer = cdoublebuffer->isChecked();
// Saving
FILE *fp;
if((fp=fopen(CONFIGURATION_FILE, "w+"))==NULL) {
printf("Error: cannot open file.\n");
if (nulldevice) nulldevice->drop();
return 0;
}
fprintf(fp, "driver=%d\n", ldriver->getSelected());
fprintf(fp, "resolution=%d\n", lresolution->getSelected());
fprintf(fp, "bits=%d\n", lbits->getSelected());
fprintf(fp, "fullscreen=%d\n", bfullscreen);
fprintf(fp, "stencilbuffer=%d\n", bstencilbuffer);
fprintf(fp, "vsync=%d\n", bvsync);
fprintf(fp, "antialiasing=%d\n", bantialiasing);
fprintf(fp, "hpf=%d\n", bhpf);
fprintf(fp, "doublebuffer=%d\n", bdoublebuffer);
fclose(fp);
// Prepare and return the driver pointer
irr::SIrrlichtCreationParameters params;
params.DriverType = drivervalues[ldriver->getSelected()];
params.WindowSize = resolutionvalues[lresolution->getSelected()];
params.Bits = bitsvalues[lbits->getSelected()];
params.Fullscreen = bfullscreen;
params.Stencilbuffer = bstencilbuffer;
params.Vsync = bvsync;
params.AntiAlias = bantialiasing;
params.HighPrecisionFPU = bhpf;
params.LoggingLevel = ELL_ERROR;
params.Doublebuffer = bdoublebuffer;
if (nulldevice) nulldevice->drop();
return createDeviceEx(params);
}
return 0;
}
}
#endif /* SELECTDEVICE_H_ */
The result is:

The source is public and free for any purpose, I hope it'll be useful for someone.
Comments and ideas are welcome.
To download a bin example (with full code) see here:
http://www.slade.altervista.org
in the download section.
Long live and prosper
silver.slade