MCPcopy Create free account
hub / github.com/KhronosGroup/Vulkan-Samples / get_dpi_factor

Method get_dpi_factor

framework/platform/glfw_window.cpp:383–398  ·  view source on GitHub ↗

@brief It calculates the dpi factor using the density from GLFW physical size GLFW docs for dpi

Source from the content-addressed store, hash-verified

381/// @brief It calculates the dpi factor using the density from GLFW physical size
382/// <a href="https://www.glfw.org/docs/latest/monitor_guide.html#monitor_size">GLFW docs for dpi</a>
383float GlfwWindow::get_dpi_factor() const
384{
385 auto primary_monitor = glfwGetPrimaryMonitor();
386 auto vidmode = glfwGetVideoMode(primary_monitor);
387
388 int width_mm, height_mm;
389 glfwGetMonitorPhysicalSize(primary_monitor, &width_mm, &height_mm);
390
391 // As suggested by the GLFW monitor guide
392 static const float inch_to_mm = 25.0f;
393 static const float win_base_density = 96.0f;
394
395 auto dpi = static_cast<uint32_t>(vidmode->width / (width_mm / inch_to_mm));
396 auto dpi_factor = dpi / win_base_density;
397 return dpi_factor;
398}
399
400float GlfwWindow::get_content_scale_factor() const
401{

Callers 4

GuiMethod · 0.45
prepareMethod · 0.45
prepareMethod · 0.45
on_update_ui_overlayMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected