Device in fullscreen 16:9
-
- Posts: 19
- Joined: Mon Apr 13, 2009 5:42 pm
In main.h
in main.cpp
Code: Select all
IrrlichtDevice *device;
IrrlichtDevice *devNull;
IVideoModeList *vidlist;
IVideoDriver *driver;
ISceneManager *smgr;
Events events;
ICameraSceneNode *camera;
Code: Select all
//when form is create
void __fastcall TfrmMain::FormCreate(TObject *Sender)
{
devNull = createDevice(EDT_NULL);
vidlist = devNull->getVideoModeList();
for (int i = 0; i < vidlist->getVideoModeCount(); i++) {
this->cbbRes->Items->Add(
IntToStr((vidlist->getVideoModeResolution(i)).Width) + "x" +
IntToStr((vidlist->getVideoModeResolution(i)).Height) + "x" +
IntToStr(vidlist->getVideoModeDepth(i))
);
}
this->cbbRes->ItemIndex=0;
this->cbbDriver->ItemIndex=0;
}
//-------------------------------------------------------------------
//when i click start button after chose resolution
void __fastcall TfrmMain::btnStartClick(TObject *Sender)
{
E_DRIVER_TYPE tmpDriver;
dimension2d<s32> tmpRes;
u32 tmpBits;
switch (this->cbbDriver->ItemIndex) {
case 0:
tmpDriver = EDT_DIRECT3D9;
break;
case 1:
tmpDriver = EDT_OPENGL;
break;
case 2:
tmpDriver = EDT_SOFTWARE;
break;
}
tmpRes = vidlist->getVideoModeResolution(this->cbbRes->ItemIndex);
tmpBits = vidlist->getVideoModeDepth(this->cbbRes->ItemIndex);
devNull->drop();
device = createDevice(tmpDriver,tmpRes,tmpBits,this->lstOptions->Checked[0],
this->lstOptions->Checked[1],this->lstOptions->Checked[2],&events);
if (!device) {
this->Close();
}
driver = device->getVideoDriver();
smgr = device->getSceneManager();
device->setWindowCaption(L"The Master Thief");
//preparazione della scena
camera = smgr->addCameraSceneNode(0,vector3df(0,40,-100),vector3df(0,10,0));
IAnimatedMesh *mesh = smgr->getMesh("sydney.md2");
ILightSceneNode *light = smgr->addLightSceneNode(0,vector3df(0,10,10),
SColor(255,255,128,128),150.0f);
if (!mesh) {
this->Close();
}
IAnimatedMeshSceneNode *node =smgr->addAnimatedMeshSceneNode(mesh);
if (node)
{
node->setMaterialFlag(EMF_LIGHTING, true);
node->setMD2Animation(scene::EMAT_STAND);
node->setMaterialTexture( 0, driver->getTexture("sydney.bmp") );
}
this->Hide();
this->IrrLoop();
}
//-------------------------------------------------------------------
//the irrlicht loop
void __fastcall TfrmMain::IrrLoop()
{
u32 shot_old = device->getTimer()->getTime();
while (device->run())
{
const u32 shot_now = device->getTimer()->getTime();
const f32 shot_delta = (f32) (shot_now-shot_old);
shot_old = shot_now;
driver->beginScene(true,true,SColor(255,255,255,255));
if (events.IsKeyDown(KEY_ESCAPE)) {
device->closeDevice();
}
if (events.IsKeyDown(KEY_KEY_A)) {
vector3df camPos = camera->getPosition();
vector3df camTPos = camera->getTarget();
camPos.X -= 0.1f*shot_delta;
camTPos.X -= 0.1f*shot_delta;
camera->setPosition(camPos);
camera->setTarget(camTPos);
}
if (events.IsKeyDown(KEY_KEY_D)) {
vector3df camPos = camera->getPosition();
vector3df camTPos = camera->getTarget();
camPos.X += 0.1f*shot_delta;
camTPos.X += 0.1f*shot_delta;
camera->setPosition(camPos);
camera->setTarget(camTPos);
}
if (events.IsKeyDown(KEY_KEY_W)) {
vector3df camPos = camera->getPosition();
vector3df camTPos = camera->getTarget();
camPos.Z += 0.1f*shot_delta;
camTPos.Z += 0.1f*shot_delta;
camera->setPosition(camPos);
camera->setTarget(camTPos);
}
if (events.IsKeyDown(KEY_KEY_S)) {
vector3df camPos = camera->getPosition();
vector3df camTPos = camera->getTarget();
camPos.Z -= 0.1f*shot_delta;
camTPos.Z -= 0.1f*shot_delta;
camera->setPosition(camPos);
camera->setTarget(camTPos);
}
smgr->drawAll();
driver->endScene();
}
device->drop();
this->Close();
}
-
- Posts: 19
- Joined: Mon Apr 13, 2009 5:42 pm
-
- Posts: 19
- Joined: Mon Apr 13, 2009 5:42 pm
Maybe irrlicht does something strange when a device get dropped. If a implement a check like this:
all goes well on the surface.
Code: Select all
if (device) {
device->drop();
}
if (devNull) {
devNull->drop();
}
You should drop devNull immediately when you have the information which you needed. Right now if btnStartClick is called more than once then devNull will be dropped several times.
It is easier to find such bugs (and good style) when you set variables always to 0 after you dropped them.
(also that was the first time I've ever seen someone using __fastcall)
It is easier to find such bugs (and good style) when you set variables always to 0 after you dropped them.
(also that was the first time I've ever seen someone using __fastcall)
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
-
- Posts: 19
- Joined: Mon Apr 13, 2009 5:42 pm
That would not prevent dropping a device several times. You have to reset a variable if you want check it:Gendo Ikari wrote:Maybe irrlicht does something strange when a device get dropped. If a implement a check like this:all goes well on the surface.Code: Select all
if (device) { device->drop(); } if (devNull) { devNull->drop(); }
Code: Select all
if (device) {
device->drop();
device = 0;
}
if (devNull) {
devNull->drop();
devNull = 0;
}
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
-
- Posts: 19
- Joined: Mon Apr 13, 2009 5:42 pm