Simple Question about Environment!

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.
Post Reply
Nosvera2
Posts: 16
Joined: Wed May 28, 2008 3:11 am
Location: Van Buren, Arkansas

Simple Question about Environment!

Post by Nosvera2 »

I've been tring to get Irrlicht to work for months and after reading ALL the api and documentation I have a fair understanding of how it works internally but can't get simple problems to work. For example, I am attempting to use the "device", "driver", and "environment" outside of main in functions without going out of scope but I still get "out-of-scope" errors. My code is below and is simple, create devices, call function to create image, and then go into draw loop...but I get an out-of-scope error in the function. I have also tried passing the environment into the function by reference and then adding the image but it still didn't work.

//Stellar: Test Code for Graphics

#include <irrlicht.h>

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

void createPic();

int main()
{
IrrlichtDevice* device = createDevice(EDT_SOFTWARE, core::dimension2d<u32>(640, 480));
IVideoDriver* driver = device->getVideoDriver();
IGUIEnvironment* env = device->getGUIEnvironment();

device->setWindowCaption(L"Stellar: Galaxy at War");

createPic();

while(device->run())
{
driver->beginScene(true, true, video::SColor(255,120,102,136));

env->drawAll();

driver->endScene();
}

device->drop();
return 0;
}

void createPic()
{
IGUIImage* map = env->addImage(driver->getTexture("Game_Map_v1.bmp"), position2d<int>(0,0));
}
Jake-GR
Posts: 41
Joined: Wed Jan 07, 2009 12:32 am
Location: Colorado
Contact:

Post by Jake-GR »

well you should know that *env is only in scope with main()

if you pass correct references it should work, as i have some classes in my project that take in different pointers as args
Nosvera2
Posts: 16
Joined: Wed May 28, 2008 3:11 am
Location: Van Buren, Arkansas

pointers

Post by Nosvera2 »

Below is my code for passing by reference...if I've made a mistake please tell me because I teach C++ and the syntax here is right but I still get a compile error with no explanation.

//Stellar: Test Code for Graphics

#include <irrlicht.h>

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

void createPic(IGUIEnvironment &stage);

int main()
{
IrrlichtDevice* device = createDevice(EDT_SOFTWARE, core::dimension2d<u32>(640, 480));
IVideoDriver* driver = device->getVideoDriver();
IGUIEnvironment* env = device->getGUIEnvironment();

device->setWindowCaption(L"Stellar: Galaxy at War");

createPic(*env);

while(device->run())
{
driver->beginScene(true, true, video::SColor(255,120,102,136));

env->drawAll();

driver->endScene();
}

device->drop();
return 0;
}

void createPic(IGUIEnvironment &stage)
{
IVideoDriver* stagedriver;
IGUIImage* map = stage->addImage(stagedriver->getTexture("Game_Map_v1.bmp"), position2d<int>(0,0));
}
Jake-GR
Posts: 41
Joined: Wed Jan 07, 2009 12:32 am
Location: Colorado
Contact:

Post by Jake-GR »

this is the code i use to pass it

update(irr::IrrlichtDevice* const mIrrDevice)

ive tried to use reference but it never worked, someone on irc told me to use it this way and works like a charm
Nosvera2
Posts: 16
Joined: Wed May 28, 2008 3:11 am
Location: Van Buren, Arkansas

Post by Nosvera2 »

Ok...not sure how or why this would work because its a constant and you're no longer passing by reference you're passing as a pointer...which is just passing the address and you're not able to manipulate the variable itself. Nonetheless, I have changed the function and it still doesn't work. I get the following error: [Linker Error] Undefined reference to '_imp_createDevice'
and I have no idea what that means but I get this error alot.

code below:


void createPic(IGUIEnvironment* const stage, IVideoDriver* const stagedriver);

int main()
{
IrrlichtDevice* device = createDevice(EDT_SOFTWARE, core::dimension2d<u32>(640, 480));
IVideoDriver* driver = device->getVideoDriver();
IGUIEnvironment* env = device->getGUIEnvironment();

device->setWindowCaption(L"Stellar: Galaxy at War");

createPic(env, driver);

while(device->run())
{
driver->beginScene(true, true, video::SColor(255,120,102,136));

env->drawAll();

driver->endScene();
}

device->drop();
return 0;
}

void createPic(IGUIEnvironment* const stage, IVideoDriver* const stagedriver)
{
IGUIImage* map = stage->addImage(stagedriver->getTexture("Game_Map_v1.bmp"), position2d<int>(0,0));
}
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Both your old code and your new code appear to be fine (with the exception of the garbage stagedriver pointer in createPic() in the reference-based version).

The error you are getting now is a linker error. It is most likely caused by failing to tell the linker where to find the Irrlicht library (the -L flag) or the name of the Irrlicht library (the -l flag).

You need your compile and link lines to match that used by the Irrlicht examples. If it is easier for you, you could just put your source code into one of the Irrlicht example programs (overwriting the original code) and then use the Irrlicht examples makefile.

Travis
Nosvera2
Posts: 16
Joined: Wed May 28, 2008 3:11 am
Location: Van Buren, Arkansas

Thank you all for the help!

Post by Nosvera2 »

Thank you all for the help...I am using Dev-C++ and I was including the "lib" folder in the directory but not including the linker to libirrlicht.a. I have corrected it and everything seems to be working now.
Post Reply