About Screen Fading with alpha

hi…im new to SDL mailing list…

i have a problem with Alpha channel…
for now i understand Per-pixel Alpha value and Per-surface Alpha values…
so if i make transparent background png file, that would be "Per-pixel
alpha"
surface, so i cant adjust “Per-surface” alpha with “SDL_SetAlpha” function.
there was a great function set Per-pixel alpha value which posted this
mailing list by Plus II… thanks!
but it worked a fresh loaded png files, but when i try to give whole screen
alpha value, i cant make it.

i tried :

void Darken_Screen(SDL_Surface *main_screen,int alpha)
{
Set_Per_Pixel_Alpha(main_screen,128); //which got from mailing list
SDL_Flip(main_screen);
}

it failed, and i tried :

void Darken_Screen(SDL_Surface *main_screen,int alpha)
{
SDL_Surface *temp_screen;

temp_screen = 
    SDL_ConvertSurface(main_screen,main_screen->format,SDL_HWSURFACE);
Set_Per_Pixel_Alpha(temp,128);
SDL_BlitSurface(temp,NULL,main_screen,NULL);
SDL_Flip(main_screen);

}

it failed, either.
please let me know what am i doing wrong… thank you._________________________________________________________________
MSN Explorer? ??? Hotmail ??? ?? ??? ???.
??
http://explorer.msn.co.kr/?? ??? ???.

i dont know exactly but, you only set the screen to alpha value of 128 which
is only 1/2 transparent! if int alpha should be the alpha value to set:

void Darken_Screen(SDL_Surface *main_screen,int alpha)
{
Set_Per_Pixel_Alpha(main_screen,alpha); //which got from mailing list
instead of
Set_Per_Pixel_Alpha(main_screen,128); //which got from mailing list
SDL_Flip(main_screen);
}

if it doesnt help, forgive me, i dont use sdl at the moment :slight_smile:

for now i understand Per-pixel Alpha value and Per-surface Alpha values…
so if i make transparent background png file, that would be "Per-pixel
alpha"
surface, so i cant adjust “Per-surface” alpha with “SDL_SetAlpha” function.
there was a great function set Per-pixel alpha value which posted this
mailing list by Plus II… thanks!

Right, SDL does not allow blits from a surface to use both per-surface
and per-pixel alpha at the same time. I don’t know what code you are
referring to, but I presume it walks through the pixels of a surface
and scale their alpha value by a constant amount.

but it worked a fresh loaded png files, but when i try to give whole screen
alpha value, i cant make it.

The screen does not have any transparency (unless you are using OPENGLBLIT,
but I don’t think you are in this case), because there is nothing "under"
it that could show through.

If you just want to fade the screen to black (or to white, or to any
other primary or combination of primaries), the best solution is to
use the SDL gamma functions (SDL_SetGammaRamp). This is equivalent to
manipulating the screen palette in 8-bit mode and is thus fast and smooth,
but might not always be available (check the return code).

If SDL_SetGammaRamp() doesn’t work, you need to do it yourself in some
way. Either repeatedly re-paint the screen at successively darker
levels, like this:

for i = 1…255
clear the screen (call SDL_FillRect with black pixels)
paint your graphics on the screen with an alpha of (255-i)

Alternatively, you could try repeated blitting of a completely black
surface to the screen, varying the alpha levels, like this:

make a screen-sized black surface (call it “black”)
for i = 1…255
set the per-surface alpha of “black” to a(i)
blit “black” on top of the screen

You can use the fact that at iteration i, the screen already has faded
to level (255-(i-1)), so a(i) would be something like
255 - (255 * (255 - (n-1)) / (255 - n). Roundoff errors might cause
it to give undesired results however, so you may want to fade in
fewer steps than 255.