Skip to content

Instantly share code, notes, and snippets.

@mattj1
Created October 28, 2020 18:28
Show Gist options
  • Save mattj1/606a94527badb6ffa7d22245c9b745b1 to your computer and use it in GitHub Desktop.
Save mattj1/606a94527badb6ffa7d22245c9b745b1 to your computer and use it in GitHub Desktop.
Vector2 GetWindowDPI(void)
{
float xdpi = 1.0;
float ydpi = 1.0;
#if defined(PLATFORM_DESKTOP)
Vector2 windowPos = GetWindowPosition();
int monitorCount;
GLFWmonitor **monitors = glfwGetMonitors (&monitorCount);
for(int i = 0; i < monitorCount; i++) {
glfwGetMonitorContentScale(monitors[i], &xdpi, &ydpi);
int xpos, ypos, width, height;
glfwGetMonitorWorkarea(monitors[i], &xpos, &ypos, &width, &height);
if(windowPos.x >= xpos
&& windowPos.x < xpos + width
&& windowPos.y >= ypos
&& windowPos.y < ypos + height) {
return (Vector2) { xdpi, ydpi };
}
}
#endif
return (Vector2){ 1.0, 1.0 };
}
// Later in your drawing code:
Vector2 scale = GetWindowDPI();
extern void rlViewport(int x, int y, int width, int height);
rlViewport(0, 0, VIEWPORT_WIDTH * scale.x, VIEWPORT_HEIGHT * scale.y);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment