From 14a760bbdb09a19a8be6e847eeb0f82c33ed45a8 Mon Sep 17 00:00:00 2001 From: Timo Kokkonen Date: Sun, 4 Apr 2010 10:37:42 +0300 Subject: [PATCH] fade_buf: Allow fading with very small increments Signed-off-by: Timo Kokkonen --- main.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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]) -- 2.45.0