Skip to content
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

Incorrect position/scale on Mac OS #27

Open
KyleKrein opened this issue Dec 24, 2022 · 11 comments
Open

Incorrect position/scale on Mac OS #27

KyleKrein opened this issue Dec 24, 2022 · 11 comments
Labels
bug Something isn't working

Comments

@KyleKrein
Copy link

if I try to run your code on Windows, everything works, but on Mac OS there's something wrong with position or scale (or both of them). As you can see on the screenshot, I moved cursor out of the window and only after this one of the ImGui buttons became blue.
CleanShot 2022-12-24 at 20 18 53@2x

Also if I try to move the ImGui demo window, it starts to disappear if it gets out of the left bottom 1/4 part of the window
CleanShot 2022-12-24 at 20 24 32@2x

@NogginBops NogginBops added the bug Something isn't working label Dec 24, 2022
@NogginBops
Copy link
Owner

My initial guess here is that this is something related to DPI and that likely the mouse coordinates might not match up with window coordinates. I don't have a macos machine that I can test with, you could try looking at the mouse position sent to ImGui and compare it to the window size that is sent to ImGui and there will likely be some discrepancy.

@KyleKrein
Copy link
Author

the mouse coordinates might not match up with window coordinates

I've checked this, and the coordinates are correct.
Do you have any other ideas?

Also I forgot to mention, that on start and if I move window, ImGui disappears or becomes a black square

CleanShot 2022-12-25 at 03 52 57@2x
CleanShot 2022-12-25 at 03 53 03@2x

@NogginBops
Copy link
Owner

That sounds pretty weird too, my guess is that some event that is called when the window moves is doing something weird. Can you check what events get triggered when you move the window?

@KyleKrein
Copy link
Author

Actually there're no events happening. Or at least on Move event in GameWindow.
image

@KyleKrein
Copy link
Author

So I managed to make ImGui use the whole window, not 1/4 part of it. But there's still an issue with window content disappearing when I move it out of the left up corner

CleanShot.2022-12-25.at.19.29.45.mp4

@NogginBops
Copy link
Owner

That looks like an issue with scissor testing... something where the scissor area gets put too far out

@tingspain
Copy link

It is happening the same to me, any update on this issue?

Thanks!

@tingspain
Copy link

In my case, I just fixed it by modifying the scalefactor, line 36 at ImGuiController.cs . I just multiply it by 2.

Previous

...
private System.Numerics.Vector2 _scaleFactor = System.Numerics.Vector2.One;
...

After

...
private System.Numerics.Vector2 _scaleFactor = System.Numerics.Vector2.One * 2;
...

@NogginBops
Copy link
Owner

This seems to me like a DPS/Retina thing as the factor is 2.
I'm guessing something about how OpenTK/GLFW handles width and height on retina displays differs from how it is handled on other types of displays.

Maybe it's possible to get the scale factor from GLFW directly?

@tingspain
Copy link

@NogginBops, indeed. I just modified:

  1. The constructor of the ImGuiController to pass the Horizontal and Vertical scale factors
  2. The OnLoad() method of the Window class to get the right Scale Factor and pass it to the ImGuiController. I also passed to the constructor the 'ContextFlags.ForwardCompatible' to make it compatible with macOS

@ imGuiController.cs

.
.
. 

        /// <summary>
        /// Constructs a new ImGuiController.
        /// </summary>
        public ImGuiController(int width, int height, float scaleFactorX=1, float scaleFactorY=1 )
        {
            _windowWidth = width;
            _windowHeight = height;

            _scaleFactor.X *=  scaleFactorX;
            _scaleFactor.Y *=  scaleFactorY;

            .
            .
            .
         }

.
.
.

@ Window.cs

  .
  .
  .
    public class Window : GameWindow
    {
        ImGuiController _controller;

        public Window() : base(GameWindowSettings.Default, 
                               new NativeWindowSettings() { 
                                    Size = new Vector2i(1600, 900), 
                                    Flags = ContextFlags.ForwardCompatible 
                               })
        { }

        protected override void OnLoad()
        {
            base.OnLoad();

            Title += ": OpenGL Version: " + GL.GetString(StringName.Version);

            // Initialise the Scale Factor
            float scaleFactorX = 0;
            float scaleFactorY = 0;

            // Get the Scale Factor of the Monitor
            this.TryGetCurrentMonitorScale(out scaleFactorX, out scaleFactorY);

            // Instanciate the ImGuiController with the right Scale Factor
            _controller = new ImGuiController(ClientSize.X, ClientSize.Y, out_width, out_height);
        }
     .
     .
     .

    }

@DigitalBox98
Copy link

Patch is working fine on MacOS. I have adjusted ImGUIController in order to have a sample working on MacOS/Win10/Linux : https://github.com/DigitalBox98/Dear-ImGui-OpenTK-Sample

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants