[SDL] Loading bitmaps with transparency? (Torsten Giebl)
Leo M. Cabrera
leo28c at gmail.com
Sun Mar 4 18:06:03 PST 2007
>
> Bad coding style. If IMG_Load() fails for some reason (file not found,
> corrupted file, out of memory, etc.), you'll be sending a NULL ptr to
> SDL_DisplayFormatAlpha(). I imagine that'd cause a segfault
> (aka SDL parachute launch).
Ha, yes, I do the same thing... *embarrass*
I always say; "I'll do this now, then I'll add error checking whenever I
finish the proggy..."
But when I finish it, I forget... gotta improve that. xD
Bill Kendrick wrote:
> On Sun, Mar 04, 2007 at 03:30:42PM +0700, Patricia Curtis wrote:
>
>> Its simple to use transparency just save your images as a PNG-24 which will
>> give you 255 levels of transparency and you don't have to do the colour
>> keying either.
>>
>> SDL_Surface * gLoadedImage = SDL_DisplayFormatAlpha(IMG_Load("SomePNG.png"
>> ));
>>
>
> Bad coding style. If IMG_Load() fails for some reason (file not found,
> corrupted file, out of memory, etc.), you'll be sending a NULL ptr to
> SDL_DisplayFormatAlpha(). I imagine that'd cause a segfault
> (aka SDL parachute launch).
>
> Always check for NULL and for errors!
>
>
> Of course, if I recall, they wanted to literally load Windows BitMaP (.bmp)
> files, as they were in an environment where SDL_Image library (and hence
> IMG_Load(), and hence PNG support) was unavailable.
>
> So for that, use BMP with a color-key.
>
>
More information about the SDL
mailing list