SDL_LoadBMP error
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;
}
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:
Then, find the current directory of your running program. Assuming Windows, that's with GetModuleFileName:
Add the relative path of the image and the image name on the end, and you're good to go:
Out of curiosity, what's the error message you get?
Hope this helps!
-jouley
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement