bool ALSoftwareGraphicsDriver::IsModeSupported(int driver, int width, int height, int colDepth) { if (_windowed) { return true; } if (_gfxModeList == NULL) { _gfxModeList = get_gfx_mode_list(driver); } if (_gfxModeList != NULL) { // if a list is available, check if the mode exists. This prevents the screen flicking // between loads of unsupported resolutions for (int i = 0; i < _gfxModeList->num_modes; i++) { if ((_gfxModeList->mode[i].width == width) && (_gfxModeList->mode[i].height == height) && (_gfxModeList->mode[i].bpp == colDepth)) { return true; } } strcpy(allegro_error, "This graphics mode is not supported"); return false; } return true; }
int ALSoftwareGraphicsDriver::FindSupportedResolutionWidth(int idealWidth, int height, int colDepth, int widthRangeAllowed) { if (_gfxModeList == NULL) { _gfxModeList = get_gfx_mode_list(GetAllegroGfxDriverID(false)); } if (_gfxModeList != NULL) { int unfilteredWidth = idealWidth; _filter->GetRealResolution(&idealWidth, &height); int filterFactor = idealWidth / unfilteredWidth; int nearestWidthFound = 0; for (int i = 0; i < _gfxModeList->num_modes; i++) { if ((_gfxModeList->mode[i].height == height) && (_gfxModeList->mode[i].bpp == colDepth)) { if (_gfxModeList->mode[i].width == idealWidth) return idealWidth / filterFactor; if (abs(_gfxModeList->mode[i].width - idealWidth) < abs(nearestWidthFound - idealWidth)) { nearestWidthFound = _gfxModeList->mode[i].width; } } } if (abs(nearestWidthFound - idealWidth) <= widthRangeAllowed * filterFactor) return nearestWidthFound / filterFactor; } return 0; }
static void GetVideoModes() { /* Need to set a gfx_mode as there is NO other way to autodetect for * cards ourselves... and we need a card to get the modes. */ set_gfx_mode(_fullscreen ? GFX_AUTODETECT_FULLSCREEN : GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0); GFX_MODE_LIST *mode_list = get_gfx_mode_list(gfx_driver->id); if (mode_list == NULL) { memcpy(_resolutions, default_resolutions, sizeof(default_resolutions)); _num_resolutions = lengthof(default_resolutions); return; } GFX_MODE *modes = mode_list->mode; int n = 0; for (int i = 0; modes[i].bpp != 0; i++) { uint w = modes[i].width; uint h = modes[i].height; if (w >= 640 && h >= 480) { int j; for (j = 0; j < n; j++) { if (_resolutions[j].width == w && _resolutions[j].height == h) break; } if (j == n) { _resolutions[j].width = w; _resolutions[j].height = h; if (++n == lengthof(_resolutions)) break; } } } _num_resolutions = n; SortResolutions(_num_resolutions); destroy_gfx_mode_list(mode_list); }
int install() { int screen_mode; if(IsInstalled) return 0; if(allegro_init()) return 1; if(install_allegro_gl()) return 1; set_window_title("Sharp Fighters"); Resolutions=get_gfx_mode_list(GFX_OPENGL_FULLSCREEN); LoadSettings(); LoadCollisionData(); if(install_keyboard()) return 1; if(install_timer()) return 1; if(install_sound(DIGI_AUTODETECT, MIDI_NONE, NULL)) return 1; JoyStickEnabled=(install_joystick(JOY_TYPE_AUTODETECT)==0); JoyStickEnabled=JoyStickEnabled && num_joysticks; LoadInput(); if(install_fonts()) printf("One or more font files were not loaded.\n"); allegro_gl_set(AGL_COLOR_DEPTH, depth); allegro_gl_set(AGL_RENDERMETHOD, 1); allegro_gl_set(AGL_DOUBLEBUFFER, 1); allegro_gl_set(AGL_SUGGEST, AGL_COLOR_DEPTH | AGL_DOUBLEBUFFER | AGL_RENDERMETHOD); if(Fullscreen) screen_mode=GFX_OPENGL_FULLSCREEN; else screen_mode=GFX_OPENGL_WINDOWED; if (set_gfx_mode(screen_mode, Width,Height, 0, 0)) { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message("Unable to set graphic mode\n%s\n", allegro_error); return 1; } set_close_button_callback(close_button_handler); SetOpenGL2D(); screenimage=(IMAGE*)malloc(sizeof(IMAGE)); screenimage->ID=0; AspectRatio=(float)SCREEN_W/(float)SCREEN_H; if(install_int(Ticks,1)) return 1; if(install_int(ProcessKeys,25)) return 1; IsInstalled=1; return 0; }