SFML: first program

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.


Install the following packages :

sudo apt-get install qtcreator qt-sdk libsfml-dev

Configure Qt

To link your application with the SFML libraries, add the following lines in the .pro file :

LIBS += -lsfml-audio
LIBS += -lsfml-graphics
LIBS += -lsfml-network
LIBS += -lsfml-window
LIBS += -lsfml-system

To avoid problem with directories, uncheck “Shadow build” in the project:

In the same way, you can uncheck “Run in terminal” :

First program

 * \file    main.cpp
 * \brief   First example of SFML (https://www.lucidarme.me/?p=6127)
 * \author  Philippe Lucidarme (from official SFML tutorial)
 * \version 1.0
 * \date    12/18/2016

// SFML libraries

int main()
    // Create a new 200x200 pixels window with a title
    sf::RenderWindow window(sf::VideoMode(200, 200), "SFML tutorial : part 1");
    // Create a green circle with a radius of 100. pixels
    sf::CircleShape shape(100.f);
    // Main loop, while the window is open
    while (window.isOpen())
        // Event loop
        sf::Event event;
        while (window.pollEvent(event))
            // If close is requested by user, close the window
            if (event.type == sf::Event::Closed) window.close();
        // Display sequence : clear screen, draw circle and update display
    // End of application
    return 0;

This should display the following window:

Download from Git

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

<- Back to SFML tutorial main menu

Leave a Reply

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