SDL OSX Tiger

Started by
6 comments, last by Draconis_9 16 years, 1 month ago
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
Advertisement
most likely a path problem, make sure that the file path is right, that tends to be the most common problem.
--------------------------------------Not All Martyrs See Divinity, But At Least You Tried
I'm fairly certain that the file path is correct. I have tried the absolute path.
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.
What does IMG_GetError() say?
In my code IMG_Error() says nothing, in lazy foos (which i'm sure works) it says can't load image

??
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
Mark Szymczyk
Author of Mac Game Programming and Xcode Tools Sensei
http://www.meandmark.com
thanks I'll give that a try

This topic is closed to new replies.

Advertisement