irrlicht input not working?

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.

irrlicht input not working?

Postby aburt11 » Wed Jun 06, 2012 11:40 am

hey there guys,
i was following tutorial 4 to try and get an in-game menu popping up whenever the escape key is pressed. I dont know why but this isnt happening, any ideas??
main.h
cpp Code: Select all
 
#ifndef MAIN_H_
#define MAIN_H_
 
#include <irrlicht.h>
#include <iostream>
#include <string.h>
 
 
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
 
 
 
 
 
 
//globals
class redNovember
{
public:
        // always initialize class-members in the constructor - especially set pointers to 0!
        redNovember() : device(0), driver(0), smgr(0),guienv(0)
        {}
 
 
        IrrlichtDevice *device;
        IVideoDriver* driver;
        ISceneManager* smgr;
        IGUIEnvironment* guienv;
        ICameraSceneNode * camera;
        IMetaTriangleSelector * meta;
        IGPUProgrammingServices* gpu;
        scene::IParticleSystemSceneNode* ps;
        gui::IGUIInOutFader* fader;
 
       
 
        void initIrrlicht();
        void initFPSCamera();
        void renderScene();
        int shutdown();
        void inputHandle();
 
        //for the game scenes
        void LoadScene(); // const chars for maps
        void initSkybox(const char* up,const char* down,const char* left, const char* right, const char* front, const char* back);
        void initSkydome(const char* skydomefile);
 
        //shader stuff
        void initShader();
        void VertexShader(const char* VertexShaderFilename, const char* VertexShaderFunction);
        void PixelShader(const char* PixelShaderFilename, const char* PixelShaderFunction);
        void GeoShader(const char* GeoShaderFilename, const char* GeoShaderFunction);
       
 
        void initRain();
        void initFog();
        void initBloom();
        void initHDR();
        void initSSAO();
        void initBokehDOF();
       
 
        //user interface and effects
        bool showGameMenu;
        void fadeInTransition();
        void fadeOutTransition();
 
        void showInGameMenu();
        void hideInGameMenu();
 
 
 
        //material and shader ID's
       
        s32 bloomMaterial;
        s32 bokehDOFMaterial;
        //s32 CgExampleMaterialType;
 
        //for shaders
       
        // You can put any other variables you want in here.
        // For example driver, scenemanger although you can also always get them from device
        // Note that the clean solution is making variables private and use public
        // get-functions to access them from other classes as you can see when looking at Irrlicht classes.
 
        // You can for example also create a function like that:
        //irr::scene::ISceneManager* getSceneManager() const { return device ? device->getSceneManager() : 0; }
 
};
 
class MyEventReceiver : public IEventReceiver
{
public:
        // This is the one method that we have to implement
        virtual bool OnEvent(const SEvent& event)
        {
                // Remember whether each key is down or up
                if (event.EventType == irr::EET_KEY_INPUT_EVENT)
                        KeyIsDown[event.KeyInput.Key] = event.KeyInput.PressedDown;
 
                return false;
        }
 
        // This is used to check whether a key is being held down
        virtual bool IsKeyDown(EKEY_CODE keyCode) const
        {
                return KeyIsDown[keyCode];
        }
 
        MyEventReceiver()
        {
                for (u32 i=0; i<KEY_KEY_CODES_COUNT; ++i)
                        KeyIsDown[i] = false;
        }
 
private:
        // We use this array to store the current state of each key
        bool KeyIsDown[KEY_KEY_CODES_COUNT];
};
 
 
#endif
 

main.cpp
cpp Code: Select all
 
#include "main.h"
#include "luamanager.h"
#include "physicsmanager.h"
 
LuaManager * LUA = new LuaManager;
//newtonManager* PHYS = new newtonManager;
redNovember* SYS = new redNovember;
MyEventReceiver receiver;
 
 
 
 
 
 
 
 
int redNovember::shutdown()
{
        LUA->DropLua();
        delete LUA;
        //PHYS->drop();
 
        device->drop();
       
        //delete PHYS;
        delete SYS;
        return 0;
}
 
int main()
{
       
 
        SYS->initIrrlicht();
 
 
        //PHYS->init();
        SYS->LoadScene();
        //SYS->initShader();
       
        SYS->initFPSCamera();
       
       
        SYS->initFog();
       
 
       
        LUA->loadScript("assets/scripts/test.lua");
 
       
        ///put main poop in here
        //put gui loop here
       
        SYS->initSkydome("assets/skydome/storm1.jpg");
 
       
 
 
        /*
        SYS->initSkybox("assets/skybox/citystorm/up.jpg",
                        "assets/skybox/citystorm/down.jpg",
                        "assets/skybox/citystorm/left.jpg",
                        "assets/skybox/citystorm/right.jpg",
                        "assets/skybox/citystorm/back.jpg",
                        "assets/skybox/citystorm/front.jpg");*/

       
       
        SYS->renderScene();
 
 
        SYS->shutdown();
 
}
 
void redNovember::initIrrlicht()
{
        device = createDevice(EDT_OPENGL, dimension2d<u32>(800, 600), 32,
                false, false, true,&receiver);
 
        device->setWindowCaption(L"Project: Red November");
 
        driver = device->getVideoDriver();
        smgr = device->getSceneManager();
        guienv = device->getGUIEnvironment();
 
        device->getCursorControl()->setVisible(false); //hide cursor
        fader = device->getGUIEnvironment()->addInOutFader();
 
        // Then create the event receiver, giving it that context structure.
 
 
       
        // And tell the device to use our custom event receiver.
        device->setEventReceiver(&receiver);
       
 
 
}
 
 
void redNovember::renderScene()
{
        int lastFPS = -1;
 
        while(device->run())
        {
               
                inputHandle(); //input handler
 
 
 
                if(!device->isWindowActive())
                {
                        //add pause functions here
 
 
                }
                if (device->isWindowActive())
                {
                        driver->beginScene(true, true, video::SColor(255,200,200,200));
 
 
 
 
                        smgr->drawAll();
                        guienv->drawAll();
                        device->getGUIEnvironment()->drawAll(); // draw the gui environment (the logo)
 
                        driver->endScene();
 
                        int fps = driver->getFPS();
 
                        if (lastFPS != fps)
                        {
                                core::stringw str = L"[";
                                str += driver->getName();
                                str += "] FPS:";
                                str += fps;
 
                                device->setWindowCaption(str.c_str());
                                lastFPS = fps;
                        }
                }
                else
                        device->yield();
        }
 
}
 
 
void redNovember::inputHandle()
{
        if(receiver.IsKeyDown(irr::KEY_ESCAPE))
                showGameMenu == true;
 
       
 
 
        //menu shit
                if (showGameMenu == true)
                {
                        SYS->showInGameMenu();
                }
                else
                        SYS->hideInGameMenu();
       
};
 
 

gui.cpp
cpp Code: Select all
 
#include "main.h"
 
 
void redNovember::fadeInTransition()
{
        fader->setColor(video::SColor(0,0,0,0));
        fader->fadeOut(4000);
}
 
void redNovember::fadeOutTransition()
{
        fader->setColor(video::SColor(0,0,0,0));
        fader->fadeIn(4000);
}
 
void redNovember::showInGameMenu()
{
 
       
        device->getGUIEnvironment()->addImage(
                        driver->getTexture("assets/gui/ingamemenu_placeholder.png"),
                        core::position2d<s32>(800,600)); //testing
       
                gui::IGUIStaticText* diagnostics = device->getGUIEnvironment()->addStaticText(
                        L"", core::rect<s32>(10, 10, 400, 20));
                diagnostics->setOverrideColor(video::SColor(255, 255, 255, 0));
 
        std::cout << "yep\n";
 
       
        //show the mouse cursor
        device->getCursorControl()->setVisible(true);
 
 
}
 
void redNovember::hideInGameMenu()
{
       
        //hide the mouse cursor
        device->getCursorControl()->setVisible(false);
}
 
aburt11
 
Posts: 66
Joined: Sun Jan 15, 2012 10:27 am

Re: irrlicht input not working?

Postby CuteAlien » Wed Jun 06, 2012 12:37 pm

You use == in an assignment.
"showGameMenu == true;" doesn't set the variable - it just returns true or false and the result is ignored here - so that does nothing.
IRC: #irrlicht on irc.freenode.net
My patches&stuff: http://www.michaelzeilfelder.de/irrlicht.htm
Games with Irrlicht: http://www.irrgheist.com/
News: http://www.reddit.com/r/irrlicht/
User avatar
CuteAlien
Admin
 
Posts: 5364
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany

Re: irrlicht input not working?

Postby aburt11 » Thu Jun 07, 2012 3:50 am

even if i remove the boolean value and give it a function to run when escape is pressed,it doesnt work..... is there something wrong with irrlicht documentation, maybe depreciated?
aburt11
 
Posts: 66
Joined: Sun Jan 15, 2012 10:27 am

Re: irrlicht input not working?

Postby CuteAlien » Thu Jun 07, 2012 8:37 am

No, I don't think there is anything wrong with Irrlicht here. I don't see how you fixed it - but taking another look at your code - I wonder if that is really what you want. You seem to remove the menu on pressing down ESC and immediately showing it again when you release ESC. Except that you don't remove it but only hide the mouse-cursor for a moment.

But just set a breakpoint directly behind your check for ESC and step through your program to see what is going on. Debuggers are there to make it easy to figure out what is going on in such cases (it's really as easy as saying "set breakpoint" on that line and then clicking on "step to next line" or "step into function" and you can walk through your application step-by-step while it's running and you can even watch the values of each variable etc. - just make sure your application is compiled with debug settings).
IRC: #irrlicht on irc.freenode.net
My patches&stuff: http://www.michaelzeilfelder.de/irrlicht.htm
Games with Irrlicht: http://www.irrgheist.com/
News: http://www.reddit.com/r/irrlicht/
User avatar
CuteAlien
Admin
 
Posts: 5364
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany

Re: irrlicht input not working?

Postby aburt11 » Thu Jun 07, 2012 8:56 am

well the code isnt finished yet. what i was testing to see if anything would come up at all. in this case my picture. so far it hasnt
aburt11
 
Posts: 66
Joined: Sun Jan 15, 2012 10:27 am

Re: irrlicht input not working?

Postby CuteAlien » Thu Jun 07, 2012 10:10 am

Well, just use the debugger - that's pretty much the easiest way to figure out what is going on.
Also I can see a few more potential problems just on a quick few already in your code.
- you draw the gui-environment twice (doesn't hurt, but also doesn't do anything useful)
- maybe don't add the inoutfader before you see anything - it makes stuff only more confusing (maybe you hide accidentally what you want to see)
- You place your image at position 800,600 in a device which is only that large. Which means you place it just outside the right-bottom corner, so it won't be visible.
IRC: #irrlicht on irc.freenode.net
My patches&stuff: http://www.michaelzeilfelder.de/irrlicht.htm
Games with Irrlicht: http://www.irrgheist.com/
News: http://www.reddit.com/r/irrlicht/
User avatar
CuteAlien
Admin
 
Posts: 5364
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany


Return to Beginners Help

Who is online

Users browsing this forum: No registered users and 1 guest