How can I implement fade-in/fade-out

void Screen::fade_in(void)
{
int i;
SDL_Surface *surface;

    surface = load_image("black.bmp");
    if(surface == NULL) {
            fprintf(stderr, "Load image error: %s\n",

SDL_GetError()); exit(-1);
}
for (i=2;i<=256;i<<=1) {

            SDL_SetAlpha(surface,SDL_RLEACCEL,(Uint8)i);
            SDL_BlitSurface(surface,NULL,screen,NULL);
            update();
    }

}

This code does’nt work!

SDL_SetAlpha(surface,SDL_RLEACCEL,(Uint8)i);
This code does’nt work!

Try this:

SDL_SetAlpha(surface,SDL_RLEACCEL | SDL_SRCALPHA,(Uint8)i);

Without SDL_SRCALPHA, blitting will ignore the alpha value you specified
and just copy the pixels instead of blending them.

–ryan.

? Sun, 09 Dec 2007 07:47:34 -0500
"Ryan C. Gordon" ??:

SDL_SetAlpha(surface,SDL_RLEACCEL,(Uint8)i);
This code does’nt work!

Try this:

SDL_SetAlpha(surface,SDL_RLEACCEL | SDL_SRCALPHA,(Uint8)i);

Without SDL_SRCALPHA, blitting will ignore the alpha value you
specified and just copy the pixels instead of blending them.

–ryan.

Thanks, I should remember this.> _______________________________________________

SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

If you are changing the alpha over a short period of time, for
fade-in/fade-out effects, I think you will get the best performance if you
leave out the SDL_RLEACCEL, as I think that it will re-encode the RLE
compression each time, making the blit slower… I always thought that, at
any rate, and have left the rle accel off for fades in my programs.
If I’m wrong, someone please correct me!
-Dave> ----- Original Message -----

From: icculus@icculus.org (icculus)
To: "A list for developers using the SDL library. (includes SDL-announce)"

Sent: Sunday, December 09, 2007 6:47 AM
Subject: Re: [SDL] How can I implement fade-in/fade-out

SDL_SetAlpha(surface,SDL_RLEACCEL,(Uint8)i);
This code does’nt work!

Try this:

SDL_SetAlpha(surface,SDL_RLEACCEL | SDL_SRCALPHA,(Uint8)i);

Without SDL_SRCALPHA, blitting will ignore the alpha value you specified
and just copy the pixels instead of blending them.

–ryan.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

? Sun, 9 Dec 2007 07:54:47 -0600
"David Olsen" ??:

If you are changing the alpha over a short period of time, for
fade-in/fade-out effects, I think you will get the best performance
if you leave out the SDL_RLEACCEL, as I think that it will re-encode
the RLE compression each time, making the blit slower… I always
thought that, at any rate, and have left the rle accel off for fades
in my programs. If I’m wrong, someone please correct me!
-Dave

I try to removed SDL_RLEACCEL, but nothing happened, probably it has
little effects on my game.> ----- Original Message -----

From: “Ryan C. Gordon”
To: “A list for developers using the SDL library. (includes
SDL-announce)”
Sent: Sunday, December 09, 2007 6:47 AM
Subject: Re: [SDL] How can I implement fade-in/fade-out

SDL_SetAlpha(surface,SDL_RLEACCEL,(Uint8)i);
This code does’nt work!

Try this:

SDL_SetAlpha(surface,SDL_RLEACCEL | SDL_SRCALPHA,(Uint8)i);

Without SDL_SRCALPHA, blitting will ignore the alpha value you
specified and just copy the pixels instead of blending them.

–ryan.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org