this is teh code I have currently, but it doesn’t work…
class ScreenData
{
public:
// I didn’t put these functions in this code…no point
void set( int xres, int yres, int bbp, Uint32 flags ); /* Set video
(will clear previous page if set) /
void setgl( int xmin, int ymin, int xmax, int ymax ); / set opengl
window */
void fade( Uint32 timelimit, int steps, int sfadealpha, int ffadealpha
);
SDL_Surface *page; /* Screen
Surface */
};
void ScreenData::fade( Uint32 stepdelay, int steps, int sfadealpha, int
ffadealpha )
/*
Fades the screen in [steps] amount of steps within the given [timelimit]
ms
If timelimit or steps is 0, displays blit (directly from fadetor,
fadetog, fadetob)
*/
{
Uint32 starttime = SDL_GetTicks (); // base time on
current ticks
if( steps > 0 ) {
Uint8 alphadist = (Uint8)ffadealpha - (Uint8)sfadealpha;
Uint8 alphastep = (Uint8)steps / alphadist;
Uint8 calpha = (Uint8)sfadealpha;
int cstep;
int res;
cstep = steps;
while( cstep > 0 )
// Loop while we are under our time limit ( + 1 is used so we hit
the time right on the dot )
{
res = SDL_SetAlpha( page, SDL_SRCALPHA, sfadealpha ); // reset
if( res == -1 ) system( “PAUSE : ECHO cannot set alpha!” );
res = SDL_SetAlpha( page, SDL_SRCALPHA, calpha );
if( res == -1 ) system( "PAUSE : ECHO cannot set alpha!" );
SDL_Flip( page );
SDL_Delay( stepdelay );
calpha += alphastep;
cstep -= 1;
}
} else {
// alphblend, then flip...bakes in under a second (unless you have a
wicked huge screen res)
SDL_SetAlpha( page, SDL_SRCALPHA, (Uint8)ffadealpha );
}
}
any suggestions? I’m not quite sure what’s wrong with this code…in
theory, it would work, but evidently not in practice
Alex~On 1/5/06, Ricardo Cruz wrote:
Yep, I think that’s the best solution. I saw a guy using SDL_SetGamma(),
but
that’s really ugly, because it changes the gamma of the whole desktop, at
least in X11.
By the way, feel free to use this code of mine:
?
#define LOOP_DELAY 20.0
void Screen::fadeout(int fade_time)
{
float alpha_inc = 256 / (fade_time / LOOP_DELAY);
float alpha = 255;
SDL_Surface *screen_copy, *black_surface;
screen_copy = SDL_CreateRGBSurface (surface->flags|SDL_SRCALPHA,
surface->w, surface->h, surface->format->BitsPerPixel,
surface->format->Rmask, surface->format->Gmask,
surface->format->Bmask,
surface->format->Amask);
if(screen_copy == NULL)
{
std::cerr << “Error: could not create screen copy for fading.\n”
"SDL error: " << SDL_GetError() << std::endl;
return;
}
SDL_BlitSurface(surface, NULL, screen_copy, NULL) ;
black_surface = SDL_CreateRGBSurface (surface->flags|SDL_SRCALPHA,
surface->w, surface->h, surface->format->BitsPerPixel,
surface->format->Rmask, surface->format->Gmask,
surface->format->Bmask,
surface->format->Amask);
if(black_surface == NULL)
{
std::cerr << “Error: could not create black surface for fading.\n”
"SDL error: " << SDL_GetError() << std::endl;
SDL_FreeSurface(screen_copy);
return;
}
SDL_FillRect(black_surface, NULL, 0);
while(alpha > 0)
{
SDL_SetAlpha(black_surface, SDL_SRCALPHA, (Uint8)(255-alpha));
SDL_BlitSurface(screen_copy, NULL, surface, NULL);
SDL_BlitSurface(black_surface, NULL, surface, NULL);
SDL_Flip(surface);
SDL_Delay(int(LOOP_DELAY));
alpha -= alpha_inc;
}
clear_screen(Color::black);
update();
}
?
Cheers,
Ricardo Cruz
Em Quarta, 4 de Janeiro de 2006 22:43, o Ryan C. Gordon escreveu:
I’m designing an introduction to a game that I’m making, and I wanted
the screen to fade to black. I think I need a YUV Overlay, but I
don’t
know, nor do I know how to use it.
A YUV overlay isn’t what you need.
You’ll need to enable alpha blending on the surfaces before blitting
them. Like this code…
SDL_SetAlpha(SDL_SRCALPHA, 127);
SDL_BlitSurface( logo2, NULL, scrn, &coord );
…will blit logo2 half-blended with the contents of the screen (which
will be black, in this case, since you did a FillRect()…). An alpha of
0 is completely faded out, and 255 is completely visible.
So just change the alpha every frame (or, rather, you’ll want to take
SDL_GetTicks() into account so you fade it smoothly over X
milliseconds).
Alpha blending is a performance hit, so be careful how and when you
enable it.
–ryan.
–
We don’t understand the software, and sometimes we don’t understand the
hardware, but we can ___see the blinking lights!
SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl
–
Smith: "…Why, Mr Anderson, Why - Do - You - Persist?"
Neo: “Because I choose to.”
-Matrix Revolutions