Beispiel #1
0
            new Dictionary <DisplayDevice, string>();    // Needed for ChangeDisplaySettingsEx
        #region --- Constructors ---

        /// <summary>Queries available display devices and display resolutions.</summary>
        static WinDisplayDeviceDriver()
        {
            lock (display_lock)
            {
                // To minimize the need to add static methods to OpenTK.Graphics.DisplayDevice
                // we only allow settings to be set through its constructor.
                // Thus, we save all necessary parameters in temporary variables
                // and construct the device when every needed detail is available.
                // The main DisplayDevice constructor adds the newly constructed device
                // to the list of available devices.
                DisplayDevice            opentk_dev;
                DisplayResolution        opentk_dev_current_res   = null;
                List <DisplayResolution> opentk_dev_available_res = new List <DisplayResolution>();
                bool opentk_dev_primary = false;
                int  device_count = 0, mode_count = 0;
                // Get available video adapters and enumerate all monitors
                WindowsDisplayDevice dev1 = new WindowsDisplayDevice(), dev2 = new WindowsDisplayDevice();
                while (Functions.EnumDisplayDevices(null, device_count++, dev1, 0))
                {
                    if ((dev1.StateFlags & DisplayDeviceStateFlags.AttachedToDesktop) == DisplayDeviceStateFlags.None)
                    {
                        continue;
                    }
                    DeviceMode monitor_mode = new DeviceMode();
                    // The second function should only be executed when the first one fails
                    // (e.g. when the monitor is disabled)
                    if (Functions.EnumDisplaySettingsEx(dev1.DeviceName.ToString(), DisplayModeSettingsEnum.CurrentSettings, monitor_mode, 0) ||
                        Functions.EnumDisplaySettingsEx(dev1.DeviceName.ToString(), DisplayModeSettingsEnum.RegistrySettings, monitor_mode, 0))
                    {
                        opentk_dev_current_res = new DisplayResolution(
                            monitor_mode.Position.X, monitor_mode.Position.Y,
                            monitor_mode.PelsWidth, monitor_mode.PelsHeight,
                            monitor_mode.BitsPerPel, monitor_mode.DisplayFrequency);
                        opentk_dev_primary =
                            (dev1.StateFlags & DisplayDeviceStateFlags.PrimaryDevice) != DisplayDeviceStateFlags.None;
                    }

                    opentk_dev_available_res.Clear();
                    mode_count = 0;
                    while (Functions.EnumDisplaySettings(dev1.DeviceName.ToString(), mode_count++, monitor_mode))
                    {
                        DisplayResolution res = new DisplayResolution(
                            monitor_mode.Position.X, monitor_mode.Position.Y,
                            monitor_mode.PelsWidth, monitor_mode.PelsHeight,
                            monitor_mode.BitsPerPel, monitor_mode.DisplayFrequency);
                        opentk_dev_available_res.Add(res);
                    }

                    // Construct the OpenTK DisplayDevice through the accumulated parameters.
                    // The constructor will automatically add the DisplayDevice to the list
                    // of available devices.
                    opentk_dev = new DisplayDevice(
                        opentk_dev_current_res,
                        opentk_dev_primary,
                        opentk_dev_available_res,
                        opentk_dev_current_res.Bounds);
                    available_device_names.Add(opentk_dev, dev1.DeviceName);
                }
            }
        }
            new Dictionary<DisplayDevice, string>();    // Needed for ChangeDisplaySettingsEx
        #region --- Constructors ---

        /// <summary>Queries available display devices and display resolutions.</summary>
        static WinDisplayDeviceDriver()
        {
            lock (display_lock)
            {
                // To minimize the need to add static methods to OpenTK.Graphics.DisplayDevice
                // we only allow settings to be set through its constructor.
                // Thus, we save all necessary parameters in temporary variables
                // and construct the device when every needed detail is available.
                // The main DisplayDevice constructor adds the newly constructed device
                // to the list of available devices.
                DisplayDevice opentk_dev;
                DisplayResolution opentk_dev_current_res = null;
                List<DisplayResolution> opentk_dev_available_res = new List<DisplayResolution>();
                bool opentk_dev_primary = false;
                int device_count = 0, mode_count = 0;
                // Get available video adapters and enumerate all monitors
                WindowsDisplayDevice dev1 = new WindowsDisplayDevice(), dev2 = new WindowsDisplayDevice();
                while (Functions.EnumDisplayDevices(null, device_count++, dev1, 0))
                {
                    if ((dev1.StateFlags & DisplayDeviceStateFlags.AttachedToDesktop) == DisplayDeviceStateFlags.None)
                        continue;
                    DeviceMode monitor_mode = new DeviceMode();
                    // The second function should only be executed when the first one fails
                    // (e.g. when the monitor is disabled)
                    if (Functions.EnumDisplaySettingsEx(dev1.DeviceName.ToString(), DisplayModeSettingsEnum.CurrentSettings, monitor_mode, 0) ||
                        Functions.EnumDisplaySettingsEx(dev1.DeviceName.ToString(), DisplayModeSettingsEnum.RegistrySettings, monitor_mode, 0))
                    {
                        opentk_dev_current_res = new DisplayResolution(
                            monitor_mode.Position.X, monitor_mode.Position.Y,
                            monitor_mode.PelsWidth, monitor_mode.PelsHeight,
                            monitor_mode.BitsPerPel, monitor_mode.DisplayFrequency);
                        opentk_dev_primary =
                            (dev1.StateFlags & DisplayDeviceStateFlags.PrimaryDevice) != DisplayDeviceStateFlags.None;
                    }

                    opentk_dev_available_res.Clear();
                    mode_count = 0;
                    while (Functions.EnumDisplaySettings(dev1.DeviceName.ToString(), mode_count++, monitor_mode))
                    {
                        DisplayResolution res = new DisplayResolution(
                            monitor_mode.Position.X, monitor_mode.Position.Y,
                            monitor_mode.PelsWidth, monitor_mode.PelsHeight,
                            monitor_mode.BitsPerPel, monitor_mode.DisplayFrequency);
                        opentk_dev_available_res.Add(res);
                    }

                    // Construct the OpenTK DisplayDevice through the accumulated parameters.
                    // The constructor will automatically add the DisplayDevice to the list
                    // of available devices.
                    opentk_dev = new DisplayDevice(
                        opentk_dev_current_res,
                        opentk_dev_primary,
                        opentk_dev_available_res,
                        opentk_dev_current_res.Bounds);
                    available_device_names.Add(opentk_dev, dev1.DeviceName);
                }
            }
        }
Beispiel #3
0
 static void VerifyMode(WindowsDisplayDevice device, DeviceMode mode)
 {
     if (mode.BitsPerPel == 0)
     {
         Debug.Print(
             "[Warning] DisplayDevice '{0}' reported a mode with 0 bpp. Please create a bug report at http://www.opentk.com",
             device.DeviceName.ToString());
         mode.BitsPerPel = 32;
     }
 }
Beispiel #4
0
 private static void VerifyMode(WindowsDisplayDevice device, DeviceMode mode)
 {
     if (mode.BitsPerPel == 0)
     {
         Debug.Print(
             "[Warning] DisplayDevice '{0}' reported a mode with 0 bpp. Please create a bug report at https://github.com/opentk/opentk/issues",
             device.DeviceName);
         mode.BitsPerPel = 32;
     }
 }
Beispiel #5
0
            new Dictionary <DisplayDevice, string>();            // Needed for ChangeDisplaySettingsEx

        /// <summary>Queries available display devices and display resolutions.</summary>
        static WinDisplayDeviceDriver()
        {
            // To minimize the need to add static methods to OpenTK.Graphics.DisplayDevice
            // we only allow settings to be set through its constructor.
            // Thus, we save all necessary parameters in temporary variables
            // and construct the device when every needed detail is available.
            // The main DisplayDevice constructor adds the newly constructed device
            // to the list of available devices.
            DisplayResolution        currentRes   = null;
            List <DisplayResolution> availableRes = new List <DisplayResolution>();
            bool devPrimary = false;
            int  deviceNum  = 0;

            // Get available video adapters and enumerate all monitors
            WindowsDisplayDevice winDev = new WindowsDisplayDevice();

            while (API.EnumDisplayDevices(null, deviceNum++, winDev, 0))
            {
                if ((winDev.StateFlags & DisplayDeviceStateFlags.AttachedToDesktop) == 0)
                {
                    continue;
                }

                DeviceMode monitor_mode = new DeviceMode();

                // The second function should only be executed when the first one fails (e.g. when the monitor is disabled)
                if (API.EnumDisplaySettings(winDev.DeviceName, (int)DisplayModeSettings.Current, monitor_mode) ||
                    API.EnumDisplaySettings(winDev.DeviceName, (int)DisplayModeSettings.Registry, monitor_mode))
                {
                    currentRes = new DisplayResolution(
                        monitor_mode.Position.X, monitor_mode.Position.Y,
                        monitor_mode.PelsWidth, monitor_mode.PelsHeight,
                        monitor_mode.BitsPerPel, monitor_mode.DisplayFrequency);
                    devPrimary = (winDev.StateFlags & DisplayDeviceStateFlags.PrimaryDevice) != 0;
                }

                availableRes.Clear();
                int i = 0;
                while (API.EnumDisplaySettings(winDev.DeviceName, i++, monitor_mode))
                {
                    availableRes.Add(new DisplayResolution(
                                         monitor_mode.Position.X, monitor_mode.Position.Y,
                                         monitor_mode.PelsWidth, monitor_mode.PelsHeight,
                                         monitor_mode.BitsPerPel, monitor_mode.DisplayFrequency));
                }

                // Construct the OpenTK DisplayDevice through the accumulated parameters.
                // The constructor automatically adds the DisplayDevice to the list of available devices.
                DisplayDevice device = new DisplayDevice(currentRes, devPrimary, availableRes, currentRes.Bounds);
                available_device_names.Add(device, winDev.DeviceName);
            }
        }
 public void RefreshDisplayDevices()
 {
     lock (this.display_lock)
     {
         this.AvailableDevices.Clear();
         DisplayResolution        local_1 = (DisplayResolution)null;
         List <DisplayResolution> local_2 = new List <DisplayResolution>();
         bool local_3 = false;
         int  local_4 = 0;
         WindowsDisplayDevice local_6 = new WindowsDisplayDevice();
         WindowsDisplayDevice temp_10 = new WindowsDisplayDevice();
         while (Functions.EnumDisplayDevices((string)null, local_4++, local_6, 0))
         {
             if ((local_6.StateFlags & DisplayDeviceStateFlags.AttachedToDesktop) != DisplayDeviceStateFlags.None)
             {
                 DeviceMode local_7 = new DeviceMode();
                 if (Functions.EnumDisplaySettingsEx(((object)local_6.DeviceName).ToString(), DisplayModeSettingsEnum.CurrentSettings, local_7, 0) || Functions.EnumDisplaySettingsEx(((object)local_6.DeviceName).ToString(), DisplayModeSettingsEnum.RegistrySettings, local_7, 0))
                 {
                     local_1 = new DisplayResolution(local_7.Position.X, local_7.Position.Y, local_7.PelsWidth, local_7.PelsHeight, local_7.BitsPerPel, (float)local_7.DisplayFrequency);
                     local_3 = (local_6.StateFlags & DisplayDeviceStateFlags.PrimaryDevice) != DisplayDeviceStateFlags.None;
                 }
                 local_2.Clear();
                 int local_5_1 = 0;
                 while (Functions.EnumDisplaySettings(((object)local_6.DeviceName).ToString(), local_5_1++, local_7))
                 {
                     DisplayResolution local_8 = new DisplayResolution(local_7.Position.X, local_7.Position.Y, local_7.PelsWidth, local_7.PelsHeight, local_7.BitsPerPel, (float)local_7.DisplayFrequency);
                     local_2.Add(local_8);
                 }
                 DisplayDevice local_0 = new DisplayDevice(local_1, local_3, (IEnumerable <DisplayResolution>)local_2, local_1.Bounds, (object)local_6.DeviceName);
                 this.AvailableDevices.Add(local_0);
                 if (local_3)
                 {
                     this.Primary = local_0;
                 }
             }
         }
     }
 }
Beispiel #7
0
 public void RefreshDisplayDevices()
 {
     lock (this.display_lock)
       {
     this.AvailableDevices.Clear();
     DisplayResolution local_1 = (DisplayResolution) null;
     List<DisplayResolution> local_2 = new List<DisplayResolution>();
     bool local_3 = false;
     int local_4 = 0;
     WindowsDisplayDevice local_6 = new WindowsDisplayDevice();
     WindowsDisplayDevice temp_10 = new WindowsDisplayDevice();
     while (Functions.EnumDisplayDevices((string) null, local_4++, local_6, 0))
     {
       if ((local_6.StateFlags & DisplayDeviceStateFlags.AttachedToDesktop) != DisplayDeviceStateFlags.None)
       {
     DeviceMode local_7 = new DeviceMode();
     if (Functions.EnumDisplaySettingsEx(((object) local_6.DeviceName).ToString(), DisplayModeSettingsEnum.CurrentSettings, local_7, 0) || Functions.EnumDisplaySettingsEx(((object) local_6.DeviceName).ToString(), DisplayModeSettingsEnum.RegistrySettings, local_7, 0))
     {
       local_1 = new DisplayResolution(local_7.Position.X, local_7.Position.Y, local_7.PelsWidth, local_7.PelsHeight, local_7.BitsPerPel, (float) local_7.DisplayFrequency);
       local_3 = (local_6.StateFlags & DisplayDeviceStateFlags.PrimaryDevice) != DisplayDeviceStateFlags.None;
     }
     local_2.Clear();
     int local_5_1 = 0;
     while (Functions.EnumDisplaySettings(((object) local_6.DeviceName).ToString(), local_5_1++, local_7))
     {
       DisplayResolution local_8 = new DisplayResolution(local_7.Position.X, local_7.Position.Y, local_7.PelsWidth, local_7.PelsHeight, local_7.BitsPerPel, (float) local_7.DisplayFrequency);
       local_2.Add(local_8);
     }
     DisplayDevice local_0 = new DisplayDevice(local_1, local_3, (IEnumerable<DisplayResolution>) local_2, local_1.Bounds, (object) local_6.DeviceName);
     this.AvailableDevices.Add(local_0);
     if (local_3)
       this.Primary = local_0;
       }
     }
       }
 }
Beispiel #8
0
 public static extern bool EnumDisplayDevices([MarshalAs(UnmanagedType.LPTStr)] string lpDevice,
                                              int iDevNum, [In, Out] WindowsDisplayDevice lpDisplayDevice, uint dwFlags);
        public void RefreshDisplayDevices()
        {
            lock (display_lock)
            {
                // Store an array of the current available DisplayDevice objects.
                // This is needed to preserve the original resolution.
                DisplayDevice[] previousDevices = AvailableDevices.ToArray();

                AvailableDevices.Clear();

                // We save all necessary parameters in temporary variables
                // and construct the device when every needed detail is available.
                // The main DisplayDevice constructor adds the newly constructed device
                // to the list of available devices.
                DisplayDevice opentk_dev;
                DisplayResolution opentk_dev_current_res = null;
                List<DisplayResolution> opentk_dev_available_res = new List<DisplayResolution>();
                bool opentk_dev_primary = false;
                int device_count = 0, mode_count = 0;

                // Get available video adapters and enumerate all monitors
                WindowsDisplayDevice dev1 = new WindowsDisplayDevice();
                while (Functions.EnumDisplayDevices(null, device_count++, dev1, 0))
                {
                    if ((dev1.StateFlags & DisplayDeviceStateFlags.AttachedToDesktop) == DisplayDeviceStateFlags.None)
                        continue;

                    DeviceMode monitor_mode = new DeviceMode();

                    // The second function should only be executed when the first one fails
                    // (e.g. when the monitor is disabled)
                    if (Functions.EnumDisplaySettingsEx(dev1.DeviceName.ToString(), DisplayModeSettingsEnum.CurrentSettings, monitor_mode, 0) ||
                        Functions.EnumDisplaySettingsEx(dev1.DeviceName.ToString(), DisplayModeSettingsEnum.RegistrySettings, monitor_mode, 0))
                    {
                        VerifyMode(dev1, monitor_mode);

                        float scale = GetScale(ref monitor_mode);
                        opentk_dev_current_res = new DisplayResolution(
                            (int)(monitor_mode.Position.X / scale), (int)(monitor_mode.Position.Y / scale),
                            (int)(monitor_mode.PelsWidth / scale), (int)(monitor_mode.PelsHeight / scale),
                            monitor_mode.BitsPerPel, monitor_mode.DisplayFrequency);

                        opentk_dev_primary =
                            (dev1.StateFlags & DisplayDeviceStateFlags.PrimaryDevice) != DisplayDeviceStateFlags.None;
                    }

                    opentk_dev_available_res.Clear();
                    mode_count = 0;
                    while (Functions.EnumDisplaySettingsEx(dev1.DeviceName.ToString(), mode_count++, monitor_mode, 0))
                    {
                        VerifyMode(dev1, monitor_mode);

                        float scale = GetScale(ref monitor_mode);
                        DisplayResolution res = new DisplayResolution(
                            (int)(monitor_mode.Position.X / scale), (int)(monitor_mode.Position.Y / scale),
                            (int)(monitor_mode.PelsWidth / scale), (int)(monitor_mode.PelsHeight / scale),
                            monitor_mode.BitsPerPel, monitor_mode.DisplayFrequency);

                        opentk_dev_available_res.Add(res);
                    }

                    // Construct the OpenTK DisplayDevice through the accumulated parameters.
                    // The constructor will automatically add the DisplayDevice to the list
                    // of available devices.
                    #pragma warning disable 612,618
                    opentk_dev = new DisplayDevice(
                        opentk_dev_current_res,
                        opentk_dev_primary,
                        opentk_dev_available_res,
                        opentk_dev_current_res.Bounds,
                        dev1.DeviceName);
                    #pragma warning restore 612,618

                    // Set the original resolution if the DisplayDevice was previously available.
                    foreach (DisplayDevice existingDevice in previousDevices)
                        if ((string)existingDevice.Id == (string)opentk_dev.Id)
                            opentk_dev.OriginalResolution = existingDevice.OriginalResolution;

                    AvailableDevices.Add(opentk_dev);

                    if (opentk_dev_primary)
                        Primary = opentk_dev;

                    Debug.Print("DisplayDevice {0} ({1}) supports {2} resolutions.",
                        device_count, opentk_dev.IsPrimary ? "primary" : "secondary", opentk_dev.AvailableResolutions.Count);
                }
            }
        }
 static void VerifyMode(WindowsDisplayDevice device, DeviceMode mode)
 {
     if (mode.BitsPerPel == 0)
     {
         Debug.Print(
             "[Warning] DisplayDevice '{0}' reported a mode with 0 bpp. Please create a bug report at http://www.opentk.com",
             device.DeviceName.ToString());
         mode.BitsPerPel = 32;
     }
 }
Beispiel #11
0
        public void RefreshDisplayDevices()
        {
            lock (display_lock)
            {
                // Store an array of the current available DisplayDevice objects.
                // This is needed to preserve the original resolution.
                DisplayDevice[] previousDevices = AvailableDevices.ToArray();

                AvailableDevices.Clear();

                // We save all necessary parameters in temporary variables
                // and construct the device when every needed detail is available.
                // The main DisplayDevice constructor adds the newly constructed device
                // to the list of available devices.
                DisplayDevice            opentk_dev;
                DisplayResolution        opentk_dev_current_res   = null;
                List <DisplayResolution> opentk_dev_available_res = new List <DisplayResolution>();
                bool opentk_dev_primary = false;
                int  device_count = 0, mode_count = 0;

                // Get available video adapters and enumerate all monitors
                WindowsDisplayDevice dev1 = new WindowsDisplayDevice();
                while (Functions.EnumDisplayDevices(null, device_count++, dev1, 0))
                {
                    if ((dev1.StateFlags & DisplayDeviceStateFlags.AttachedToDesktop) == DisplayDeviceStateFlags.None)
                    {
                        continue;
                    }

                    DeviceMode monitor_mode = new DeviceMode();

                    // The second function should only be executed when the first one fails
                    // (e.g. when the monitor is disabled)
                    if (Functions.EnumDisplaySettingsEx(dev1.DeviceName.ToString(), DisplayModeSettingsEnum.CurrentSettings, monitor_mode, 0) ||
                        Functions.EnumDisplaySettingsEx(dev1.DeviceName.ToString(), DisplayModeSettingsEnum.RegistrySettings, monitor_mode, 0))
                    {
                        VerifyMode(dev1, monitor_mode);

                        float scale = GetScale(ref monitor_mode);
                        opentk_dev_current_res = new DisplayResolution(
                            (int)(monitor_mode.Position.X / scale), (int)(monitor_mode.Position.Y / scale),
                            (int)(monitor_mode.PelsWidth / scale), (int)(monitor_mode.PelsHeight / scale),
                            monitor_mode.BitsPerPel, monitor_mode.DisplayFrequency);

                        opentk_dev_primary =
                            (dev1.StateFlags & DisplayDeviceStateFlags.PrimaryDevice) != DisplayDeviceStateFlags.None;
                    }

                    opentk_dev_available_res.Clear();
                    mode_count = 0;
                    while (Functions.EnumDisplaySettingsEx(dev1.DeviceName.ToString(), mode_count++, monitor_mode, 0))
                    {
                        VerifyMode(dev1, monitor_mode);

                        float             scale = GetScale(ref monitor_mode);
                        DisplayResolution res   = new DisplayResolution(
                            (int)(monitor_mode.Position.X / scale), (int)(monitor_mode.Position.Y / scale),
                            (int)(monitor_mode.PelsWidth / scale), (int)(monitor_mode.PelsHeight / scale),
                            monitor_mode.BitsPerPel, monitor_mode.DisplayFrequency);

                        opentk_dev_available_res.Add(res);
                    }

                    // Construct the OpenTK DisplayDevice through the accumulated parameters.
                    // The constructor will automatically add the DisplayDevice to the list
                    // of available devices.
                    #pragma warning disable 612,618
                    opentk_dev = new DisplayDevice(
                        opentk_dev_current_res,
                        opentk_dev_primary,
                        opentk_dev_available_res,
                        opentk_dev_current_res.Bounds,
                        dev1.DeviceName);
                    #pragma warning restore 612,618

                    // Set the original resolution if the DisplayDevice was previously available.
                    foreach (DisplayDevice existingDevice in previousDevices)
                    {
                        if ((string)existingDevice.Id == (string)opentk_dev.Id)
                        {
                            opentk_dev.OriginalResolution = existingDevice.OriginalResolution;
                        }
                    }

                    AvailableDevices.Add(opentk_dev);

                    if (opentk_dev_primary)
                    {
                        Primary = opentk_dev;
                    }

                    Debug.Print("DisplayDevice {0} ({1}) supports {2} resolutions.",
                                device_count, opentk_dev.IsPrimary ? "primary" : "secondary", opentk_dev.AvailableResolutions.Count);
                }
            }
        }
Beispiel #12
0
 public static extern BOOL EnumDisplayDevices([MarshalAs(UnmanagedType.LPTStr)] LPCTSTR lpDevice,
                                              DWORD iDevNum, [In, Out] WindowsDisplayDevice lpDisplayDevice, DWORD dwFlags);
Beispiel #13
0
        public void RefreshDisplayDevices()
        {
            lock (display_lock)
            {
                AvailableDevices.Clear();

                // We save all necessary parameters in temporary variables
                // and construct the device when every needed detail is available.
                // The main DisplayDevice constructor adds the newly constructed device
                // to the list of available devices.
                DisplayDevice opentk_dev;
                DisplayResolution opentk_dev_current_res = null;
                List<DisplayResolution> opentk_dev_available_res = new List<DisplayResolution>();
                bool opentk_dev_primary = false;
                int device_count = 0, mode_count = 0;

                // Get available video adapters and enumerate all monitors
                WindowsDisplayDevice dev1 = new WindowsDisplayDevice(), dev2 = new WindowsDisplayDevice();
                while (Functions.EnumDisplayDevices(null, device_count++, dev1, 0))
                {
                    if ((dev1.StateFlags & DisplayDeviceStateFlags.AttachedToDesktop) == DisplayDeviceStateFlags.None)
                        continue;

                    DeviceMode monitor_mode = new DeviceMode();

                    // The second function should only be executed when the first one fails
                    // (e.g. when the monitor is disabled)
                    if (Functions.EnumDisplaySettingsEx(dev1.DeviceName.ToString(), DisplayModeSettingsEnum.CurrentSettings, monitor_mode, 0) ||
                        Functions.EnumDisplaySettingsEx(dev1.DeviceName.ToString(), DisplayModeSettingsEnum.RegistrySettings, monitor_mode, 0))
                    {
                        VerifyMode(dev1, monitor_mode);

                        opentk_dev_current_res = new DisplayResolution(
                            monitor_mode.Position.X, monitor_mode.Position.Y,
                            monitor_mode.PelsWidth, monitor_mode.PelsHeight,
                            monitor_mode.BitsPerPel, monitor_mode.DisplayFrequency);
                        opentk_dev_primary =
                            (dev1.StateFlags & DisplayDeviceStateFlags.PrimaryDevice) != DisplayDeviceStateFlags.None;
                    }

                    opentk_dev_available_res.Clear();
                    mode_count = 0;
                    while (Functions.EnumDisplaySettingsEx(dev1.DeviceName.ToString(), mode_count++, monitor_mode, 0))
                    {
                        VerifyMode(dev1, monitor_mode);

                        DisplayResolution res = new DisplayResolution(
                            monitor_mode.Position.X, monitor_mode.Position.Y,
                            monitor_mode.PelsWidth, monitor_mode.PelsHeight,
                            monitor_mode.BitsPerPel, monitor_mode.DisplayFrequency);

                        opentk_dev_available_res.Add(res);
                    }

                    // Construct the OpenTK DisplayDevice through the accumulated parameters.
                    // The constructor will automatically add the DisplayDevice to the list
                    // of available devices.
                    opentk_dev = new DisplayDevice(
                        opentk_dev_current_res,
                        opentk_dev_primary,
                        opentk_dev_available_res,
                        opentk_dev_current_res.Bounds,
                        dev1.DeviceName);

                    AvailableDevices.Add(opentk_dev);

                    if (opentk_dev_primary)
                        Primary = opentk_dev;

                    Debug.Print("DisplayDevice {0} ({1}) supports {2} resolutions.",
                        device_count, opentk_dev.IsPrimary ? "primary" : "secondary", opentk_dev.AvailableResolutions.Count);
                }
            }
        }