bool OpenGLSdlGraphicsManager::loadGFXMode() { // If the screen was resized, do not change its size if (!_screenResized) { const int scaleFactor = getScale(); _videoMode.overlayWidth = _videoMode.hardwareWidth = _videoMode.screenWidth * scaleFactor; _videoMode.overlayHeight = _videoMode.hardwareHeight = _videoMode.screenHeight * scaleFactor; int screenAspectRatio = _videoMode.screenWidth * 10000 / _videoMode.screenHeight; int desiredAspectRatio = getAspectRatio(); // Do not downscale dimensions, only enlarge them if needed if (screenAspectRatio > desiredAspectRatio) _videoMode.hardwareHeight = (_videoMode.overlayWidth * 10000 + 5000) / desiredAspectRatio; else if (screenAspectRatio < desiredAspectRatio) _videoMode.hardwareWidth = (_videoMode.overlayHeight * desiredAspectRatio + 5000) / 10000; } _screenResized = false; // Setup OpenGL attributes for SDL SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); const bool isFullscreen = getFullscreenMode(); // In case we have an fullscreen mode and we are not in a rollback, detect // a proper mode to use. In case we are in a rollback, we already detected // a proper mode when setting up that mode, thus there is no need to run // the detection again. if (isFullscreen && _transactionMode != kTransactionRollback) { if (!setupFullscreenMode()) // Failed setuping a fullscreen mode return false; } _videoMode.overlayWidth = _videoMode.hardwareWidth; _videoMode.overlayHeight = _videoMode.hardwareHeight; uint32 flags = SDL_OPENGL; if (isFullscreen) flags |= SDL_FULLSCREEN; else flags |= SDL_RESIZABLE; // Create our window _hwscreen = SDL_SetVideoMode(_videoMode.hardwareWidth, _videoMode.hardwareHeight, 32, flags); #ifdef USE_RGB_COLOR detectSupportedFormats(); #endif if (_hwscreen == NULL) { // DON'T use error(), as this tries to bring up the debug // console, which WON'T WORK now that _hwscreen is hosed. if (!_oldVideoMode.setup) { warning("SDL_SetVideoMode says we can't switch to that mode (%s)", SDL_GetError()); g_system->quit(); } else // Cancel GFX load, and go back to last mode return false; } // Check if the screen is BGR format _formatBGR = _hwscreen->format->Rshift != 0; if (isFullscreen) { _lastFullscreenModeWidth = _videoMode.hardwareWidth; _lastFullscreenModeHeight = _videoMode.hardwareHeight; ConfMan.setInt("last_fullscreen_mode_width", _lastFullscreenModeWidth); ConfMan.setInt("last_fullscreen_mode_height", _lastFullscreenModeHeight); } // Call and return parent implementation of this method return OpenGLGraphicsManager::loadGFXMode(); }
bool OpenGLSdlGraphicsManager::loadGFXMode() { // If the screen was resized, do not change its size if (!_screenResized) { const int scaleFactor = getScale(); _videoMode.overlayWidth = _videoMode.hardwareWidth = _videoMode.screenWidth * scaleFactor; _videoMode.overlayHeight = _videoMode.hardwareHeight = _videoMode.screenHeight * scaleFactor; // The only modes where we need to adapt the aspect ratio are 320x200 // and 640x400. That is since our aspect ratio correction in fact is // only used to ensure that the original pixel size aspect for these // modes is used. // (Non-square pixels on old monitors vs square pixel on new ones). if (_videoMode.aspectRatioCorrection && ((_videoMode.screenWidth == 320 && _videoMode.screenHeight == 200) || (_videoMode.screenWidth == 640 && _videoMode.screenHeight == 400))) _videoMode.overlayHeight = _videoMode.hardwareHeight = 240 * scaleFactor; else _videoMode.overlayHeight = _videoMode.hardwareHeight = _videoMode.screenHeight * scaleFactor; } _screenResized = false; // Setup OpenGL attributes for SDL SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); const bool isFullscreen = getFullscreenMode(); // In case we have an fullscreen mode and we are not in a rollback, detect // a proper mode to use. In case we are in a rollback, we already detected // a proper mode when setting up that mode, thus there is no need to run // the detection again. if (isFullscreen && _transactionMode != kTransactionRollback) { if (!setupFullscreenMode()) // Failed setuping a fullscreen mode return false; } _videoMode.overlayWidth = _videoMode.hardwareWidth; _videoMode.overlayHeight = _videoMode.hardwareHeight; uint32 flags = SDL_OPENGL; if (isFullscreen) flags |= SDL_FULLSCREEN; else flags |= SDL_RESIZABLE; // Create our window _hwscreen = SDL_SetVideoMode(_videoMode.hardwareWidth, _videoMode.hardwareHeight, 32, flags); #ifdef USE_RGB_COLOR detectSupportedFormats(); #endif if (_hwscreen == NULL) { // DON'T use error(), as this tries to bring up the debug // console, which WON'T WORK now that _hwscreen is hosed. if (!_oldVideoMode.setup) { warning("SDL_SetVideoMode says we can't switch to that mode (%s)", SDL_GetError()); g_system->quit(); } else // Cancel GFX load, and go back to last mode return false; } // Check if the screen is BGR format _formatBGR = _hwscreen->format->Rshift != 0; if (isFullscreen) { _lastFullscreenModeWidth = _videoMode.hardwareWidth; _lastFullscreenModeHeight = _videoMode.hardwareHeight; ConfMan.setInt("last_fullscreen_mode_width", _lastFullscreenModeWidth); ConfMan.setInt("last_fullscreen_mode_height", _lastFullscreenModeHeight); } // Call and return parent implementation of this method return OpenGLGraphicsManager::loadGFXMode(); }
bool OpenGLSdlGraphicsManager::loadGFXMode() { // Force 4/3 if feature enabled if (_aspectRatioCorrection) _videoMode.mode = OpenGL::GFX_4_3; _videoMode.overlayWidth = _videoMode.screenWidth * _videoMode.scaleFactor; _videoMode.overlayHeight = _videoMode.screenHeight * _videoMode.scaleFactor; // If the screen was resized, do not change its size if (!_screenResized) { _videoMode.hardwareWidth = _videoMode.overlayWidth; _videoMode.hardwareHeight = _videoMode.overlayHeight; int screenAspectRatio = _videoMode.screenWidth * 10000 / _videoMode.screenHeight; int desiredAspectRatio = getAspectRatio(); // Do not downscale dimensions, only enlarge them if needed if (screenAspectRatio > desiredAspectRatio) _videoMode.hardwareHeight = (_videoMode.overlayWidth * 10000 + 5000) / desiredAspectRatio; else if (screenAspectRatio < desiredAspectRatio) _videoMode.hardwareWidth = (_videoMode.overlayHeight * desiredAspectRatio + 5000) / 10000; // Only adjust the overlay height if it is bigger than original one. If // the width is modified it can break the overlay. if (_videoMode.hardwareHeight > _videoMode.overlayHeight) _videoMode.overlayHeight = _videoMode.hardwareHeight; } _screenResized = false; // Setup OpenGL attributes for SDL SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); if (_videoMode.fullscreen) if (!setupFullscreenMode()) // Failed setuping a fullscreen mode return false; uint32 flags = SDL_OPENGL; if (_videoMode.fullscreen) flags |= SDL_FULLSCREEN; else flags |= SDL_RESIZABLE; // Create our window _hwscreen = SDL_SetVideoMode(_videoMode.hardwareWidth, _videoMode.hardwareHeight, 32, flags); #ifdef USE_RGB_COLOR detectSupportedFormats(); #endif if (_hwscreen == NULL) { // DON'T use error(), as this tries to bring up the debug // console, which WON'T WORK now that _hwscreen is hosed. if (!_oldVideoMode.setup) { warning("SDL_SetVideoMode says we can't switch to that mode (%s)", SDL_GetError()); g_system->quit(); } else // Cancel GFX load, and go back to last mode return false; } // Check if the screen is BGR format _formatBGR = _hwscreen->format->Rshift != 0; if (_videoMode.fullscreen) { _lastFullscreenModeWidth = _videoMode.hardwareWidth; _lastFullscreenModeHeight = _videoMode.hardwareHeight; ConfMan.setInt("last_fullscreen_mode_width", _lastFullscreenModeWidth); ConfMan.setInt("last_fullscreen_mode_height", _lastFullscreenModeHeight); } // Call and return parent implementation of this method return OpenGLGraphicsManager::loadGFXMode(); }