From: Timo Kokkonen Date: Sun, 4 Apr 2010 07:37:42 +0000 (+0300) Subject: fade_buf: Allow fading with very small increments X-Git-Url: http://git.itanic.dy.fi/?p=sdl-planets;a=commitdiff_plain;h=14a760bbdb09a19a8be6e847eeb0f82c33ed45a8 fade_buf: Allow fading with very small increments Signed-off-by: Timo Kokkonen --- diff --git a/main.c b/main.c index 66272cb..d2f408a 100644 --- a/main.c +++ b/main.c @@ -8,11 +8,21 @@ #define MAX_FPS 60 -static void fade_buf(SDL_Surface *screen, int amount) +static void fade_buf(SDL_Surface *screen, double fade) { int i; unsigned int *buf = screen->pixels; unsigned char *b; + unsigned char amount; + static double threshold = 0; + threshold += fade; + + if (threshold > 1) { + amount = threshold; + threshold -= amount; + } else { + return; + } for (i = 0; i < screen->pitch * screen->h / sizeof(*buf); i ++) { if (!buf[i])