The DisplayDevice class

There are three main types of display devices: monitors, projectors and TV screens. OpenTK exposes all of them through the same interface: OpenTK.DisplayDevice.

You can use OpenTK.DisplayDevice to query available display devices, discover and modify their properties.

Example 1: discover available devices

using OpenTK;
 
foreach (DisplayDevice device in DisplayDevice.AvailableDisplays)
{
    Console.WriteLine(device.IsPrimary);
    Console.WriteLine(device.Bounds);
    Console.WriteLine(device.RefreshRate);
    Console.WriteLine(device.BitsPerPixel);
    foreach(DisplayResolution res in device.AvailableResolutions)
   {
      Console.WriteLine(res);
   }
}

Example 2: set the resolution of the first device to 800x600x32@60Hz:

using OpenTK;
 
devices[0].ChangeResolution(800, 600,  32,60);

Example 3: set the resolution of the second device to 800x600x32 using the preferred refresh rate:

using OpenTK;
 
devices[1].ChangeResolution(800, 600, 32, -1);

Example 4: restore all devices to their default settings

using OpenTK;
 
foreach (DisplayDevice device in DisplayDevice.AvailableDevices)
{
    device.RestoreResolution();
}

OpenTK will try to match your custom resolution to the closest supported resolution. If a specific bit depth or refresh rate is not supported, the current bit depth or refresh rate will be used. If no custom resolution matches the specified parameters, the current DisplayResolution will be used. You can specify a negative number or zero to indicate that a specific parameter is of no interest: for example, specifying a refresh rate of 0 will result in the default refresh rate being used.

Note that it is your responsibility to call RestoreResolution() prior to exiting your application. Failing to call this method will result in undefined behavior.

[Todo: add information about hotplugging support]


Comments

Comment viewing options

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

I think the greater than should be an equality in Example 1.

the Fiddler's picture

Good catch, fixed.

shiwenren's picture

Help!
In Example 4 , when I build , emerge a error. " the 'OpenTK.DisplayDevice' doesn't contain the definition of 'AvailableDevices'
Does the Eample wrong? Or How can I do for it ?