#include #include #include #include "lighting.h" /* Load bitmap in given color depth, scale to screen size, and compensate * for desired lighting effects */ static BITMAP* load_funky_bitmap(char* filename) { int x, y; BITMAP* ret; BITMAP* tmp; set_color_depth(32); ret = load_bitmap(filename, NULL); tmp = create_bitmap(ret->w, ret->h); if (use_overbright && !use_shadow) for (y = 0; y < ret->h; y++) for (x = 0; x < ret->w * 4; x += 4) { tmp->line[y][x] = ret->line[y][x] / 4 + 191; tmp->line[y][x + 1] = ret->line[y][x + 1] / 4 + 191; tmp->line[y][x + 2] = ret->line[y][x + 2] / 4 + 191; } else if (use_overbright && use_shadow) for (y = 0; y < ret->h; y++) for (x = 0; x < ret->w * 4; x += 4) { tmp->line[y][x] = ret->line[y][x]; tmp->line[y][x + 1] = ret->line[y][x + 1]; tmp->line[y][x + 2] = ret->line[y][x + 2]; } else if (!use_overbright && use_shadow) for (y = 0; y < ret->h; y++) for (x = 0; x < ret->w * 4; x += 4) { tmp->line[y][x] = ret->line[y][x] * 191 / 255; tmp->line[y][x + 1] = ret->line[y][x + 1] * 191 / 255; tmp->line[y][x + 2] = ret->line[y][x + 2] * 191 / 255; } destroy_bitmap(ret); ret = create_bitmap(SCREEN_W, SCREEN_H); stretch_blit(tmp, ret, 0, 0, tmp->w, tmp->h, 0, 0, ret->w, ret->h); destroy_bitmap(tmp); return ret; } /* Load all the funky lighting maps */ BITMAP** load_lighting_maps(void) { BITMAP** light; int i, y, x, ri, gi, bi; char filename[64]; BITMAP* tmp; light = malloc(sizeof(BITMAP*) * 29); /* Allocate bitmaps */ for (i = 0; i < 29; i++) light[i] = create_bitmap_ex(32, SCREEN_W, SCREEN_H); /* See if no special lighting effects are desired */ if (!use_overbright && !use_shadow) { for (i = 0; i < 29; i++) clear_to_color(light[i], makecol32(191, 191, 191)); return light; } /* Create the bitmaps from files on disk */ for (i = 0; i < 29; i++) { ri = i % 29; gi = (i + 9) % 29; bi = (i + 18) % 29; sprintf(filename, "resource/light.%02i.bmp", i + 1); tmp = load_funky_bitmap(filename); /* Bring the colors out of phase */ for (y = 0; y < SCREEN_H; y++) for (x = 0; x < SCREEN_W * 4; x += 4) { light[ri]->line[y][x] = tmp->line[y][x]; light[gi]->line[y][x + 1] = tmp->line[y][x + 1]; light[bi]->line[y][x + 2] = tmp->line[y][x + 2]; } } return light; }