SDL image directory

Started by
4 comments, last by rip-off 12 years, 6 months ago
In the game that i am working on, the amount of graphics is getting a bit large, so is there anyway that i can put my images in a different directory than the .exe or can i somehow load the images into the .exe?
Thanks
Advertisement
Sure; instead of SDL_LoadWhatever("foo.file"); just use SDL_LoadWhatever("images/foo.file"); and you're done :-)

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]


Sure; instead of SDL_LoadWhatever("foo.file"); just use SDL_LoadWhatever("images/foo.file"); and you're done :-)


Lol i tried that before and i didnt work, but then i tried it again and it did :o
Anyway its working now, thanks :)

Is there a way to put the images in the .exe though? I have seen a couple games where it is just one .exe
How would i do that?
On Windows? Through resouce files, I believe.
Note that if you don't run the exe from the terminal (cmd.exe or whatever) from the directory in which the .EXE is present, you need to set the working directory for the EXE through the shortcut. Otherwise any relative paths you use inside the code will not be detected properly.
Relative paths are fickle, the working directory can be changed. One option is to discover the correct path during program startup (e.g. on windows you could use GetModuleFileName() (or whatever it is called) and then store that somewhere. When you load an image, concatenate this path to the executable-relative path, producing an absolute path.

This is a robust solution because if you were to target a *nix OS, where executables live in different areas from data, you only need to change the part that discovers the data path on startup, you don't need to rewrite all your image loading elsewhere. If you need to push your image directory down (e.g. you'd prefer resources/images), you can do that as a one-place fix, rather than editing every path in your program.

You could use physfs, enabling you to keep all your data in one big archive file. Or use Windows resources.

This topic is closed to new replies.

Advertisement