How do you exit examples?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Jehsup

How do you exit examples?

Post by Jehsup »

How do you exit any of the examples without restarting your whole computer? It is quite frustrating.

Thanks,
J
Guest

Post by Guest »

just press [ALT]+[F4] :wink:
Guest

Post by Guest »

LOL!!! must have been quite frustrating! :D

Glad that didnt deter you from developing! At least now you know the ALT-F4 trick. Otherwise you could build it into your event handler.
Dogs
Posts: 195
Joined: Wed Sep 15, 2004 1:04 am
Location: michigan

Post by Dogs »

lol I had this same problem.... in fact its posted about 35 post down this list... I wasnt happy about it myself... I just tried every combo of alt I could find and found it myself... Then I came back to this forum the next day and the answer was here lol... Maybe ill write a small example on how to implement the escape key to close the app when I figure it out myself lol... heheheh.. Stick with the engine its quite nice and has much potential from what ive done so far... And im a very basic C++ programmer and know very little about programming and yet I can use most of the main features of the engine now due to some help here in the forum.. Most here at this forum have been great help..
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

I add a global boolean variable called progDeath
Just create a event receiver like this:

Code: Select all

bool cIrrEventReceiver::OnEvent(SEvent event){
  if (event.EventType == EET_KEY_INPUT_EVENT && !event.KeyInput.PressedDown){
    switch(event.KeyInput.Key){
      case KEY_ESCAPE:{
        return progDeath = true;
      }break;
    }
  }
  return false;
}
and the main loop should look something like that:

Code: Select all

  progDeath = false;
  while(device->run()) { 
    driver->beginScene(true, true, 0); 
    smgr->drawAll(); 
    driver->endScene(); 
    if(progDeath){
      device->closeDevice();
    }
  }
  device->drop(); 
That should close your app by pressing Escape... ;)
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
blackbirdXXX
Posts: 20
Joined: Tue Sep 21, 2004 9:08 pm

Post by blackbirdXXX »

I would do it the following:

Code: Select all

bool cIrrEventReceiver::OnEvent(SEvent event){
  if (event.EventType == EET_KEY_INPUT_EVENT && !event.KeyInput.PressedDown){
    switch(event.KeyInput.Key){
      case KEY_ESCAPE:{
        return progDeath = true;
      }break;
    }
  }
  return false;
}

Code: Select all

  progDeath = false;
  while(device->run()) { 
    driver->beginScene(true, true, 0); 
    smgr->drawAll(); 
    driver->endScene(); 
    if(progDeath){
       break;
    }
  }
  device->drop(); 
Kristian
Posts: 12
Joined: Wed Sep 22, 2004 3:07 pm
Location: Germany

Post by Kristian »

I did Alt + Tab and then Ctr. + C in the console window :P
Dogs
Posts: 195
Joined: Wed Sep 15, 2004 1:04 am
Location: michigan

Post by Dogs »

I tried to figure out the code that was posted here and im leaving something out...
Could you exsplain it a bit more please...
Im sure I need to add more to it to make it work...
Im quite new to C++.. I hope to get the hang of this in time lol...
Dogs
Posts: 195
Joined: Wed Sep 15, 2004 1:04 am
Location: michigan

Post by Dogs »

I figured id explain myself a bit more...

I understand the concept of how the code works..
But here is where I run into problems..
Im sure its just my dumb newbie C++ mind...
progDeath is not declared, How and where did you declared it in your app..

cIrrEventReceiver::OnEvent
cIrrEventReceiver isnt of namespace type..
OnEvent is an illegal local varible..

These are the errors I get..

I added cIrrEventReceiver to namespace of course didnt fix..
I also added IEventReciver.h I think it was to my #include section..

Im sure ill lol at the answer to this, Like I said im a newbie to C++.

Thanks for any help..
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

As I told before, progDeath is a global boolean variable...
Well, this is how I handle this, there are other solusions as well...

Now here is my template, that I use for starting a new project:

Code: Select all

#include <irrlicht.h>

using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;

IrrlichtDevice *device = 0;
IVideoDriver* driver = 0;
ISceneManager* smgr = 0;
IGUIEnvironment* guienv = 0;
bool progDeath = false;

ICameraSceneNode* camera = 0;

class MyEventReceiver : public IEventReceiver{
  public:	virtual bool OnEvent(SEvent event){
    if((event.EventType == EET_KEY_INPUT_EVENT) && !event.KeyInput.PressedDown){		
      switch(event.KeyInput.Key){		
        case KEY_ESCAPE:{
          return progDeath = true;
        }break;		
      }
    }
    return false;
  }
};

int main(){
  MyEventReceiver receiver;
  device = createDevice(EDT_DIRECTX8, dimension2d<s32>(600, 400), 16, false, false, &receiver);

  device->setWindowCaption(L"Hello World! - Irrlicht Engine");
  
  driver = device->getVideoDriver();
  smgr = device->getSceneManager();
  guienv = device->getGUIEnvironment();

  guienv->addStaticText(L"Hello World! (Dev-C++ - Irrlicht-Template, by Acki B.)", rect<int>(10,10,250,30), true);

  IAnimatedMesh* mesh = smgr->getMesh("sydney.md2");
  IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( mesh );
  if (node){
    node->setMaterialFlag(EMF_LIGHTING, false);	
    node->setFrameLoop(0, 310);	
    node->setMaterialTexture( 0, driver->getTexture("sydney.bmp"));
  }
  
  camera = smgr->addCameraSceneNodeFPS(0, 100, 300, -1, keyMap, 8);
  camera->setPosition(vector3df(0,20,-40));
  device->getCursorControl()->setVisible(false);
  
  while(device->run()){
    driver->beginScene(true, true, SColor(0,100,100,100));
    smgr->drawAll();
    guienv->drawAll();
    driver->endScene();
    
    if(progDeath){
      device->closeDevice();
    }
  }
  device->drop();
  return 0;
}
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Dogs
Posts: 195
Joined: Wed Sep 15, 2004 1:04 am
Location: michigan

Post by Dogs »

Now if this works That will help out dramaticaly.. Im more of a visual learner,
Sorry to be such a pest... lol
But I think you just saved the day here lol..
I think I can see what I wasnt doing allready..
Thanks for all your help Acki...
And im sure it will help many other newbies as well..
Dogs
Posts: 195
Joined: Wed Sep 15, 2004 1:04 am
Location: michigan

Post by Dogs »

Ok im glad that I have a great C++ editor and compiler that give me good debug info and hints on what is wrong with my code...
I messed around with your code on and off all day and implemented it into a simple test world,
Ive got it to compile flawlessly but yet any key that I assign to the event will not work... The program runs fine, just no exit...
Im thinking its just not initializing the event handler at all..
Here is the code and maybe Acki or someone else can see what im missing..
Its just strange that it compiles fine without error but still dosnt work..

#include <irrlicht.h>
#include <ICameraSceneNode.h>
#include <IEventReceiver.h>
#include <stdio.h>
#include <audiere.h>

using namespace irr;
using namespace audiere;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
bool Exit = false;

#pragma comment(lib, "Irrlicht.lib")
#pragma comment (lib, "audiere.lib")


int main()
{

//sets screen size and driver to use//

IrrlichtDevice *device =
createDevice(EDT_DIRECTX8, dimension2d<s32>(800, 600),32, false, true, true, 0);


//window//

device->setWindowCaption(L"TEST");
device->setResizeAble(true);
IVideoDriver* driver = device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();

//load3ds//


scene::IAnimatedMesh* mesh = smgr->getMesh(
"../../media/room.3ds");

smgr->getMeshManipulator()->makePlanarTextureMapping(
mesh->getMesh(0), 0.012f);

scene::ISceneNode* node = 0;

node = smgr->addAnimatedMeshSceneNode(mesh);
node->setMaterialTexture(0, driver->getTexture("../../media/wall.jpg"));
node->getMaterial(0).EmissiveColor.set(0,55,55,55);


//collison triangle selector//

scene::ITriangleSelector* selector = 0;

if (node)
{
selector = smgr->createOctTreeTriangleSelector(mesh->getMesh(0), node, 128);
node->setTriangleSelector(selector);
selector->drop();
}

// add animated character//

mesh = smgr->getMesh("../../media/sydney.md2");

scene::IAnimatedMeshSceneNode* anode = 0;

anode = smgr->addAnimatedMeshSceneNode(mesh);
anode->setPosition(core::vector3df(15,45,-30));
anode->setMD2Animation(scene::EMAT_STAND);
anode->setMaterialTexture(0, driver->getTexture("../../media/sydney.BMP"));

anode->addShadowVolumeSceneNode();
smgr->setShadowColor(video::SColor(140,0,0,0));




//WATER//

mesh = smgr->addHillPlaneMesh("myHill",
core::dimension2d<f32>(20,20),
core::dimension2d<s32>(40,40), 0, 0,
core::dimension2d<f32>(0,0),
core::dimension2d<f32>(10,10));

node = smgr->addWaterSurfaceSceneNode(mesh->getMesh(0), 3.0f, 300.0f, 30.0f);
node->setPosition(core::vector3df(0,7,0));

node->setMaterialTexture(0, driver->getTexture("../../media/water.jpg"));
node->setMaterialTexture(1, driver->getTexture("../../media/stones.jpg"));

node->setMaterialType(video::EMT_REFLECTION_2_LAYER);



//LIGHT//

node = smgr->addLightSceneNode(0, core::vector3df(250,250,-20),
video::SColorf(0.7f, 0.7f, 0.7f, 1.0f), 800.0f);
scene::ISceneNodeAnimator* anim = 0;


//ATTACH BILLBOARD TO LIGHT (the actual texture)//

node = smgr->addBillboardSceneNode(node, core::dimension2d<f32>(80, 80));
node->setMaterialFlag(video::EMF_LIGHTING, false);
node->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR);
node->setMaterialTexture(0, driver->getTexture("../../media/particlewhite.bmp"));



//camera section//

scene::ICameraSceneNode* camera =
smgr->addCameraSceneNodeFPS(0,100.0f,300.0f);
camera->setPosition(core::vector3df(-100,50,-150));

//disables camera movement//

camera->setInputReceiverEnabled(true);

//disable mouse cursor//


device->getCursorControl()->setVisible(false);




//add collision to cam//

anim = smgr->createCollisionResponseAnimator(
selector, camera, core::vector3df(30,15,30),
core::vector3df(0,-100,0), 100.0f,
core::vector3df(0,50,0));
camera->addAnimator(anim);
anim->drop();



//initialize audio//

AudioDevicePtr device1(OpenDevice());
if (!device1) {
// failure
}

OutputStreamPtr stream(OpenSound(device1, "../../media/sound2.mp3", true));
if (!stream) {
// failure
}

// start the sound

stream->setRepeat(true);
stream->setVolume(1.0f); // 100% volume
stream->play();


//exit code//

class MyEventReceiver : public IEventReceiver{
public: virtual bool OnEvent(SEvent event){
if ((event.EventType == EET_KEY_INPUT_EVENT) &&
!event.KeyInput.PressedDown){
switch(event.KeyInput.Key){
case KEY_ESCAPE:{
return Exit = true;
}break;
}
}
return false;
}

};

//draw//

while(device->run())
{


driver->beginScene(true, true, SColor(0,200,200,200));
smgr->drawAll();
driver->endScene();


if(Exit){
device->closeDevice();
}




//end//
}

device->drop();

return 0;
}


Its of course the exit code.. I need to figure out how to make the event code work cause I have many other things I will need this for but cant move forward tell I figure this out...
Thanks for any help...
afecelis
Admin
Posts: 3075
Joined: Sun Feb 22, 2004 10:44 pm
Location: Colombia
Contact:

Post by afecelis »

your event receiver has to be the first thing in your code, place it immediately after your bool variables.

follow this order:
1. headers
2. namespaces
3. bools
4. event receiver
5. main function
6. initialize the engine
7. add stuff -models, particles, water, terrain, etc
8. while(device->run()) --important, Exit = false; before!!!
9. ifs
10. draw all
11. drop device

I think your error is the place of your event receiver.

BTW. Which compile r u using?
Image
afecelis
Admin
Posts: 3075
Joined: Sun Feb 22, 2004 10:44 pm
Location: Colombia
Contact:

Post by afecelis »

oh yes! and change:

Code: Select all

 createDevice(EDT_DIRECTX8, dimension2d<s32>(800, 600),32, false, true, true, 0); 
for

Code: Select all

 createDevice(EDT_DIRECTX8, dimension2d<s32>(800, 600),32, false, true, true, &receiver); 
otherwise none of your boolean variables will do anything.

check Acki's code, it works fine!
Image
Dogs
Posts: 195
Joined: Wed Sep 15, 2004 1:04 am
Location: michigan

Post by Dogs »

Hmm it didnt compile for me.. I use msdev 6.0,
im wondering if this played a role most the time.. &receiver
My code isnt giving any errors it compiles perfectly after working with it some and the program runs as well lol.. just no exit lol..
Ill move it around and add &receiver and see what happens...
You sure see the lesser C++ info somone knows when looking at there code lol...
I did notice that his was before the main call and I had moved it around but got some errors but then fixed some things and then created this simple example.. I didnt think to move it back.. And maybe you can tell me technically why &receiver needs to be added...?
Thanks again for your help, At this rate ill have to start sending you Cash for all your help... lol both of you have been great help..
Thanks again..
Post Reply