Per-surface alpha not working

Hi,
I’m sure this comes under the category of things asked about SDL every day so
apologies, but I’ve looked up resources that say how to do it and they don’t
work. I want to be able to take an SDL_Surface with some stuff on it, and blit
it to the screen with an overall level of transparency (as opposed to per-pixel
transparency, which I can do by loading in a PNG). I’ve tried using SDL_SetAlpha
on the surface before blitting, but it just goes on top opaque.

I do it like this (on a 32bit display):

/* the rmask, etc. are previously defined according to the system’s endianness */
SDL_Surface overlay = SDL_CreateRGBSurface(
SDL_HWSURFACE, screen->w, screen->h, 32,
rmask, gmask, bmask, amask);

// blah blah, painting stuff onto the surface… then set alpha

SDL_SetAlpha(overlay,SDL_SRCALPHA,128);
SDL_BlitSurface(overlay,NULL,screen,NULL);
SDL_Flip(screen);

is there anything fundamentally wrong with the way I’m going about this?

Thanks

Nick Howes

Nick Howes <csucew dcs.warwick.ac.uk> writes:

Hi,
I’m sure this comes under the category of things asked about SDL every day so
apologies,

Not to mention the category of “things that are asked and then suddenly work
about 10 minutes later”.

I read that if per-pixel alpha is enabled then this always overrides per-surface
alpha, I didn’t explicitly turn this on and my overlay surface was fully opaque,
but I tried some ways to disable per-pixel alpha. I ended up changing the
arguments for creating the overlay surface so the channel masks were all zero,
ie from this

SDL_Surface * dest = SDL_CreateRGBSurface (
SDL_HWSURFACE,
screen->w,
screen->h,
32,
rmask,gmask,bmask,amask);

to this

SDL_Surface * dest = SDL_CreateRGBSurface (
SDL_HWSURFACE,
screen->w,
screen->h,
32,
0,0,0,0);

and the usual SetAlpha stuff, and now it’s all transparent and nice, and I have
completed my gorgeous full-screen fade effect. Ahhh, it’s beautiful. Thank you
everybody for reading. I can post my fading method if it interests.

I dunno if this change breaks it for computers with other Endian-ness?