Windows & displaysSDL 3.2

SDL_GetWindowSizeInPixels

Reads the size of the window's drawing area in real PIXELS: what OpenGL, Vulkan and SDL_GPU draw into.

Signature

bool SDL_GetWindowSizeInPixels(SDL_Window *window, int *w, int *h);

How it works

Pass this size to glViewport, to the Vulkan swapchain extent, or use it to size an offscreen texture. It changes when the window is resized or dragged to a monitor with another density; the event SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED tells you when.

Parameters

windowSDL_Window *

The window to measure.

wint *

Where to write the width in pixels, or NULL.

hint *

Where to write the height in pixels, or NULL.

Return value

true on success, false on failure.

Tips & pitfalls

  • A minimized window can report 0Ă—0. Skip the frame: a swapchain or a projection with 0 height is invalid.

Example

example.cpp
1if (e.type == SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED) {
2    int pw, ph;
3    SDL_GetWindowSizeInPixels(window, &pw, &ph);
4    glViewport(0, 0, pw, ph);
5}
Official SDL wiki