Display Settings and Game Restart
Why do some games require a restart after changing display settings while others can change them instantly?
Games may require restarts for display setting changes due to several technical factors:
Engine Architecture
Some game engines initialize critical systems based on the display settings during startup. These might include:
- Memory allocation for rendering buffers
- Creation of rendering contexts and pipelines
- Loading of shaders and textures at specific resolutions
- Setup of post-processing effects
Changing these settings while the game is running could require complex reconstruction of these systems, which might be risky or impractical.
Resource Management
Games often load and optimize resources based on the initial display settings:
class ResourceManager {
std::vector<SDL_Texture*> TextureCache;
SDL_Renderer* Renderer;
int CurrentWidth;
int CurrentHeight;
public:
ResourceManager(
SDL_Renderer* R, int W, int H
) : Renderer{R},
CurrentWidth{W},
CurrentHeight{H}
{
// Resources loaded and optimized for
// this resolution
LoadResources();
}
private:
void LoadResources() {
// Load textures at appropriate sizes
// for current resolution
// ...
// Calculate mipmap chains
// ...
// Set up render targets
// ...
}
};
Changing resolution might require reloading these resources, which could be time-consuming and memory-intensive during gameplay.
Safe Implementation
For games that do support instant changes, careful implementation is required:
#include <SDL.h>
class DynamicRenderer {
SDL_Window* Window;
SDL_Renderer* Renderer;
bool RecreateRenderer() {
// Destroy old renderer and resources
if (Renderer) {
SDL_DestroyRenderer(Renderer);
}
// Create new renderer for current settings
Renderer = SDL_CreateRenderer(
Window, -1,
SDL_RENDERER_ACCELERATED
);
return Renderer != nullptr;
}
public:
bool ChangeDisplayMode(
const SDL_DisplayMode& Mode) {
// Apply new mode
if (SDL_SetWindowDisplayMode(
Window, &Mode) < 0) {
return false;
}
// Recreate renderer for new settings
return RecreateRenderer();
}
};
The choice between instant changes and requiring a restart often comes down to balancing technical complexity against user convenience.
Display Modes
Learn how to manage screen resolutions and refresh rates in SDL games using display modes.