SDL_LoadBMP error

Started by
4 comments, last by Zaris 17 years ago
I trying to load a bitmap using this function, but when I attempt the function always returns Null. ball.bmp is in the resource section of project and copy into the main folder of the project. SDL_Surface* bitmap = SDL_LoadBMP( "ball.bmp" ); if (bitmap == NULL) { printf("Unable to load bitmap: %s\n", SDL_GetError()); return 1; }
Advertisement
Quote:Original post by Zaris
I trying to load a bitmap using this function, but when I attempt the function
always returns Null. ball.bmp is in the resource section of project and copy into the main folder of the project.



SDL_Surface* bitmap = SDL_LoadBMP( "ball.bmp" );
if (bitmap == NULL)
{
printf("Unable to load bitmap: %s\n", SDL_GetError());
return 1;
}


Sound's like your using VC++, copy + paste your ball.bmp in every folder that you created the program in, it will eventually load it.
One way to make sure you're using the right path is to put the bitmap in a directory where each executable is. For example:
some folder|------------Game Folder                  |----------Game.exe                  |----------Images Folder                  |----------Sounds Folder... etc.


Then, find the current directory of your running program. Assuming Windows, that's with GetModuleFileName:
//  storage for the FULL filenamechar pszExe[MAX_PATH];//  get the name of the current processGetModuleFileName(NULL, pszExe, MAX_PATH);//  make a string out of it for ease of use/safetystd::string strDirectory(pszExe);//  get rid of the filename at the end, just focus on the directorystrDirectory = strDirectory.substr(0, strDirectory.find_last_of('\\') + 1);


Add the relative path of the image and the image name on the end, and you're good to go:
std::string strImage = strDirectory + "Image Folder\\ball.bmp";SDL_Surface* bitmap = SDL_LoadBMP(strImage.c_str( ));if (bitmap == NULL){  printf("Unable to load bitmap: %s\n", SDL_GetError());  return 1;}

Out of curiosity, what's the error message you get?

Hope this helps!
-jouley
The error I'm getting is the "file is not a windows bitmap". I am using VC standard 2003. I've created a breakout clone in VC express previously and having no problems with the image not loading.
Quote:Original post by jouley
<Stuff>

Quote:Original post by Zaris
The error I'm getting is the "file is not a windows bitmap". I am using VC standard 2003. I've created a breakout clone in VC express previously and having no problems with the image not loading.

Whoops. Well, can you verify that is is a valid bitmap file? If you try other files you know to be valid, do they work? Have you solved the problem by now?

Sorry for jumping to conclusions!
-jouley
It is a valid windows bitmap. I'm using paint.net for my artwork. It started working today without any additional changes. That was a little weird, but trying to figure it out would take a while.

This topic is closed to new replies.

Advertisement