While the operating system can handle DPI scaling automatically, there are several important reasons why we should handle it ourselves:
When we let the operating system handle scaling, it's essentially taking our rendered output and stretching it to fit the screen. This is like taking a small image and making it bigger - it gets blurry. Here's a comparison:
#include <SDL.h>
#include <iostream>
void CompareScaling(SDL_Window* Window) {
SDL_Surface* Surface{
SDL_GetWindowSurface(Window)};
// Draw a small detailed pattern
for (int y = 0; y < 10; ++y) {
for (int x = 0; x < 10; ++x) {
SDL_Rect Pixel{x * 2, y * 2, 1, 1};
SDL_FillRect(Surface, &Pixel,
SDL_MapRGB(Surface->format,
(x + y) % 2 ? 255 : 0, // Red
0, // Green
0 // Blue
));
}
}
}
When the OS scales this pattern, the individual pixels become blurry. When we handle scaling ourselves, we can render at the native resolution, keeping everything sharp.
By handling DPI scaling ourselves, we can:
OS-level scaling can be less efficient because:
By handling scaling ourselves, we can optimize each element individually and avoid unnecessary scaling operations.
Answers to questions are automatically generated and may not have been reviewed.
Learn how to create SDL applications that look great on modern displays across different platforms