void init_video (void) { if (! al_init_image_addon ()) error (-1, 0, "%s (void): failed to initialize image addon", __func__); al_set_new_display_flags (al_get_new_display_flags () | (display_mode < 0 ? ALLEGRO_WINDOWED : ALLEGRO_FULLSCREEN) | ALLEGRO_RESIZABLE | ALLEGRO_GENERATE_EXPOSE_EVENTS); display_width = display_width ? display_width : DISPLAY_WIDTH; display_height = display_height ? display_height : DISPLAY_HEIGHT; if (display_mode >= 0) { ALLEGRO_DISPLAY_MODE d; get_display_mode (display_mode, &d); display_width = d.width; display_height = d.height; al_set_new_display_refresh_rate (d.refresh_rate); al_set_new_display_flags (al_get_new_display_flags () & ~ALLEGRO_FULLSCREEN_WINDOW); } al_set_new_display_option (ALLEGRO_SINGLE_BUFFER, 1, ALLEGRO_SUGGEST); display = al_create_display (display_width, display_height); if (! display) error (-1, 0, "%s (void): failed to initialize display", __func__); set_target_backbuffer (display); al_set_new_bitmap_flags (ALLEGRO_VIDEO_BITMAP); al_set_window_title (display, WINDOW_TITLE); icon = load_bitmap (ICON); al_set_display_icon (display, icon); cutscene = true; if (mr.fit_w == 0 && mr.fit_h == 0) { mr.fit_w = 2; mr.fit_h = 2; } set_multi_room (1, 1); effect_buffer = create_bitmap (CUTSCENE_WIDTH, CUTSCENE_HEIGHT); black_screen = create_bitmap (CUTSCENE_WIDTH, CUTSCENE_HEIGHT); uscreen = create_bitmap (CUTSCENE_WIDTH, CUTSCENE_HEIGHT); iscreen = create_bitmap (display_width, display_height); clear_bitmap (uscreen, TRANSPARENT_COLOR); video_timer = create_timer (1.0 / EFFECT_HZ); al_init_font_addon (); builtin_font = al_create_builtin_font (); if (! builtin_font) error (-1, 0, "%s (void): cannot create builtin font", __func__); if (! al_init_primitives_addon ()) error (-1, 0, "%s (void): failed to initialize primitives addon", __func__); }
ALLEGRO_BITMAP * create_bitmap (int w, int h) { set_target_backbuffer (display); ALLEGRO_BITMAP *bitmap = al_create_bitmap (w, h); if (! bitmap) { error (-1, 0, "%s (%i, %i): cannot create bitmap", __func__, w, h); return NULL; } validate_bitmap_for_mingw (bitmap); return bitmap; }
ALLEGRO_BITMAP * load_bitmap (char *filename) { set_target_backbuffer (display); ALLEGRO_BITMAP *bitmap = load_resource (filename, (load_resource_f) al_load_bitmap); if (! bitmap) error (-1, 0, "%s: cannot load bitmap file '%s'", __func__, filename); validate_bitmap_for_mingw (bitmap); if (load_callback) load_callback (); return bitmap; }
bool set_multi_room (int w, int h) { if (w == mr.w && h == mr.h) return true; int sw = ORIGINAL_WIDTH * w; int sh = ROOM_HEIGHT * h + 11; ALLEGRO_BITMAP *b = create_bitmap (sw, sh); if (! b) return false; destroy_bitmap (b); destroy_multi_room (); mr.h = h; mr.w = w; set_target_backbuffer (display); al_set_new_bitmap_flags (ALLEGRO_VIDEO_BITMAP); screen = create_bitmap (sw, sh); effect_buffer = create_bitmap (sw, sh); black_screen = create_bitmap (sw, sh); cache = create_bitmap (sw, sh); int x, y; mr.cell = xcalloc (w, sizeof (* mr.cell)); mr.last.cell = xcalloc (w, sizeof (* mr.last.cell)); for (x = 0; x < w; x++) { mr.cell[x] = xcalloc (h, sizeof (** mr.cell)); mr.last.cell[x] = xcalloc (h, sizeof (** mr.last.cell)); for (y = 0; y < h; y++) { int x0 = ORIGINAL_WIDTH * x; int y0 = ROOM_HEIGHT * y; int sw = ORIGINAL_WIDTH; int sh = ORIGINAL_HEIGHT - (y < h - 1 ? 8 : 0); mr.cell[x][y].screen = al_create_sub_bitmap (screen, x0, y0, sw, sh); mr.cell[x][y].cache = al_create_sub_bitmap (cache, x0, y0, sw, sh); } } return true; }
void create_multi_room_bitmaps (void) { set_target_backbuffer (display); al_set_new_bitmap_flags (ALLEGRO_VIDEO_BITMAP); int x, y; for (x = 0; x < mr.w; x++) for (y = 0; y < mr.h; y++) { int sw = ORIGINAL_WIDTH; int sh = ORIGINAL_HEIGHT - (y < mr.h - 1 ? 8 : 0); destroy_bitmap (mr.cell[x][y].screen); destroy_bitmap (mr.cell[x][y].cache); mr.cell[x][y].screen = create_bitmap (sw, sh); mr.cell[x][y].cache = create_bitmap (sw, sh); clear_bitmap (mr.cell[x][y].screen, BLACK); clear_bitmap (mr.cell[x][y].cache, BLACK); } }
void flip_display (ALLEGRO_BITMAP *bitmap) { int w = al_get_display_width (display); int h = al_get_display_height (display); int uw = al_get_bitmap_width (uscreen); int uh = al_get_bitmap_height (uscreen); int flags = screen_flags | potion_flags; if (bitmap) { int bw = al_get_bitmap_width (bitmap); int bh = al_get_bitmap_height (bitmap); set_target_backbuffer (display); al_draw_scaled_bitmap (bitmap, 0, 0, bw, bh, 0, 0, w, h, flags); } else { if (has_mr_view_changed () && ! cutscene && ! no_room_drawing) { draw_multi_rooms (); force_full_redraw = true; } int iw = al_get_bitmap_width (iscreen); int ih = al_get_bitmap_height (iscreen); if (iw != w || ih != h) { destroy_bitmap (iscreen); iscreen = clone_bitmap (al_get_backbuffer (display)); } al_set_target_bitmap (iscreen); int x, y; int tw, th; mr_get_resolution (&tw, &th); for (y = mr.h - 1; y >= 0; y--) for (x = 0; x < mr.w; x++) { ALLEGRO_BITMAP *screen = (mr.cell[x][y].room || no_room_drawing || cutscene) ? mr.cell[x][y].screen : mr.cell[x][y].cache; int sw = al_get_bitmap_width (screen); int sh = al_get_bitmap_height (screen); float dx = ((ORIGINAL_WIDTH * x) * w) / (float) tw; float dy = ((ROOM_HEIGHT * y) * h) / (float) th; float dw = (sw * w) / (float) tw; float dh = (sh * h) / (float) th; if (cutscene || mr.cell[x][y].room || mr.last.display_width != w || mr.last.display_height != h || force_full_redraw) al_draw_scaled_bitmap (screen, 0, 0, sw, sh, dx, dy, dw, dh, 0); } set_target_backbuffer (display); al_draw_bitmap (iscreen, 0, 0, flags); if (mr.room_select > 0 && ! cutscene) for (y = mr.h - 1; y >= 0; y--) for (x = 0; x < mr.w; x++) if (mr.cell[x][y].room == mr.room_select) { int rx = x, ry = y; if (flags & ALLEGRO_FLIP_HORIZONTAL) rx = (mr.w - 1) - x; if (flags & ALLEGRO_FLIP_VERTICAL) ry = (mr.h - 1) - y; draw_mr_select_rect (rx, ry, GREEN); } if ((mr.room != mr.last.room || mr.x != mr.last.x || mr.y != mr.last.y || mr.w != mr.last.w || mr.h != mr.last.h) && ! cutscene) mr.select_cycles = SELECT_CYCLES; if (mr.select_cycles > 0 && ! cutscene) { int rx = mr.x, ry = mr.y; if (flags & ALLEGRO_FLIP_HORIZONTAL) rx = (mr.w - 1) - mr.x; if (flags & ALLEGRO_FLIP_VERTICAL) ry = (mr.h - 1) - mr.y; draw_mr_select_rect (rx, ry, RED); if (! pause_anim) mr.select_cycles--; } } al_draw_scaled_bitmap (uscreen, 0, 0, uw, uh, 0, 0, w, h, 0); al_flip_display (); force_full_redraw = false; }