Skip to content

Commit 9f13684

Browse files
committed
Examples: GLFW+OpenGL2: Fixed not applying content scale. (ocornut#8921)
Note that this requires GLFW 3.3.
1 parent 6d25cb8 commit 9f13684

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

docs/CHANGELOG.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ Other Changes:
107107
while navigating and to not close popup automatically.
108108
- CI: Updates Windows CI to use a more recent VulkanSDK. (#8925, #8778) [@yaz0r]
109109
- Examples: Android: Android+OpenGL3: update Gradle project (#8888, #8878) [@scribam]
110+
- Examples: GLFW+OpenGL2: Fixed not applying content scale. (#8921)
110111
- Backends: SDL_GPU: Added ImGui_ImplSDLGPU3_InitInfo::SwapchainComposition and
111112
PresentMode to configure how secondary viewports are created. Currently only used
112113
multi-viewport mode. (#8892) [@PTSVU]

examples/example_glfw_opengl2/main.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ int main(int, char**)
4040
return 1;
4141

4242
// Create window with graphics context
43-
GLFWwindow* window = glfwCreateWindow(1280, 720, "Dear ImGui GLFW+OpenGL2 example", nullptr, nullptr);
43+
float main_scale = ImGui_ImplGlfw_GetContentScaleForMonitor(glfwGetPrimaryMonitor()); // Valid on GLFW 3.3+ only
44+
GLFWwindow* window = glfwCreateWindow((int)(1280 * main_scale), (int)(800 * main_scale), "Dear ImGui GLFW+OpenGL2 example", nullptr, nullptr);
4445
if (window == nullptr)
4546
return 1;
4647
glfwMakeContextCurrent(window);
@@ -57,6 +58,11 @@ int main(int, char**)
5758
ImGui::StyleColorsDark();
5859
//ImGui::StyleColorsLight();
5960

61+
// Setup scaling
62+
ImGuiStyle& style = ImGui::GetStyle();
63+
style.ScaleAllSizes(main_scale); // Bake a fixed style scale. (until we have a solution for dynamic style scaling, changing this requires resetting Style + calling this again)
64+
style.FontScaleDpi = main_scale; // Set initial font scale. (using io.ConfigDpiScaleFonts=true makes this unnecessary. We leave both here for documentation purpose)
65+
6066
// Setup Platform/Renderer backends
6167
ImGui_ImplGlfw_InitForOpenGL(window, true);
6268
ImGui_ImplOpenGL2_Init();

0 commit comments

Comments
 (0)