Skip to content

struct SF::VideoMode
inherits Struct #

VideoMode defines a video mode (width, height, bpp)

A video mode is defined by a width and a height (in pixels) and a depth (in bits per pixel). Video modes are used to setup windows (SF::Window) at creation time.

The main usage of video modes is for fullscreen mode: indeed you must use one of the valid video modes allowed by the OS (which are defined by what the monitor and the graphics card support), otherwise your window creation will just fail.

SF::VideoMode provides a static function for retrieving the list of all the video modes supported by the system: fullscreen_modes().

A custom video mode can also be checked directly for fullscreen compatibility with its valid?() function.

Additionally, SF::VideoMode provides a static function to get the mode currently used by the desktop: desktop_mode(). This allows to build windows with the same size or pixel depth as the current resolution.

Usage example:

# Display the list of all the video modes available for fullscreen
SF::VideoMode.fullscreen_modes.each do |mode|
  puts "Mode ##{i}: #{mode.width}x#{mode.height} - #{mode.bits_per_pixel} bpp"
end

# Create a window with the same pixel depth as the desktop
desktop = SF::VideoMode.desktop_mode
window.create(SF::VideoMode.new(1024, 768, desktop.bits_per_pixel), "SFML window")

Constructors#

.desktop_mode : VideoMode#

Get the current desktop video mode

Returns: Current desktop video mode

View source

.new(width : Int, height : Int, bits_per_pixel : Int = 32)#

Construct the video mode with its attributes

  • width - Width in pixels
  • height - Height in pixels
  • bits_per_pixel - Pixel depths in bits per pixel
View source

.new#

Default constructor

This constructors initializes all members to 0.

View source

Class methods#

.fullscreen_modes : Array(VideoMode)#

Retrieve all the video modes supported in fullscreen mode

When creating a fullscreen window, the video mode is restricted to be compatible with what the graphics driver and monitor support. This function returns the complete list of all video modes that can be used in fullscreen mode. The returned array is sorted from best to worst, so that the first element will always give the best mode (higher width, height and bits-per-pixel).

Returns: Array containing all the supported fullscreen modes

View source

Methods#

#!=(right : VideoMode) : Bool#

Overload of != operator to compare two video modes

  • left - Left operand (a video mode)
  • right - Right operand (a video mode)

Returns: True if modes are different

View source

#<(right : VideoMode) : Bool#

Overload of < operator to compare video modes

  • left - Left operand (a video mode)
  • right - Right operand (a video mode)

Returns: True if left is lesser than right

View source

#<=(right : VideoMode) : Bool#

Overload of <= operator to compare video modes

  • left - Left operand (a video mode)
  • right - Right operand (a video mode)

Returns: True if left is lesser or equal than right

View source

#==(right : VideoMode) : Bool#

Overload of == operator to compare two video modes

  • left - Left operand (a video mode)
  • right - Right operand (a video mode)

Returns: True if modes are equal

View source

#>(right : VideoMode) : Bool#

Overload of > operator to compare video modes

  • left - Left operand (a video mode)
  • right - Right operand (a video mode)

Returns: True if left is greater than right

View source

#>=(right : VideoMode) : Bool#

Overload of >= operator to compare video modes

  • left - Left operand (a video mode)
  • right - Right operand (a video mode)

Returns: True if left is greater or equal than right

View source

#bits_per_pixel : UInt32#

Video mode pixel depth, in bits per pixels

View source

#bits_per_pixel=(bits_per_pixel : Int)#

View source

#dup : VideoMode#

Returns a shallow copy of this object.

Because Value is a value type, this method returns self, which already involves a shallow copy of this object because value types are passed by value.

View source

#height : UInt32#

Video mode height, in pixels

View source

#height=(height : Int)#

View source

#valid? : Bool#

Tell whether or not the video mode is valid

The validity of video modes is only relevant when using fullscreen windows; otherwise any video mode can be used with no restriction.

Returns: True if the video mode is valid for fullscreen mode

View source

#width : UInt32#

Video mode width, in pixels

View source

#width=(width : Int)#

View source