Kind of a noob question - finding artwork within my .app??

Posts: 1
Joined: 2010.03
Post: #1
Hi all,

I feel really stupid here - I have only recently started coding on OSX and I tried searching the forums (I'm sure the answer is already here, I'm just using the wrong words for my search) - but:

I'm storing my graphical assets within the .app package (I'm using SDL using one of their pre-built templates for a project within XCode) - I know I can use argv[0] and get the full path to the executable then do some work to strip back to where I store my artwork - I was wondering is there an easier way anyone knows of to get the full path up to the .app? so I could end up with a variable that has something like (this is an experiment using OpenGL for 2D work, hence the name 2dogltest):


instead of what I get with argv[0]:


Thoughts appreciated - I'm sure there is a way. I could take getcwd and add my app name to it, but then arises a problem if someone renames the actual app for some odd reason or another...
Quote this message in a reply
Posts: 1,487
Joined: 2002.09
Post: #2
There is a method in SDLMain.m that sets the working directory to the application's enclosing folder. The following snippet sets the working directory to the app's resources directory instead. Presumably that is where you are putting the game's assets in the bundle.

- (void) setupWorkingDirectory:(BOOL)shouldChdir
        char parentdir[MAXPATHLEN];
        CFURLRef url = CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle());
        if(CFURLGetFileSystemRepresentation(url, true, (unsigned char *)parentdir, MAXPATHLEN))
            assert(chdir(parentdir) == 0);   /* chdir to the resources directory */

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Posts: 484
Joined: 2008.04
Post: #3
OneSadCookie usually points people to this blog post:

Howling Moon Software - CrayonBall for Mac and iPhone, Contract Game Dev Work
Quote this message in a reply
Post Reply