[SDL] Loading PNG files with transparency already set

Jonathan Dearborn grimfang4 at gmail.com
Fri Jul 2 06:35:06 PDT 2010


SDL_DisplayFormat and SDL_DisplayFormatAlpha are not necessary, by the way.
 They just improve performance when blitting to the display surface.

Jonny D


On Fri, Jul 2, 2010 at 9:32 AM, Jonathan Dearborn <grimfang4 at gmail.com>wrote:

> It looks like you're trying to do something fancy, but SDL_image does it
> for you.  Just to be clear, you're simply trying to load a png with an alpha
> channel?  I think your biggest concern here is that you're using
> SDL_DisplayFormat() instead of SDL_DisplayFormatAlpha().  Try this?
>
> SDL_Surface *getimage(const char *name)
>
> {
>     SDL_Surface *surface;
>
>     char path[256];
>     char msg[256];
>     strcpy(path, DATA_PREFIX);
>
>         strcat(path, "gfx/");
>
>         strcat(path, name);
>         strcat(path, ".png");
>
>     surface = IMG_Load(path);
>     if (surface == NULL)
>     {
>          strcpy(msg, path);
>         strcat(msg, " Not Loaded");
>         debug(msg,0);
>     }
>     else
>     {
>         SDL_Surface *image = surface;
>         surface = SDL_DisplayFormatAlpha(image);
>
>         SDL_FreeSurface(image);
>
>          strcpy(msg, path);
>         strcat(msg, " Loaded");
>         debug(msg,0);
>     }
>
>     return surface;
> }
>
> Jonny D
>
>
> On Fri, Jul 2, 2010 at 9:07 AM, Neil White <neil at cloudsprinter.com> wrote:
>
>> i just quicky went through my images filling in the transparent bits black
>> and they turned out looking rubbish, some have random edge lines creeping in
>> ( probably cos of gimps fill function ) and some i didnt realise just how
>> much they relied on being able to be semi transparent.. , i really need to
>> get this to work or i'll have to re do all the gfx ( AGAIN ) :-)
>>
>>
>>
>> _______________________________________________
>> SDL mailing list
>> SDL at lists.libsdl.org
>> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20100702/5353ce98/attachment.htm>


More information about the SDL mailing list