[SDL] Problem trying to render alpha-blended sprite

Kylotan kylotan at kylotan.eidosnet.co.uk
Mon Jul 29 11:51:01 PDT 2002

krata at matfyz.cz wrote:
> On Fri, 26 Jul 2002, Kylotan wrote:
>> playerGraphicTrans =  SDL_ConvertSurface(playerGraphic,
>>     playerGraphic->format, playerGraphic->flags);
>> SDL_SetAlpha(playerGraphicTrans, SDL_SRCALPHA|SDL_RLEACCEL, 128);
>> This works perfectly, except that the first time I try to blit from
>> playerGraphicTrans, there is a small but very noticeable delay,
>> which I believe is the on-the-fly format conversion for that
>> surface.
> i am not sure but it is because RLE "compresion" correct me if i am
> wrong

You're probably right. It's just a shame that whatever it is isn't done
when SDL_ConvertSurface is called. I understand why lazy evaluation
might be useful but I would think it would be undesirable in most games.
Of course, I am probably just doing something wrong in the conversion.

> SDL_DisplayFormatAlpha copies surface to another.
> And it doesn't work because it is copied using alpha channel. Try to
> disable SDL_SRCALPHA before SDL_DisplayFormatAlpha.
> Again maybe i am wrong. But this is what i read out from sources quite
> long time ago.

It's hard to keep up with all these options. There's alpha channels and
apparently per-surface alpha and then there's colourkeys (which appear
to be converted to and alpha channel in certain circumstances) and it
all seems a mass of special cases with minimal documentation. Can I
humbly suggest that the alpha management functions are given extra
consideration for the next version of SDL? :)

And you're suggesting I disable the alpha channel, but don't I need the
alpha channel to give me my 50% opacity? Basically, I have a simple
image where I want the bits that match the colourkey to have 0% opacity
and the rest to have 50% opacity. I can't find a way of doing this that
doesn't incur an abrupt halt the first time it is drawn. I can get
around this with a useless blit beforehand, but I'm sure this shouldn't
be necessary. Thanks for your help, anyway.


More information about the SDL mailing list