opentk / LearnOpenTK

A port of learnopengl.com's tutorials to OpenTK and C#.
Creative Commons Attribution 4.0 International
458 stars 115 forks source link

Resizing window on MacOS doesn't take care of the scale factor*2 #88

Closed DigitalBox98 closed 6 months ago

DigitalBox98 commented 8 months ago

When resizing on MacOS, the rendered objects are divided by 2.

macos

The solution consists to use scale factor :

    // Initialise the Scale Factor
    float scaleFactorX = 1.0f;
    float scaleFactorY = 1.0f;

And to identify it correctly on MacOS (2.0f on my Mac) during the OnLoad():

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

Then the OnResize() needs to use it :

        GL.Viewport(0, 0, (int)(Size.X * scaleFactorX), (int)(Size.Y * scaleFactorY));

With this method, the window once resized is displaying correctly the object :

macos-fix
NogginBops commented 7 months ago

The proper solution here I think is to use the FramebufferSize property and OnFramebufferResize properties that are new in 4.8.2