I can't upload my model

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
SanekFPS
Posts: 14
Joined: Tue Nov 14, 2023 11:53 am

I can't upload my model

Post by SanekFPS »

I don't know why, but after compilation, the program loads models not along the path relative to itself, but relative to the Win32-gcc folder. Tell me what the reason is. Here is my code.
#include <irrlicht.h>

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

#pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")

using namespace irr;

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


int main(int argc, char** argv)
{


IrrlichtDevice *device =
createDevice(EDT_SOFTWARE, dimension2du(1280, 720), 16,
false, false, false, 0);

device->setWindowCaption(L"Antenna");


IVideoDriver* driver = device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();
IGUIEnvironment* guienv = device->getGUIEnvironment();


IAnimatedMesh* ant = smgr-> getMesh("../Models/ant1.obj");




smgr->addCameraSceneNode(0, vector3df(0,30,-40), vector3df(0,5,0));


while(device->run())
{

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



driver->endScene();
}


device->drop();

return 0;
}
CuteAlien
Admin
Posts: 9651
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: I can't upload my model

Post by CuteAlien »

The ../path notation is always relative to the working directory. Where that is set depends ... for example your IDE may set it. In Visual Studio I think the default is your project file, but it can be changed in Debugging - Working Directory. In Code::Blocks it's in Build targets - Execution working dir (and default also at project file I think). Those can be useful to set when developing things.

When you start an exe from explorer then the working directory is usually the .exe path. Although it's possible to change the working directory in which an exe is started - like the "Start in" stuff you can set in shortcuts.

For application releases there are different options to handle this. Some people just expect working path is the one of the .exe and for most cases it will be fine. In many applications the installer writes the path where the program (or your media) is into the registry. And at program start your application reads that registry entry. This also makes it easier to separate your data from your executable.

There are also ways to find out the path in which your binary is. On Linux I use for example a script I copied from Loki games for this: https://github.com/mzeilfelder/hc1/blob ... /hcraft.sh
So it works when people start the script instead of the binary.

On Windows you can also set your working directory to the path of your executable at program start like this:

Code: Select all

TCHAR szPath[MAX_PATH];
GetModuleFileName(NULL, szPath, MAX_PATH);
namespace fs = std::filesystem;
fs::path exePath(szPath);

std::string workingDir = exePath.parent_path().lexically_normal().string();
SetCurrentDirectoryA(workingDir.c_str());
Note: probabaly not the best code as I mix strings and TCHAR there (but got no time right now to clean up). So depending on your compile/unicode options you may have to modify it slightly. Also you have to include <filesystem> for the fs stuff and <windows.h> for the Windows stuff I think.

Also be aware that code inside your application may change your working-directory - like file-open dialogs in Irrlicht for example. So you may have to restore it at some point. A good way to handle it is to figure out your media-path at start in some way. And then make all paths internally relative to some media-path variable.
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
SanekFPS
Posts: 14
Joined: Tue Nov 14, 2023 11:53 am

Re: I can't upload my model

Post by SanekFPS »

The problem turned out to be in the IDE Code::Blocks. I created a new project for the console type and its engine and the path began to turn out normal.
CuteAlien
Admin
Posts: 9651
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: I can't upload my model

Post by CuteAlien »

OK. Note that the working directory isn't anything engine specific but a functionality of the operating systems. You can find more info for example on MSDN by looking at documentation of SetCurrentDirectory and GetCurrentDirectory (on Linux it would be getcwd and chdir).
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
Post Reply