Hi Guys,
First time poster so any help or advise would be greatly appreciated…
I’m having a problem loading a bmp image. I’m basically passing the
filename to a function that does an SDL_LoadBMP. Most of the code is
from examples. I’ve been trawling through this for ages and cannot
figure out what is going on. Basically if I pass it an image that is
320x480 .bmp, it’s fine. An image of 704x16 .bmp crashes.
Tony.
Code included below…
SDL_TextureID load_image (char *image_name) {
SDL_Surface *bmp_surface;
SDL_Surface *bmp_surface_rgba;
int format = SDL_PIXELFORMAT_ABGR8888; // desired texture format
Uint32 Rmask, Gmask, Bmask, Amask; /* masks for desired format */
int bpp; /* bits per pixel for desired format */
// load the image onto a temp background
bmp_surface = SDL_LoadBMP( image_name );
if ( bmp_surface == NULL ) {
fatalError( "could not load image" ); // <<<---Crashes here--->>>
}
/* set white to transparent */
SDL_SetColorKey(bmp_surface, 1, SDL_MapRGB(bmp_surface->format,
255, 0, 255));
SDL_PixelFormatEnumToMasks(format, &bpp, &Rmask, &Gmask, &Bmask,
&Amask);
// create a new RGBA surface and blit the bmp to it
bmp_surface_rgba = SDL_CreateRGBSurface(0, bmp_surface->w,
bmp_surface->h, bpp, Rmask, Gmask, Bmask, Amask);
SDL_BlitSurface(bmp_surface, NULL, bmp_surface_rgba, NULL);
// create new texture from loaded image
SDL_TextureID texture_id = SDL_CreateTextureFromSurface( format,
bmp_surface_rgba );
if ( texture_id == 0 ) {
fatalError( “could not create new texture” );
}
// free up all allocated memory
SDL_FreeSurface( bmp_surface );
SDL_FreeSurface( bmp_surface_rgba );
return ( texture_id );
}