[SDL] Need some help: cross platform resource loading(Windows/Linux/OSX)...

Holmes Futrell hfutrell at umail.ucsb.edu
Thu May 22 10:58:08 PDT 2008


Hi Jesse,

Oops, my code segment was not totally right.  The code I gave you was  
for changing the current working directory to the the resources  
directory of the bundle.  This is what you need to do if you decide to  
keep your resources in the bundle, along with the executable.

In the case that you'd like to keep your resources in an external  
folder, you can do what I sent you, but then add the line  
chdir("../../../../"); to set the working directory a few directories  
higher.  I don't know if there is a better way than this.

- Holmes

On May 22, 2008, at 10:45 AM, Holmes Futrell wrote:

> Hi Jesse,
>
> My primary experience is with Mac OS X, so let me comment on that.
>
> On Mac OS X, executables and their related resources are typically  
> grouped together into application "bundles".  These bundles are just  
> special folders, but they appear as applications to users (who can  
> double click them to launch them).  In XCode you can add a resource  
> to the application bundle by placing it under the "resources"  
> grouping in the side bar.  After compilation, XCode will place the  
> resource into the Contents/Resources directory of the application  
> bundle.
>
> To locate the resources within the bundle you can use the Objective- 
> C class NSBundle or you can use CFBundle if you're working in  
> straight C.  I guess you could also locate the resources manually  
> within your bundle, if you were so inclined.
>
> To make your app look like a "real" Mac OS X application, you should  
> keep the executable in an application bundle, but if you'd prefer,  
> you could still keep your resources in external folders in the same  
> way that you are doing on windows.  Just keep in mind that when you  
> launch your Mac OS X application, the current working directory will  
> be the executable's directory (which is located within the  
> application bundle) rather than the directory of the application  
> bundle.  So on Mac OS X you'll have to go through the extra step of  
> changing the working directory.  This can be done with chdir or by  
> the following method using CFURL and CFBundle:
>
>     CFURLRef resourceURL =   
> CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle());
>     char resourcePath[4096];
>     CFURLGetFileSystemRepresentation((__CFURL*)resourceURL, TRUE,  
> (UInt8*)resourcePath, 4096);	
>     chdir(resourcePath);	
>     CFRelease(resourceURL);
>
> - Holmes
>
>
> On May 22, 2008, at 4:27 AM, Jesse P. wrote:
>
>> Need some help: cross platform resource loading(Windows/Linux/OSX)...
>>
>>
>> Hi,
>>
>> I wrote an SDL based game for Windows.
>>
>> I have a friend working on the Linux and Mac OSX version now.
>> He is having some difficulty in the porting to these platforms.
>>
>> Here is a sample of my code:
>> *Spritebmp[0] = SDL_LoadBMP("Graphics/Title Screen Graphics/ 
>> SimpleDirectmediaLayer_Logo.bmp"); *
>>
>> The above code is the Windows implementation.
>> (on Windows platform, the resources are stored in a folder in the  
>> executables folder)
>>
>> How would we load resources on Linux and Mac OSX platforms ?
>> (solution must work on Windows, Linux, and Max OSX platforms)
>>
>> Thanks in advanced!
>>
>>
>> PS - This is the game:
>> http://www.silentheroproductions.com/games_pc_windows_lettersfall_100percent.htm
>>
>>
>>
>> Jesse "JeZ+Lee"
>> slnthero at aol.com
>> Silent Hero Productions(R)
>> http://www.SilentHeroProductions.com
>>
>> _______________________________________________
>> SDL mailing list
>> SDL at lists.libsdl.org
>> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
>
> _______________________________________________
> SDL mailing list
> SDL at lists.libsdl.org
> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20080522/854af6bc/attachment-0001.htm>


More information about the SDL mailing list