Skip to content

SFML:Window

This tutorial only explains how to open and manage a window. Drawing stuff is beyond the scope of the sfml-window module: it is handled by the sfml-graphics module. However, the window management remains exactly the same so reading this tutorial is important in any case.

Opening a window

Windows in SFML are defined by the sf::Window class. A window can be created and opened directly upon construction:

#include <SFML/Window.hpp>

int main()
{
    sf::Window window(sf::VideoMode(800, 600), "My window");

    ...

    return 0;
}

The first argument, the video mode, defines the size of the window (the inner size, without the title bar and borders). Here, we create a window with a size of 800x600 pixels. The sf::VideoMode class has some interesting static functions to get the desktop resolution, or the list of valid video modes for fullscreen mode. Don't hesitate to have a look at its documentation.

The second argument is simply the title of the window.

This constructor accepts a third optional argument: a style, which allows you to choose which decorations and features you want. You can use any combination of the following styles:

sf::Style::None

No decoration at all (useful for splash screens, for example); this style cannot be combined with others

sf::Style::Titlebar

The window has a titlebar

sf::Style::Resize

The window can be resized and has a maximize button

sf::Style::Close

The window has a close button

sf::Style::Fullscreen

The window is shown in fullscreen mode; this style cannot be combined with others, and requires a valid video mode

sf::Style::Default

The default style, which is a shortcut for Titlebar | Resize | Close

See also