[SDL] surface transparency

Brian brian.ripoff at gmail.com
Tue Jul 17 00:50:10 PDT 2007


If your surface doesn't contain an alpha channel you could get away
with using SDL_SetAlpha maybe?
http://www.libsdl.org/cgi/docwiki.cgi/SDL_5fSetAlpha

This willl allow your function to work with non RGBA surfaces.
If it does contain an alpha channel you could fall back to your routine.

It could be as simple as:
if( Src->format->Amask ) {
       SDL_SetAlpha(Src,SDL_SRCALPHA, (Uint8)(SDL_ALPHA_OPAQUE * PercentTrans));
       return;
}

I don't have a compiler here to test this on unfortunately, apologies
in advance if this doesn't work.

On 16/07/07, Patricia Curtis <patricia.curtis at gmail.com> wrote:
> Hi Guys
>         A surface or an image AFAIK can not be faded, as we cant change the
> Alpha of a surface with transparent bits, so i use this i wrote to allow me
> to fade a temp SW surface such as an image, the output from SDL_TTF Blended
> or Rotozoom, and i thought i would share it, it steps through the whole
> surface adjusting the alpha byte of each pixel. Yes it could be a lot
> faster, like only adjusting the alpha byte and stepping over the colour
> bytes, but it does what it says on the tin, so for now here it is.


More information about the SDL mailing list