Jump to content
  • Advertisement
Sign in to follow this  
chosenkill6

SDL image directory

This topic is 2549 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
Sure; instead of SDL_LoadWhatever("foo.file"); just use SDL_LoadWhatever("images/foo.file"); and you're done :-)

Share this post


Link to post
Share on other sites

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?

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 physfs, 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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!