New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Screen resolution change cannot be handled correctly on windows 11 platform #6556
Comments
This doesn't seem to happen in our example. Can you test the example_glfw_opengl3 example to compare?
I can think of many variants of this, which is generally confusing for users/developers, but only on other backends and platforms. But GLFW in particular enable DPI awareness and there are no known problem on GLFW+OpenGL+Windows. Likewise can you check Use Tools->Metrics and Tools->DebugLog inputs to try to inspect things. (PS: You can drag or paste images/gifs into messages without needing to host them elsewhere.) |
|
I've checked my code. Finally I found that when I
|
Wow wow you should not delete and reaffect io.Fonts. You can call its clear function, load new functions and then call the backend function to destroy/recreate fonts. |
Would you please explain more about how to reload io.Fonts or is there a FAQ mentioned this question? |
Replace your delete/new sequence by calls to the clear function + call the destroy/create function declared in imgui_impl_opengl3.h This will be streamlined and made simpler with future work. |
Thanks! I solved the black screen problem by the replacement.
Additionally, about question 3, I remove all the code about changing |
Closing this. Note that your approach will have some issues on Mac by default. We're working on standardizing a few things to make things works for everyone neatly. |
@ocornut I am trying to use the above code to reload fonts when there is a change in DPI scale. However, I kept running into the following assert:
The assertion is really with io_ref.Fonts->Build. I don't know what this assertion is checking. Could you share some light on this? The assertation only happens when I tried to clear old fonts and then reload the font. It works okay when I first loaded the font. Here is the system configuration:
Here is the snippet of code I used to load/reload fonts when DPI scale changes.
int dpi_scale_int = round(dpi_scale);
ImFont* font = io_ref.Fonts->AddFontFromFileTTF(
"./src/fonts/NotoSansSC-Light.otf",
19.0f * dpi_scale, NULL,
io_ref.Fonts->GetGlyphRangesChineseFull());
if (font == NULL) {
LOG(ERROR) << "Failed to load font file";
}
// merge in icons from Font Awesome
ImFontConfig icons_config;
icons_config.MergeMode = true;
icons_config.PixelSnapH = true;
io_ref.Fonts->AddFontFromFileTTF("./src/external/fa-solid-900.ttf",
15.0f * dpi_scale, &icons_config, icons_ranges);
io_ref.Fonts->Build();
ImGuiIO& io_ref = ImGui::GetIO();
if (io_ref.Fonts->Fonts.size()) {
io_ref.Fonts->ClearFonts();
}
ImGui_ImplOpenGL3_DestroyFontsTexture();
ImGui_ImplOpenGL3_CreateFontsTexture(); |
aboute question 3, you can modify imgui_impl_win32.cpp -> ImGui_ImplWin32_WndProcHandler function, event WM_NCMOUSEMOVE, |
Just want to chime in that if you ended up in this thread while trying to solve DPI scaling and you've still got a black window, don't call Here's what worked for me, calling it outside of NewFrame: io.Fonts->Clear();
auto font1 = io.Fonts->AddFontFromFileTTF("C:/Windows/Fonts/Arial.ttf", 16);
ImGui_ImplOpenGL3_DestroyFontsTexture();
IM_ASSERT(ImGui_ImplOpenGL3_CreateFontsTexture()); |
Thanks for creating such an amazing GUI framework, it's really great!
Here is my issue:
Version/Branch of Dear ImGui:
Version: 1.89.6
Branch: docking
Back-end/Renderer/Compiler/OS/Dependencies
Back-ends: GLFW
Renderer: OpenGL
Compiler: MSVC 2022
Operating System: Windows 11
Dependencies: imgui-node-editor and GLFW&OpenGL related(glm, glad, etc.)
My Issue/Question:
When I set the screen resolution scale to 100%, the program works fine.
When the program is running, I scale the screen resolution to 125%, the program goes black.
When my screen resolution is set to 125%, the program goes wired. The mouse cannot operate correctly, as if a single mouse position occupies multiple pixels, making it impossible to perform proper positioning and selection operations.
It seems like the screen's dpi change cannot be handled correctly. I don't know how to address this problem.
The text was updated successfully, but these errors were encountered: