bool graphics_mode_init(const ScreenSetup &setup, const ColorDepthOption &color_depths) { // Log out display information Size device_size; if (get_desktop_resolution(&device_size.Width, &device_size.Height) == 0) Out::FPrint("Device display resolution: %d x %d", device_size.Width, device_size.Height); else Out::FPrint("Unable to obtain device resolution"); const char *screen_sz_def_options[kNumScreenDef] = { "explicit", "scaling", "max" }; const bool ignore_device_ratio = setup.Windowed || setup.SizeDef == kScreenDef_Explicit; const String scale_option = make_scaling_option(setup.GameFrame.ScaleDef, convert_fp_to_scaling(setup.GameFrame.ScaleFactor)); Out::FPrint("Game settings: windowed = %s, screen def: %s, screen size: %d x %d, match device ratio: %s, game scale: %s", setup.Windowed ? "yes" : "no", screen_sz_def_options[setup.SizeDef], setup.Size.Width, setup.Size.Height, ignore_device_ratio ? "ignore" : (setup.MatchDeviceRatio ? "yes" : "no"), scale_option.GetCStr()); // Game size is used when defining resolution base and proper scaling; // Box size specifies minimal wanted screen size for the game (unscaled), // it is supposed to be be equal or greater than game_size GameSizeDef game_size; game_size.Game = game.size; game_size.Box = game.size; // Prepare the list of available gfx factories, having the one requested by user at first place StringV ids; GetGfxDriverFactoryNames(ids); StringV::iterator it = std::find(ids.begin(), ids.end(), setup.DriverID); if (it != ids.end()) std::rotate(ids.begin(), it, ids.end()); else Out::FPrint("Requested graphics driver '%s' not found, will try existing drivers instead", setup.DriverID.GetCStr()); // Try to create renderer and init gfx mode, choosing one factory at a time bool result = false; for (StringV::const_iterator it = ids.begin(); it != ids.end(); ++it) { result = create_gfx_driver_and_init_mode(*it, game_size, setup, color_depths, setup.Windowed); if (result) break; graphics_mode_shutdown(); } // If all possibilities failed, display error message and quit if (!result) { display_gfx_mode_error(game_size.Box, setup.Filter, color_depths.Prime); return false; } // On success: log out new mode params and continue initialization DisplayMode dm = gfxDriver->GetDisplayMode(); ScreenResolution = dm; Rect dst_rect = gfxDriver->GetRenderDestination(); Rect filter_rect = filter->GetDestination(); Out::FPrint("Succeeded. Using gfx mode %d x %d (%d-bit) %s\n\t" "filter dest (%d, %d, %d, %d : %d x %d), render dest (%d, %d, %d, %d : %d x %d)", dm.Width, dm.Height, dm.ColorDepth, dm.Windowed ? "windowed" : "fullscreen", filter_rect.Left, filter_rect.Top, filter_rect.Right, filter_rect.Bottom, filter_rect.GetWidth(), filter_rect.GetHeight(), dst_rect.Left, dst_rect.Top, dst_rect.Right, dst_rect.Bottom, dst_rect.GetWidth(), dst_rect.GetHeight()); return true; }