james_lohr's picture

GameWindow - fullscreen + setting the resolution

At present, if I create a new GameWindow, with a resolution of say 800x600, and then set the WindowState to fullscreen, instead of changing my monitor resolution to 800x600 (as I would expect), it just overrwrites the resolution with my current desktop resolution.

So, how do I change my monitor resolution? I've spent a good 25 minutes googling, and I found:

OpenTK.Graphics.DisplayDevice and OpenTK.Graphics.DisplayResolution help enumerate available displays and resolutions (yes, the code is multi-monitor aware ;) ), and provide methods to change the settings of any display.

...but the I can't for the life of me find these elusive methods. Are they perhaps private? - if so, how do I get at them?


Comments

Comment viewing options

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

At present, if I create a new GameWindow, with a resolution of say 800x600, and then set the WindowState to fullscreen, instead of changing my monitor resolution to 800x600 (as I would expect), it just overrwrites the resolution with my current desktop resolution.
This was discussed in the forums. I'm not sure what is the current state of this part of the API. If I might, I certainly wouldn't expect GameWindow to change the screen resolution :)

the Fiddler's picture

OpenTK.Graphics.DisplayDevice.ChangeResolution() and OpenTK.Graphics.DisplayDevice.RestoreResolution() are the methods you are looking for.

Edit: I made a mistake in my orginal post, it's DisplayDevice, not DisplayResolution. Sorry!

james_lohr's picture

Woah woah woah, there seriously needs to be some documentation up on how to use this part of the library because it's very confusing if you're used to how the majority of games libs do it (i.e. they only support a single monitor).

This is how I expected it to work - (for anyone referring to this thread, this is wrong) :

//get an array of all the resolutions that my monitor supports 
OpenTK.Graphics.DisplayDevice[] resolutions = OpenTK.Graphics.DisplayDevice.AvailableDisplays;
 
//I expected this to be a static method, but it's not so this won't even compile
OpenTK.Graphics.DisplayDevice.ChangeResolution(...)

For anyone referring to this thread, this is how it actually works:

// returns an array of displays, one per monitor - on a single monitor computer, this will just be of length 1
OpenTK.Graphics.DisplayDevice[] displays = OpenTK.Graphics.DisplayDevice.AvailableDisplays;
 
//get a list of available resolutions for the first monitor
resolutions = displays[0].AvailableResolutions;
 
//change the resolution to one that is supported   
displays[0].ChangeResolution(resolutions[x]);
 
//or set it manually
displays[0].ChangeResolution(800,600,32,60);

In hindsight it's extremely simple, and works exactly as it should. The problem was that I wasn't expecting the support for multiple monitors, and that was where the confusion arose from. - also, no amount of googling showed up any snippet of code (like the one above) for simply setting the resolution on a single monitor.

Perhaps it was just me being slow, or the fact that I recall using a previous games library where "availableDisplayModes" was used to mean the available resolutions (which is rather similar to "availableDisplays"). Anyway, at least this thread now exists, so noone else will have the same problem as myself.

Probably half the problem is that C# comes with such good development tools that people don't even bother documenting stuff because they just assume that other programmers will have enough common sense to explore the available methods themselves throught the IDE. :P

the Fiddler's picture

As part of the ongoing documentation effort, I've added a new chapter describing the DisplayDevice class.

If you are using OpenTK 0.9.9+, you can optionally pass a DisplayDevice to the GameWindow constructor. This will ensure the GameWindow is instantiated on that specific device (OpenTK 0.9.8 and older would always instantiate GameWindows on the primary display).

Finally, you can query the actual bounds of the device using the Bounds property. This can be useful in some obscure cases, where you might like to know the actual position of each device relative to the rest.

james_lohr's picture

Excellent! :)

objarni's picture

Great work in supporting multiple display devices - as james said - it is quite unique among the graphics libraries out there. Eg. I'm not sure even the widely used SimpleDirectmedia Library (SDL) supports this.