Jump to content
  • Advertisement
Sign in to follow this  

Loading BMP image with SDL

This topic is 2337 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to load a .bmp image with SDL but i'm not sure were to put the image so it can be found. When I add the file in the project folder and run this code I get the following output in the console: /Users/user/Library/Developer/Xcode/DerivedData/SDLExperiment-dsfnjwhgojekaeehoaipimlpnoqb/Build/Products/Debug
The image could not be located due to the following error: Couldn't open hello.bmp

#include <SDL.h>
#include <iostream>
using namespace std;
int main( int argc, char* args[] )
SDL_Surface* hello = NULL;
SDL_Surface* screen = NULL;
char title[50] = "";


screen = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE);

hello = SDL_LoadBMP("hello.bmp");
if (hello == NULL)
cout << getcwd(title, 120) << endl;
cout << "The image could not be located due to the following error: "
<< SDL_GetError() << endl;

return 1;
SDL_BlitSurface(hello, NULL, screen, NULL);




return 0;

Share this post

Link to post
Share on other sites
This is not a question about SDL or about loading bitmap but more about directory structure. I'm not used to Xcode and I find your project path to be quite long, but usually the application will search the file in a relative path to the working directory. Under Windows, when you double click an .exe, the working directory is the same as the executable. Under visual studio when you run the application from the IDE it's by default the directory of the .sln file, but can be modified in the project settings. I'm guessing it's about the same for Xcode.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!