Sign in to follow this  
chosenkill6

SDL image directory

Recommended Posts

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

Share this post


Link to post
Share on other sites
[quote name='ApochPiQ' timestamp='1317689401' post='4868773']
Sure; instead of SDL_LoadWhatever("foo.file"); just use SDL_LoadWhatever("images/foo.file"); and you're done :-)
[/quote]

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 [url="http://icculus.org/physfs/docs/html/"]physfs[/url], enabling you to keep all your data in one big archive file. Or use Windows resources.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this