Sign in to follow this  
Zaris

SDL_LoadBMP error

Recommended Posts

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; }

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 filename
char pszExe[MAX_PATH];

// get the name of the current process
GetModuleFileName(NULL, pszExe, MAX_PATH);

// make a string out of it for ease of use/safety
std::string strDirectory(pszExe);

// get rid of the filename at the end, just focus on the directory
strDirectory = 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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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