klenium
klenium

Reputation: 2617

SDL2 window size is bigger than it should be

I'm trying to create a window, let's say 400x400:

SDL_Init(SDL_INIT_VIDEO);
Uint32 mode = SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE;
SDL_Window* window;
SDL_Renderer* renderer;
if (SDL_CreateWindowAndRenderer(400, 400, mode, &window, &renderer))
    return 2;
if (!window || !renderer)
    return 2;
SDL_RenderClear(renderer);
SDL_RenderPresent(renderer);
SDL_Event event;
int quit = 0;
while (!quit)
{
    while (SDL_PollEvent(&event))
    {
        if (event.type == SDL_QUIT)
            quit = 1;
    }
}
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();

I see a window filled with black pixels. However, the window's size is 500x500 withouth borders, and 502x540 with them, but why?

Upvotes: 3

Views: 1108

Answers (1)

Antoine C.
Antoine C.

Reputation: 3962

On Windows, the OS may stretch your window in the case when you are using a high DPI monitor. You can disable this stretching using:

SDL_SetHint(SDL_HINT_VIDEO_HIGHDPI_DISABLED, "1")

Upvotes: 2

Related Questions