UltravioletFramework / ultraviolet

The Ultraviolet Framework is a .NET game development framework written in C#.
https://github.com/UltravioletFramework/ultraviolet/wiki
MIT License
542 stars 46 forks source link

Set screen size/resolution? #85

Closed SirKnightTG closed 6 years ago

SirKnightTG commented 6 years ago

I've looked through the wiki, docs, headers, and samples and I can't seem to find a way to set the application's resolution. How do we do this as well as setting full-screen/windowed, re-sizable window or not, etc...?

With XNA/MonoGame it was: graphics = new GraphicsDeviceManager(this); graphics.IsFullScreen = false; graphics.PreferredBackBufferHeight = 340; graphics.PreferredBackBufferWidth = 480;

Surely there's an equivalent in UV.

tlgkccampbell commented 6 years ago

Ultraviolet works a bit differently than XNA here, because Ultraviolet has built-in support for multiple windows. Resolution settings are exposed on the IUltravioletWindow interface.

The first window which your application creates is called the "primary window" -- for the majority of applications, this will be the only window that exists. You can get to it through the platform subsystem:

var win = uvcontext.GetPlatform().Windows.GetPrimary();

Once you have that, you can modify its resolution:

// for fullscreen
win.SetFullscreenDisplayMode(width, height, 32, 60)
win.SetWindowMode(WindowMode.Fullscreen); // or FullscreenWindowed

// for windowed
win.SetWindowedClientSize(width, height);
win.SetWindowMode(WindowMode.Windowed);

The window will remember both resolutions independently and automatically switch between them when you call SetWindowMode().

I will make a note to add documentation on this.

tlgkccampbell commented 6 years ago

I should note also that the reference documentation for IUltravioletWindow is available here. It can provide guidance on how to modify your game window in other ways.

SirKnightTG commented 6 years ago

Cool. That helps a lot, thanks.