DEV Community

dwarfŧ
dwarfŧ

Posted on • Edited on

creating a window in SFML

step 1
first of all you need to install SFML. I am using ubuntu and i found the linux installation guide here.

step 2
next, you need to create a window you can do this by doing:

#include <SFML/Graphics.hpp>

int main()
{
    // create the window
    sf::RenderWindow window(sf::VideoMode(800, 600), "Hello window!");

    // run the program as long as the window is open
    while (window.isOpen())
    {
        // check all the window's events that were triggered since the last iteration of the loop
        sf::Event event;
        while (window.pollEvent(event))
        {
            // "close requested" event: we close the window
            if (event.type == sf::Event::Closed)
                window.close();
        }

        // clear the window with black color
        window.clear(sf::Color::Black);

        // draw everything here...
        // window.draw(...);

        // end the current frame
        window.display();
    }

    return 0;
}
Enter fullscreen mode Exit fullscreen mode

this will give us a black window named hello window!

step 3
to compile we cannot just do g++ main.cpp. We have to include some library's we can compile this by doing:

g++ main.cpp -o main -lsfml-graphics -lsfml-window -lsfml-system
Enter fullscreen mode Exit fullscreen mode

step 4
you can run it by doing: ./main

step 6
enjoy and have a good day

Image of Datadog

The Future of AI, LLMs, and Observability on Google Cloud

Datadog sat down with Google’s Director of AI to discuss the current and future states of AI, ML, and LLMs on Google Cloud. Discover 7 key insights for technical leaders, covering everything from upskilling teams to observability best practices

Learn More

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more