glfwGetWindowContentScale
Reads the display scale the user chose for the window's monitor, e.g. 1.5 for 150%.
Signature
void glfwGetWindowContentScale(GLFWwindow* window, float* xscale, float* yscale);
How it works
On high-DPI screens people enlarge everything (125%, 150%, 200%) so text stays readable. The content scale is that factor. Multiply the size of your text and user interface by it, so a 16-pixel font becomes 24 pixels at 1.5 and looks the same size as everywhere else.
It is not the same as framebuffer size Ă· window size: on Windows and X11 the window size already grows with the scale when GLFW_SCALE_TO_MONITOR is on, on macOS it never does.
Parameters
The window to ask about.
Where to write the horizontal scale, or NULL.
Where to write the vertical scale, or NULL.
Tips & pitfalls
It changes when the window moves to another monitor; glfwSetWindowContentScaleCallback tells you when.
Errors
When the call is invalid it does nothing and sets an error, which glGetError returns:
- GLFW_NOT_INITIALIZED
- Called before glfwInit or after glfwTerminate.
- GLFW_PLATFORM_ERROR
- The operating system or window system reported a failure; the description says which.
Example
1float sx, sy;
2glfwGetWindowContentScale(window, &sx, &sy);
3float fontPx = 16.0f * sy; // same apparent size at 100%, 150%, 200%