Games may require restarts for display setting changes due to several technical factors:
Some game engines initialize critical systems based on the display settings during startup. These might include:
Changing these settings while the game is running could require complex reconstruction of these systems, which might be risky or impractical.
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.
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.
Answers to questions are automatically generated and may not have been reviewed.
Learn how to manage screen resolutions and refresh rates in SDL games using display modes.