SFML : get display resolution

This article is part of a tutorial dedicated to SFML. The reader may consult the other parts of the tutorial by following this link : SFML tutorial.

This example shows how to get available screen resolutions for full screen display:

/*!
 * \file    main.cpp
 * \brief   Display the list of available video mode (https://www.lucidarme.me/?p=6127)
 * \author  Philippe Lucidarme
 * \version 1.0
 * \date    12/18/2016
 */

// SFML libraries
#include 
#include 

int main()
{

    // Display the list of all the video modes available for fullscreen
    std::vector modes = sf::VideoMode::getFullscreenModes();

    // Display each mode
    for (std::size_t i = 0; i < modes.size(); ++i)
    {
        sf::VideoMode mode = modes[i];
        std::cout << "Mode #" << i << "\t"
                  << mode.width << "x" << mode.height << " \t "
                  << mode.bitsPerPixel << " bpp" << std::endl;
    }

    // Get and display desktop mode
    sf::VideoMode mode = sf::VideoMode::getDesktopMode();
    std::cout << "Desktop"  << "\t"
              << mode.width << "x" << mode.height << " \t "
              << mode.bitsPerPixel << " bpp" << std::endl;

    // End of application
    return 0;
}

Download from Git

Files and source codes can be downloaded for GitLab : https://gitlab.com/philippe.lucidarme/sfml_tutorial/tree/master/part_002

<- Back to SFML tutorial main menu

Leave a Reply

Your email address will not be published. Required fields are marked *