views:

1142

answers:

3

Edit: After using a bmp at toastie's suggestion, I'm still having problems loading the image:

I'm using SDL and OpenGL with Xcode and I'm trying to load an image to use as a texture on a cube. The image is a 256x256 RBG jpeg. The image is in the same directory as all of my source code, and it's under the Resources folder in the Xcode project. The file is named texture.bmp

if (textureSurface = SDL_LoadBMP("texture.bmp")) 
{
  // ...
}
else printf("%s", SDL_GetError());

I keep running it and getting the console error: Couldn't open texture.bmp

What is the path, or proper syntax for loading a file under these conditions?

+2  A: 

SDL_LoadBMP only loads BMP files as its name would suggest :)

You will need another library to load other image formats.

Try SDL_image: http://www.libsdl.org/projects/SDL_image/

or DevIL: http://openil.sourceforge.net/

Or roll your own loader: http://www.libpng.org/pub/png/libpng.html

toastie
While libpng is great and all, I don't think it will help with loading jpegs. libjpeg would be much more helpful at that =).
Adam Rosenfield
See I figured SDL_LoadBMP would load a jpeg since it's technically a bitmap. Thanks.
Hooray Im Helping
A: 

Found the answer here. Essentially the image path is relative to the application being run, so I had to move the image or make the path relative to the debug build.

Hooray Im Helping
A: 

I don't have Xcode in front of me, but I think if you right/option click on the file in your resources listing to get at the preferences for the file you can set it to be relative to the project, containing directory, etc.

Dolphin