OpenTK.DisplayDevice.SelectResolution C# (CSharp) Method

SelectResolution() public method

Selects an available resolution that matches the specified parameters.

If a matching resolution is not found, this function will retry ignoring the specified refresh rate, bits per pixel and resolution, in this order. If a matching resolution still doesn't exist, this function will return the current resolution.

A parameter set to 0 or negative numbers will not be used in the search (e.g. if refreshRate is 0, any refresh rate will be considered valid).

This function allocates memory.

public SelectResolution ( int width, int height, int bitsPerPixel, float refreshRate ) : DisplayResolution
width int The width of the requested resolution in pixels.
height int The height of the requested resolution in pixels.
bitsPerPixel int The bits per pixel of the requested resolution.
refreshRate float The refresh rate of the requested resolution in hertz.
return DisplayResolution
        public DisplayResolution SelectResolution(int width, int height, int bitsPerPixel, float refreshRate)
        {
            DisplayResolution resolution = FindResolution(width, height, bitsPerPixel, refreshRate);
            if (resolution == null)
                resolution = FindResolution(width, height, bitsPerPixel, 0);
            if (resolution == null)
                resolution = FindResolution(width, height, 0, 0);
            if (resolution == null)
                return current_resolution;
            return resolution;
        }

Usage Example

Esempio n. 1
0
        /// <summary>
        /// Creates a new DisplayResolution object for the specified DisplayDevice.
        /// </summary>
        /// <param name="width">The requested width in pixels.</param>
        /// <param name="height">The requested height in pixels.</param>
        /// <param name="bitsPerPixel">The requested bits per pixel in bits.</param>
        /// <param name="refreshRate">The requested refresh rate in hertz.</param>
        /// <remarks>OpenTK will select the closest match between all available resolutions on the specified DisplayDevice.</remarks>
        ///
        public DisplayResolution(int width, int height, int bitsPerPixel, float refreshRate, DisplayDevice device)
        {
            // Refresh rate may be zero, since this information may not be available on some platforms.
            if (width <= 0)
            {
                throw new ArgumentOutOfRangeException("width", "Must be greater than zero.");
            }
            if (height <= 0)
            {
                throw new ArgumentOutOfRangeException("height", "Must be greater than zero.");
            }
            if (bitsPerPixel <= 0)
            {
                throw new ArgumentOutOfRangeException("bitsPerPixel", "Must be greater than zero.");
            }
            if (refreshRate < 0)
            {
                throw new ArgumentOutOfRangeException("refreshRate", "Must be greater than, or equal to zero.");
            }
            if (device == null)
            {
                throw new ArgumentNullException("DisplayDevice", "Must be a valid DisplayDevice");
            }

            DisplayResolution res = device.SelectResolution(width, height, bitsPerPixel, refreshRate);

            this.width          = res.width;
            this.height         = res.height;
            this.bits_per_pixel = res.bits_per_pixel;
            this.refresh_rate   = res.refresh_rate;
        }
All Usage Examples Of OpenTK.DisplayDevice::SelectResolution