I am writing a resource manager for a hobby game project that reads textures/fonts etc.
Up to now, I was giving the location of the files relative to the executable path, like:
my_texture.loadFromFile("textures\\my_texture.png");
However, now I realized that the relative path I'm giving is relative to the working directory of the game. So, for example, if I run the executable from my IDE (which sets the working directory to the project directory instead of executable directory), the game fails to load the texture and crashes.
I was thinking about using the main's argv[0]
and did some research on it, but apparently it is not reliable (it might just give the name of the exe).
So, how can I get the path to my resource files reliably? How does the professionals do it?
I'm using the SFML and C++17. I would like a portable solution if possible, otherwise Windows.
I checked this question but it wasn't helpful.