PNG Transparency (other image formats too)

Hi.

When I call SDL_DisplayFormat() on a surface to convert it and
speed up blitting, I lose all alpha channel information as loaded
from the file.

How do I preserve alpha channel information? Or is this not
possible?

MC

Hello !

When I call SDL_DisplayFormat() on a surface to convert it and
speed up blitting, I lose all alpha channel information as loaded
from the file.

How do I preserve alpha channel information? Or is this not
possible?

There is a SDL_DisplayFormatAlpha(), just test this.

CU

SDL_DisplayFormatAlpha()

//David Olofson - Programmer, Composer, Open Source Advocate

.------- http://olofson.net - Games, SDL examples -------.
| http://zeespace.net - 2.5D rendering engine |
| http://audiality.org - Music/audio engine |
| http://eel.olofson.net - Real time scripting |
’-- http://www.reologica.se - Rheology instrumentation --'On Thursday 28 September 2006 20:08, mal content wrote:

Hi.

When I call SDL_DisplayFormat() on a surface to convert it and
speed up blitting, I lose all alpha channel information as loaded
from the file.

How do I preserve alpha channel information? Or is this not
possible?

SDL_DisplayFormatAlpha()

There is a SDL_DisplayFormatAlpha(), just test this.

Yes, sorry! I’ll go back to sleep now!

cheers,
MCOn 28/09/06, David Olofson wrote:
On 28/09/06, Torsten Giebl wrote:

SDL_DisplayFormatAlpha()

There is a SDL_DisplayFormatAlpha(), just test this.

Ok, I have another one…

What’s a reliable way to test if a freshly loaded image has an
alpha channel, so I know whether to call SDL_DisplayFormatAlpha()
or just plain SDL_DisplayFormat() on it?

MCOn 28/09/06, mal content <@mal_content> wrote:

On 28/09/06, David Olofson wrote:
On 28/09/06, Torsten Giebl wrote:

Le jeudi 28 septembre 2006 22:36, mal content a ?crit?:> On 28/09/06, mal content <artifact.one at googlemail.com> wrote:

On 28/09/06, David Olofson wrote:

SDL_DisplayFormatAlpha()

On 28/09/06, Torsten Giebl wrote:

There is a SDL_DisplayFormatAlpha(), just test this.

Ok, I have another one…

What’s a reliable way to test if a freshly loaded image has an
alpha channel, so I know whether to call SDL_DisplayFormatAlpha()
or just plain SDL_DisplayFormat() on it?

MC

Check for the SDL_SRCALPHA flag of the loaded surface :slight_smile:

something like :

if (surface->flags & SDL_SRCALPHA)
surface = SDL_DisplayFormatAlpha(surface);
else
surface = SDL_DisplayFormat(surface);

++

AHA!

Well that’s me sorted out then, thanks!

MCOn 28/09/06, Laurent Carlier wrote:

Check for the SDL_SRCALPHA flag of the loaded surface :slight_smile:

something like :

if (surface->flags & SDL_SRCALPHA)
surface = SDL_DisplayFormatAlpha(surface);
else
surface = SDL_DisplayFormat(surface);