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

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay