[SDL] Alpha blending, how to

Ismael Barros razielmine at gmail.com
Sun Sep 17 17:50:34 PDT 2006


Thank you very much, I'm just starting to understand alpha blending :p

On 9/18/06, David Olofson <david at olofson.net> wrote:
> On Sunday 17 September 2006 20:03, Ismael Barros wrote:
> > Hi,
> >
> > I'm pretty new to SDL, and I don't know if it's possible to do this,
> > but I wanted to blit a 3-color surface, with a transparent color, an
> > opaque color and a semi-transparent (alpha=128) color.
> >
> > The surface I'm trying to blit is a window created with tiles
> > extracted from this palete:
> > http://img356.imageshack.us/img356/5391/windowbiggr4.png
> >
> > Black color (0, 0, 0) must be transparent, the blue of the border
> > must be opaque and the other blue (deeper) must have alpha=128
> >
> > The effect I'm trying to achieve is this:
> > http://img516.imageshack.us/img516/2704/scnv9.png
> >
> > I also can split the window in two surfaces, the opaque border and
> > the content, but I wanted to know if there is a cleaner way to do
> > it.
> >
> > Any idea?
>
> I'm not quite sure what the problem is... If you use alpha, you just
> use the alpha channel to specify how transparent each pixel should be
> - including totally transparent pixels. So, just erase the black
> pixels in GIMP, PhotoShop or whatever you're using, enable
> SDL_SRCALPHA after loading the surface, and that's it!
>
> You can get antialiazing (which is basically semi-transparent pixels
> around the otherwise jagged edges) as en extra bonus while you're at
> it. Just let GIMP/PhotoShop/... do it's usual stuff. (Most such
> applications require that you work in RGB mode to get AA.)
>
> (You *can* use colorkey together with [full surface] alpha blending,
> which is useful in some special cases - but I'm not totally sure you
> can use colorkey with an alpha channel. Why would you, anyway? Alpha
> is the more powerful method handling transparency, so if you're using
> that, why bother using colorkey?)
>
>
> //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  --'
>
> _______________________________________________
> SDL mailing list
> SDL at libsdl.org
> http://www.libsdl.org/mailman/listinfo/sdl
>




More information about the SDL mailing list