Forem

vigo walker
vigo walker

Posted on

1 1

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!

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read 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

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay