Sign in to follow this  

Loading BMP image with SDL

This topic is 2057 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: [b]/Users/user/Library/Developer/Xcode/DerivedData/SDLExperiment-dsfnjwhgojekaeehoaipimlpnoqb/Build/Products/Debug[/b]
[b]The image could not be located due to the following error: Couldn't open hello.bmp[/b]



[color=#754a2b][CODE]
#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] = "";

SDL_Init (SDL_INIT_EVERYTHING);

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);
SDL_Flip(screen);

SDL_Delay(2000);

SDL_FreeSurface(hello);

SDL_Quit();

return 0;
}
[/CODE][/color]

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

This topic is 2057 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.

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