[SDL] Alpha Channel
maos at gbl.com.br
Fri Apr 6 13:50:19 PDT 2001
Mattias Engdegård wrote:
> > Thing is, I correctly read the 32bpp TGA files - that is, I get
> >all the pixel components right, and use SDL_MapRGBA to fill in the image
> >buffer. I then use SDL_CreateRGBSurfaceFrom to create the SDL surface.
> >Well, if I call SDL_SetAlpha for that surface, the entire surface gets
> >affected, instead of a per-pixel effect. Any pointers here? BTW, the
> >SDL_CreateRGBSurfaceFrom is being called with all the color masks set to
> If you pass 0 as the colour masks in calls to SDL_CreateRGBSurface[From]
> then some default masks will be used with no alpha channel (Amask=0).
> In general, *always* specify the colour masks for non-palettized surfaces
> the TGA loader will create surfaces with an alpha channel if and only if
> the file had an alpha channel
> The per-surface alpha will only be used if the surface doesn't have an
> alpha channel
Aha! I found out what was the problem: I was calling SDL_MapRGBA
passing the screen surface's format as the format argument (by screen
surface I refer to the SDL_Surface* returned by the SDL_SetVideoMode
call). Thing is, the screen format had it's masks set as the following:
R: 0xFF0000, G: 0x00FF00, B: 0x0000FF, A: 0. Well, what I did was create
a dummy (SDL_Surface *dummy) surface, with masks 0xFF000000, 0x00FF0000,
0x0000FF00 and 0x000000FF respectively, and then passed dummy->format as
the format argument for the SDL_MapRGBA call - it worked.
Ok, but here's the catch: this whole dummy-surface thing doesn't look
like the most elegant thing to do, so I was wondering: is there a way to
specify the screen surface's masks ?
Thanks for any help,
More information about the SDL