thedmd / imgui-node-editor

Node Editor built using Dear ImGui
MIT License
3.6k stars 536 forks source link

Screen resolution change cannot be handled correctly on windows 11 platform #239

Open cliche9 opened 1 year ago

cliche9 commented 1 year ago

Thanks for creating such an amazing node-editor framework, it's really great!

Here is my issue which has been raised in imgui issues. Here is the link to this issue: https://github.com/ocornut/imgui/issues/6556#issue-1778994593

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:

  1. When I set the screen resolution scale to 100%, the program works fine.
  2. When the program is running, I scale the screen resolution to 125%, the program goes black.
  3. 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.

I already checked my code, I have a same code structure like the blueprint example, but the problem still exists, any ideas about this?

wecand0 commented 1 year ago

Hi, I solved this issue with adding determing scale factor. Add such method in application/platform_glfw.cpp

float getDisplayScaleFactor() {
    float xscale = 1.f;
    float yscale = 1.f;
    auto monitor = glfwGetPrimaryMonitor();
    if (monitor)
        glfwGetMonitorContentScale(monitor, &xscale, &yscale);
    return 0.5f * (xscale + yscale);
}

And change UpdatePixelDencity() to :

void PlatformGLFW::UpdatePixelDensity() {
    float xscale, yscale;
    glfwGetWindowContentScale(m_Window, &xscale, &yscale);
    float scale = xscale > yscale ? xscale : yscale;

#if PLATFORM(WINDOWS)
    float windowScale = scale;
    float framebufferScale = scale;
#else
    float windowScale = getDisplayScaleFactor();//1.0f;
    float framebufferScale = scale;
#endif

    SetWindowScale(windowScale);// this is how windows is scaled, not window content

    SetFramebufferScale(framebufferScale);
}
Tianyun-Xuan commented 1 year ago

float getDisplayScaleFactor() { float xscale = 1.f; float yscale = 1.f; auto monitor = glfwGetPrimaryMonitor(); if (monitor) glfwGetMonitorContentScale(monitor, &xscale, &yscale); return 0.5f * (xscale + yscale); }

Thanks this works for me