DEV Community

vigo walker
vigo walker

Posted on

how to use SFML in C++ (Basics)

So, the only reason why you would use SFML is because you are searching to challenge yourself, because these days there is Unity or Unreal Engine. Where you can get your games done in a really short period, since game engines like Unity have renderers, physics engine, animation engine, etc.
So with that being said, let’s get into the tutorial.

Creating our first game in SFML!

NOTE: In this tutorial we do not go by the installation, you can get more info here.

So, when we create a project in SFML. In order to get a window you will need to come code to start.

how to use SFML in C++ (Basics)

Above there’s some code that will create a basic window, the window should look like this:

SFML in C++

So, now. Let’s revise what this code does and how it works!

What does the code do

So, the first 4 lines of code are the necessary code to make hour coding more easy, I mean the first 2 are importing the necessary libraries, SFML is for the graphics and iostream is for coding in C++, basically.

Then in the main function, there is the sf::RenderWindow window(sf::VideoMode(1000, 1000), "Good Game"); code.
this renders the window with a resolution of 1000 * 1000 and puts a title of Good Game.

Then the rest of the code is for displaying the screen and detecting when the game needs to be closed! also the game will run at 60 fps or more depending on your hardware!

So if you like this post or want more content, you can support me using the following links!
website: theshadowtech
instagram: vigo_walker
youtube: theshadow 76

searching for graphics cards? We recommend these ones!

Top comments (0)