Display Modes

Display Settings and Game Restart

Why do some games require a restart after changing display settings while others can change them instantly?

Abstract art representing computer programming

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.

Answers to questions are automatically generated and may not have been reviewed.

sdl2-promo.jpg
Part of the course:

Game Dev with SDL2

Learn C++ and SDL development by creating hands on, practical projects inspired by classic retro games

Free, unlimited access

This course includes:

  • 71 Lessons
  • 100+ Code Samples
  • 91% Positive Reviews
  • Regularly Updated
  • Help and FAQ
Free, Unlimited Access

Professional C++

Comprehensive course covering advanced concepts, and how to use them on large-scale projects.

Screenshot from Warhammer: Total War
Screenshot from Tomb Raider
Screenshot from Jedi: Fallen Order
Contact|Privacy Policy|Terms of Use
Copyright © 2024 - All Rights Reserved