#include #include #include "shadow.h" /* Renders the whole scene to a bitmap */ /* TODO: consider internal and external color depths */ void render_lscene(BITMAP* b, lscene_t* s) { /* Pixel rows */ unsigned int** bpp; int y; /* Pixel columns */ unsigned int* bp; int x; /* Layer stack */ layer_t** l_begin = s->l; layer_t** k; layer_t** l; layer_t** l_end = l_begin + s->c; #if INTERNAL_DEPTH == 32 #define GETPIXEL(l, x, y) _getpixel32((*(l))->img, (x), (y)) #define MASK_COLOR MASK_COLOR_32 #endif for (bpp = (unsigned int**)b->line, y = 0; y < SCREEN_HEIGHT; bpp++, y++) { for (bp = *bpp, x = 0; x < SCREEN_WIDTH; bp++, x++) { int c; /* Find which layer to draw */ for (k = l_begin; k < l_end; k++) { c = GETPIXEL(k, x, y); if (c != MASK_COLOR) break; } /* Skip empty areas */ if (k == l_end) { *bp = 0; continue; } /* Calculate shadows */ for (l = l_begin; l < k; l++) { #if 0 /* Uncomment for plain shadows */ int o = ((*l)->z - (*k)->z) * 5; if (x < o || y < o) continue; if (GETPIXEL(l, x - o, y - o) != MASK_COLOR) break; #endif #if 0 /* Uncomment for growing shadows */ int o = ((*k)->z - (*l)->z); int xx = x + (x - 160) * (float)o / 20.0; int yy = y + (y - 100) * (float)o / 20.0; if (xx < 0 || xx > 319 || yy < 0 || yy > 199) continue; if (GETPIXEL(l, xx, yy) != MASK_COLOR) break; #endif #if 1 /* Uncomment for shrinking shadows */ int o = ((*l)->z - (*k)->z); int xx = x + (x - 160) * (float)o / 20.0; int yy = y + (y - 100) * (float)o / 20.0; if (xx < 0 || xx > 319 || yy < 0 || yy > 199) continue; if (GETPIXEL(l, xx, yy) != MASK_COLOR) break; #endif } if (l != k)+ c = (((c >> 16) / 2) << 16) + ((((c >> 8) & 0xff) / 2) << 8) + ((c & 0xff) / 2); /* Plot! */ *bp = c; } } }