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));
}
Simple Question about Environment!
pointers
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));
}
//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));
}
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));
}
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));
}
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
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
Thank you all for the help!
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.