trouble with SDL_LoadBMP

-Rice-
Unregistered
 
Post: #1
I am having trouble with SDL_LoadBMP function. It is copied straight from Jonh Halls book (thank you John for allowing this in a pdf format for public consumption). Example 4-3 on page 84 (book) or 102 (pdf) is returning error stating "Couldn't open test-image.bmp".

what I am doing:
-creating the SDL application in project builder (SDL Application option)
-adding the source code from the book. I copied this out of acrobat so there should be no typo mistakes.
-add the file test-image.bmp via pb's project->add files... menu. Checking copy items into destination group's folder (if needed) button.
-build. here I get the error annotated above.

other sdl projects compile fine up to this point, but no idea. I have tested this at home and at work and fails both places. Home is compiled on an iMac G3 333 w/ 168 mb ram, and at work on a 350 Blue white G3 w/192 mb ram. Both are running OS X10.2.6 and pb 2.0.1 SDL is version 1.2.6 at work and 1.2.5 at home

thank you,

Rice
Quote this message in a reply
Member
Posts: 156
Joined: 2002.10
Post: #2
OK I don't know the exact book you are talking about but here are a few things about loading images.

You need to be sure of where the image file is. If you have added it to your project it will likely have been added in the Bundle Resources section (look in the Targets section of PB).

In that case the path you need to use to open the image is

"MyApp.app/Contents/Resources/test-image.bmp"

because the file loader starts looking in the same folder as your .app but the image is stored inside the .app itself.

I think this will work.

BTW If you're wanting to load lots of images, and also ones that aren't BMP, the SDL_image framework is great.

- Iain
Quote this message in a reply
Nibbie
Posts: 2
Joined: 2012.06
Post: #3
if you are using the 'open' or 'fopen' interfaces, then you
need to put your bmp file in the same directory as the
application bundle. (don't add it to the Resources folder
for the project).

That probably means going into the build folder and putting
the image there.

in order to access the image inside to application bundle,
you would need to get a reference to the mainBundle and
then get the path for the Resources directory. Then you can
use that path plus filename to open the file.

kevin
Quote this message in a reply
-Rice-
Unregistered
 
Post: #4
THAT WORKED!!!! Thank you both for the replies. My bad on not posting the url for John Halls book. This is it below:
http://www.overcode.net/~overcode/writing/plg/
funny thing though, I can get to that page in safari, but on this computer (OS 9), I can not.

Good book, though. Again, thank you both for the help.

Rice
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #5
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Passing values to SDL_LoadBMP strangeness Lunatic 0 2,522 Sep 7, 2005 08:49 PM
Last Post: Lunatic