imgui-rs / imgui-rs

Rust bindings for Dear ImGui
Apache License 2.0
2.64k stars 359 forks source link

imgui does not work any more #71

Closed lilianmoraru closed 5 years ago

lilianmoraru commented 7 years ago

I cloned the latest imgui-rs and the examples draw only white(later found that the little imgui window was not visible but when maximizing the entire window, it all will just go white - note that I cannot move that little window any more, on the latest master) and windows are not responsive to mouse clicks any more. I switched v0.0.14 and it was working ok, so I decided to bisect and it seems that the issue appeared in one of these 2 commits:

f33567a1dca83060f4535a9dc5c2e8ed8463edb9
43c40849c344642ba73d32d91eb05705d381f6ea

I could not find exactly which commit introduced the issue because some versions of the code were panicking.

lilianmoraru commented 7 years ago

I observed now that one of the commits is just a merge, so the issue is actually in f33567a1dca83060f4535a9dc5c2e8ed8463edb9.

cluosh commented 7 years ago

Currently experiencing a similiar issue right now (in combination with Glium). It appears to me as if the coordinates used by imgui are not corresponding to the window coordinates.

Im using a 1920x1080 screen and the y-position of everything drawn is approximately 310px off for me. If I add 310px to the window position and to the mouse position, everything is visible and working fine.

cluosh commented 7 years ago

It appears to be a change in glutin/glium:

let gl_window = display.gl_window();
let size_points = gl_window.get_inner_size_points().unwrap();
let size_pixels = gl_window.get_inner_size_pixels().unwrap();

glutin 0.8 gives me: (size_points, size_pixels) == ((1920, 1080),(1920, 1080)), while glutin 0.9 gives me this: (size_points, size_pixels) == ((1920, 1080),(2720, 1530))

cluosh commented 7 years ago

Problems are probably related to tomaka/glutin#903 and tomaka/winit#245 Glutin is apparently using the Xserver dpi correctly after 0.9. I can eliminate the problem by using xrandr --dpi 96, but it seems HiDPI is currently an issue.

I think I have a working fix, at least for Glium: https://github.com/cluosh/imgui-rs My guess is that the DPI scaling doesn't play nicely with the orthographic transform. In combination with the orthographic transformation, imgui is being scaled with the bottom left corner as pivot (instead of top left).

Gekkio commented 7 years ago

Thanks to both for taking the time to report and investigate this! Confirmed on my HiDPI laptop after forcing the DPI to another value (for some reason my Ubuntu reports 96 dpi by default).

The changes to the orthographic matrix and scissor rect fix the issue on my machine too, but I think this needs more testing. The upstream imgui library examples don't seem to scale the matrix this way and they apparently work fine on OS X. On Linux there's no DPI scaling because they use GLFW which doesn't at the moment account for HiDPI on X11.

Basically my fear is that if we do a quick change to fix it on Linux X11, it might end up breaking some other platform.

cluosh commented 7 years ago

That's my fear as well, since fixing the orthographic matrix and scissor rect manually kinda feels like a dirty hack. Especially since I'm not able to apply the fix to gfx as well, because I can't wrap my head around the y-coordinate of the gfx scissor rect.

I'll check out the imgui examples and see if I can come up with a better solution.

Gekkio commented 7 years ago

I noticed imgui-sys exports ImDrawData_ScaleClipRects, and the corresponding C++ function is used in the imgui examples to fix the scissor rect. There's also a glViewPort call that seems to affect the coordinates and might do the same thing as the matrix transform in the fix.

cluosh commented 7 years ago

So I've looked over the upstream imgui examples. Both SDL and GLFW seem to completely ignore the X11 DPI value. After hardcoding a scaling factor in the SDL example I'm facing the same problems we have. I don't have a clue why this is working on OS X and not on X11, since the transformation should essentially still be the same

Piripant commented 6 years ago

I am trying to use imgui-rs on Linux with gfx and I've got caught in this issue, which makes the library unusable. Are there any news towards a possible solution? P.S: I would be happy to contribute if it is necessary.

Gekkio commented 5 years ago

DPI handling should be much better since the winit upgrade in v0.0.19, so the problems should be gone now. Please reopen this or open new issues if you run into trouble :smiley: