Sign in to follow this  
Draconis_9

SDL OSX Tiger

Recommended Posts

Hi, I'm trying to get SDL to work on OSX Tiger using Xcode, however I'm getting stuck loading an image, this line of code (c++) SDL_Surface* loadedImage = IMG_Load( filename.c_str() ); always returns NULL. I'm using SDL_image also, everything compiles and links and the SDL window opens and all that, but I can't load an image to show. Even when trying to compile lazyfoo's tutorial code even they don't load the image , so I'm guessing it's something to do with my SDL? perhaps? Does anyone know of anything that might help/fix this issue? Thanks Draconis

Share this post


Link to post
Share on other sites
Be sure the image is relative to where XCode runs from. I haven't used XCode so I don't know how it works, but with visual studio...if you run the program from the IDE(instead of clicking on the binary), it gets run from where the project file is...not where the compiled binary gets put.

Share this post


Link to post
Share on other sites
Mac OS X applications use bundles. A bundle appears to the end user as a single file, but is actually a hierarchy of directories. Image and sound files normally reside in the Resources folder inside the application bundle. The SDL Xcode project templates make creating an application bundle easy. All you have to is add your image and sound files to the Resources folder in the Groups and Files list in the project window. When you build your project, Xcode copies the image and sound files to the Resource folder inside the application bundle.

The problem with SDL's Mac OS X implementation is that it sets the working directory to the directory containing the application bundle. You have to navigate the bundle directory structure to get to the Resources folder containing the image file you want to load. In your case, you would have to supply the following path to IMG_Load:

YourGameName.app/Contents/Resources/YourFilename

If you're going to do a lot of work with SDL on Mac OS X, you should modify the method -setupWorkingDirectory:, which you can find in the file SDLMain.m. Change the method so it sets the working directory to the application bundle's Resources folder. You can find directions at the following URL:

http://meandmarkpublishing.blogspot.com/2007/12/changing-sdls-working-directory-on-mac.html

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