Haighstrom's picture

[Solved]Screen Size not working correctly

When I create my window using the Gamewindow class, the window size isn't coming out the size I ask for.

If I make the simple program:

class Program
    static void Main(string[] args)
        using (var game = new GameWindow(200,200))

the screen area (excluding the window border) comes out at exactly 250 x 250. GameWindow's Width and Height variables confirm this (as does measuring a screenshot in Paint).

Using 500,500 gives size 625, 625.

It seems the screen dimensions are 25% bigger than the size I ask for... why is this?

I tried calling

game.Size = new Size(200,200);

directly before game.Run but this resizes the window (inclusive of of the window border) to that size, meaning the screen area comes out at only 182 x 153.



Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture

You probably have DPI scaling set at 125%.

If you need exact sizing in pixels, set:

 game.ClientSize = new Size(200, 200);

ClientSize sets the size of the client area (without borders) in pixels. Size sets the size of the window area (with borders) in native screen coordinates (points).

Haighstrom's picture

That solves it, thanks.

Still seems odd though! What sets DPI scaling, can I not change that?

the Fiddler's picture

DPI scaling is an OS setting. OpenTK has no control over it, but a user can change it using the display settings in the control panel.

In most cases, you should not hardcode windows to a specific pixel size. For example, a 500x500 pixel window will be unusably small on a modern 4K monitor. Instead, you should respect the OS settings and accept that a 500x500 point window may create a 1000x1000 pixel window on system with 200% DPI scaling (e.g. a retina MacBook).

If you must force a specific resolution for some reason, you have two options:
1. Render to a framebuffer object with the desired size. You can then scale to the window size using an interpolation filter of your choice (point, linear or a custom shader.)
2. Disable HiDPI support using:

static void Main()
    var options = new ToolkitOptions
        EnableHighResolution = false
    using (OpenTK.Init(options))
    using (var game = new GameWindow(500, 500))

Just to reiterate, you should not force a specific window size in pixels. Doing so will render your application unusable on an increasing number of systems with HiDPI monitors.