r/sfml • u/JungleGames77 • 3d ago
A 2D sandbox game built with C++17 and SFML 3
r/sfml • u/DarkCisum • Apr 16 '26
SFML 3.1 is finally out! š„³
While "only" a minor version, it brings major updates feature wise. The highlights are:
Complete revamped text rendering engine using the power of HarfBuzz, cpp-unicodelib and SheenBidi. SFML can finally render complex text layouts, bi-directional texts, provides more glyph-level information and allows for rendering customization.
The network module joins the 21st century by supporting TLS, HTTPS, IPv6, and SFTP! Additionally, a DNS client has been introduced.
Unicode support in various parts of the library has been improved.
Lots of improvements for Android and iOS.
See the changelog for more details.
See the migration guide on how to migrate from deprecated methods.
See the full list of contributors on GitHub.
r/sfml • u/DarkCisum • Sep 18 '25
A few bugfixes and some build configuration enhancements, including automated release builds.
Automatic release CI builds (#3538)
Documentation improvements (#3547, #3548)
GitHub Actions updates (#3517, #3536)
CMake adjustments (#3504, #3510, #3511)
Bugfixes
Add explicit cast for charN_t conversion for Clang 21 (#3571)
Bugfixes
[Android] Fix issue with Re-creation of Windows on Android (#3507)
Bugfixes
Assert positive size and in-bounds position for copy area (#3539, #3541)
[Android] Fixed normalized texture coordinates when NPOT textures aren't supported (#3460, #3461)
Bugfixes
Fixed audio engine attempting to read data from previously destroyed objects (#3503, #3522)
See the full list of contributors on GitHub
r/sfml • u/TheEyebal • 6d ago
I keep getting the error error: expected primary expression before 'mouse' and error: expected primary expression before 'rect'
Can someone assist me on this because I am lost
CONTEXT
I made a boolean function that detects if a point is colliding with a rectangle and in my main function when button is pressed and mouse is colliding with rectangle than the console needs to output string
bool pointRectCollision(Mouse mouse, RectangleShape rect){
if(mouse.getPosition().x > int(rect.getPosition().x) && mouse.getPosition.x() < int(rect.getPosition().x + rect.getSize().x) && mouse.getPosition().y > int(rect.getPosition().y) && mouse.getPosition.y() < int(rect.getPosition().y + rect.getSize().y)){
return true;
}
else {
return false;
}
}
int main(){
// GAME LOOP
if (mouse.isButtonPressed(Button::Left) && pointRectCollision(mouse, pauseBtn)){
cout << "COLLISION" << endl;
}
return 0;
}UPDATE
I was able to fix the problem. I had to fix the syntax of how I was declaring mouse and also nest my conditional statement for detecting collision.
// function to detect point-rectangle collision
bool pointRectCollision(Vector2i mousePos, RectangleShape &rect){
if(mousePos.x > int(rect.getPosition().x) && mousePos.x < int(rect.getPosition().x + rect.getSize().x) && mousePos.y > int(rect.getPosition().y) && mousePos.y < int(rect.getPosition().y + rect.getSize().y)){
return true;
}
else {
return false;
}
}
int main(){
// GAME LOOP
// MOUSE
if (Mouse::isButtonPressed(Mouse::Button::Left)){
if(pointRectCollision(Mouse::getPosition(window), pauseBtn)){
cout << "collision" << endl;
}
}
}r/sfml • u/Ok-Affect-691 • 14d ago
yeah my comments are kinda funny lmao also i've been fighting one segfault for five hours also
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <chrono>
#include <thread>
#include <cstdlib>
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
using namespace std::this_thread;
using namespace std::chrono;
string score = "0";
int position1;
int position2;
int rotation = 2;
int apples = 0;
int grid[32][24];
/* /\ this motherfucker messed up my code SO MUCH
* that now it fucking always segfaults,
* fuck you. */
int headx = 0;
int heady = 0;
int tail = 0;
int oldposx;
int oldposy;
int countx = 0;
int county = 0;
int main() {
start:
sf::Font font("ComicNeue-Bold.ttf");
sf::Text text(font);
text.setCharacterSize(24);
text.setFillColor(sf::Color::Red);
text.setPosition({10.f, 10.f});
//text.setString(score);
sf::Text text2(font);
text2.setCharacterSize(64);
text2.setFillColor(sf::Color::Red);
text2.setPosition({150.f, 150.f});
text2.setString("Game Over!");
sf::Text text3(font);
text3.setCharacterSize(24);
text3.setFillColor(sf::Color::Red);
text3.setPosition({200.f, 300.f});
text3.setString("r - restart, q - quit");
sf::RectangleShape head({20.f, 20.f});
head.setFillColor(sf::Color(100, 250, 50));
sf::RectangleShape tail({20.f, 20.f});
tail.setFillColor(sf::Color(100, 250, 50));
sf::RectangleShape bg({20.f, 20.f});
bg.setFillColor(sf::Color(0, 0, 0));
sf::RectangleShape food({20.f, 20.f});
food.setFillColor(sf::Color(255, 0, 0));
food.setPosition({60.f, 60.f});
sf::RenderWindow window(sf::VideoMode({640, 480}), "Snake in SFML!");
//cout << "First stuff done" << endl;
while (window.isOpen()){
/* dont delete this motherfucker, it works, it just works
* \/ */
stringstream ss;
ss << apples;
ss >> score;
while (const std::optional event = window.pollEvent()){
if (event->is<sf::Event::Closed>()){
window.close();
}
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::S)){
rotation = 2;
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::W)){
rotation = 0;
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::A)){
rotation = 3;
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::D)){
rotation = 1;
}
if (headx == 31 || headx == 0 || heady == 0 || heady == -23){
sleep_for(nanoseconds(100000000));
}
if (headx != 31 || headx != 0 || heady != 0 || heady != -23){
sleep_for(nanoseconds(50000000));
}
/* /\ dont fucking even try to fix janky controls, i dont want to suffer
* it fucking works, it works, it works */
//cout << "before oldposes" << endl;
/* these oldposses probably killing my code, i just cant prove it
* so im just gonna leave them here so they wont oload my mem or segfault */
oldposx = headx;
oldposy = heady - heady - heady;
/* positioning of these movements to oldposses is prob segfaulting it */
/* this layout is pretty bad but it should work and if wont i will
* suddenly combust, so i hope it works lol */
/* these are used for a lot of stuff, DONT FUCKING DELETE IT!!
* so bassicaly a very usefull thing and you prob have to rewrite
* half of this game cuz its so used lol */
sf::Vector2f positionfood = food.getPosition();
sf::Vector2f positionhead = head.getPosition();
if (rotation == 0){
if (heady + 1 == 1){
head.setPosition(sf::Vector2f(positionhead.x, 460));
heady = -23;
}
else {
heady += 1;
head.move({0.f, -20.f});
}
if (grid[headx][heady + 1] > 1){
goto over;
}
}
if (rotation == 2){
if (heady - 1 == -24){
head.setPosition(sf::Vector2f(positionhead.x, 0));
heady = 0;
}
else {
heady -= 1;
head.move({0.f, 20.f});
}
if (grid[headx][heady - 1] > 1){
goto over;
}
}
if (rotation == 1){
if (headx + 1 == 32){
head.setPosition(sf::Vector2f(0, positionhead.y));
headx = 0;
}
else {
headx += 1;
head.move({20.f, 0.f});
}
if (grid[headx + 1][heady] > 1){
goto over;
}
}
if (rotation == 3){
if (headx - 1 == -1){
head.setPosition(sf::Vector2f(620, positionhead.y));
headx = 31;
}
else {
headx -= 1;
head.move({-20.f, 0.f});
}
if (grid[headx - 1][heady] > 1){
goto over;
}
}
goto before;
over:
while (true){
/*
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::R)){
apples = 0;
grid[0][0] = 1;
goto start;
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Q)){
window.close();
}
*/
window.clear(sf::Color::Black);
window.draw(text2);
//window.draw(text3);
window.display();
/*
while (true) {
countx++;
if (countx == 32 || countx > 31){
countx = 0;
county++;
}
grid[countx][county] = 0;
if (countx == 31){
if(county == 23){
break;
}
}
}
*/
}
before:
//cout << "Getpositions" << endl;
/* this was breaking my code probably lol
if (headx == 32) {
head.setPosition(sf::Vector2f(0, positionhead.y));
headx = 0;
}
if (headx == -1 || headx < -1) {
head.setPosition(sf::Vector2f(620, positionhead.y));
headx = 31;
}
if (heady == 1 || heady > 1) {
head.setPosition(sf::Vector2f(positionhead.x, 460));
heady = -23;
}
if (heady == -24 || heady < -24) {
head.setPosition(sf::Vector2f(positionhead.x, 0));
heady = 0;
}
*/
//cout << "Apples" << endl;
if (positionfood == positionhead){
position1 = rand() % 31;
position2 = rand() % 23;
position1 = position1 * 20;
position2 = position2 * 20;
food.setPosition(sf::Vector2f(position1, position2));
apples += 1;
}
//cout << "Set the apples" << endl;
if (apples != 0){
cout << "X: " << oldposx << endl << "Y: " << oldposy << endl;
grid[oldposx][oldposy] = 2;
}
countx = 0;
county = 0;
while (apples != 0){
while(true){
/* so this adds one to everything thats bigger than 1
* and if that equals apples + 2 then it will put it to 0 */
if (grid[countx][county] > 1){
if (grid[countx][county] == apples + 2){
grid[countx][county] = 0;
}
}
/* if it + 1 != apples + 2 just add 1 */
if (grid[countx][county] > 1) {
if (grid[countx][county] != apples + 2){
grid[countx][county] += 1;
}
}
if (countx == 32){
countx = 0;
if (county + 1 != 24){
county++;
}
/* im using goto only cuz it will prob only break the fisrt loop so yeah
* it will just cause another infinite loop and segfault lol */
else {
goto endofapple;
}
}
/* if evetyrhing is clear add 1 to x and go back */
countx++;
}
}
endofapple:
/*
while (true) {
countx++;
if (countx == 32 || countx > 31){
countx = 0;
county++;
}
if (grid[countx][county] > 1){
tail.setPosition(sf::Vector2f(countx * 20, county * 20));
window.draw(tail);
}
if (countx == 31){
if(county == 23){
break;
}
}
}
*/
/* that code prob broke the code so i gave it the ultimate fate
* of being commented!
while (true) {
countx++;
if (countx == 32 || countx > 31) {
countx = 0;
county++;
}
if (grid[countx][county] > 1){
grid[countx][county] = grid[countx][county] - 1;
if (grid[countx][county] < 2){
grid[countx][county] = 0;
}
}
if (countx == 31){
if(county == 23){
break;
}
}
}
*/
//cout << "end of first loop" << endl;
countx = 0;
county = 0;
text.setString(score);
//cout << "x: " << headx << endl << "y: " << heady << endl;
window.clear(sf::Color::Black);
window.draw(text);
window.draw(head);
window.draw(food);
window.draw(text);
//cout << "start of new one" << endl;
while (true) {
countx++;
if (countx == 32 || countx > 31){
countx = 0;
county++;
}
if (grid[countx][county] > 1){
tail.setPosition(sf::Vector2f(countx * 20, county * 20));
window.draw(tail);
}
if (countx == 31){
if(county == 23){
break;
}
}
}
countx = 0;
county = 0;
/*
while (true) {
countx++;
if (countx == 32 || countx > 31){
countx = 0;
county++;
}
if (grid[countx][county] == 0){
bg.setPosition(sf::Vector2f(countx * 20, county * 20));
window.draw(bg);
}
if (countx == 31){
if(county == 23){
break;
}
}
}
*/
window.display();
//cout << "WHAT" << endl;
/*
countx = 0;
county = 0;
while(true) {
if (countx == 32){
countx = 0;
if (county + 1 != 24){
county++;
cout << endl;
}
else {
goto start;
}
}
cout << grid[countx][county];
countx++;
}
*/
}
}
I found a videotutorial I've made back in late 2022 on my old HDD.
r/sfml • u/NotStiveOrMike • 25d ago
A bit of background:
I started out with a simple term projectāgenerating a landscape where you could place tile-sized buildings. Later, I felt the urge to try something more ambitious. I considered a few options, like Unity or Godot, but ultimately, it turned out to be easier to build everything from scratch.
The video shows what Iāve been working on for the last month, building upon the foundation from that initial term project.
Iāve implemented an interface using TGUI (replacing my previous "hacky" solutions), a localization manager, and a tilemap system for textures.
The map generator has been overhauled, moving from a cellular automaton approach to using Perlin noise.
The game world is divided into counties, to group these into duchies, then kingdoms, and finally empires.
As for the state of the codeāwell, letās just say itās in dire need of a refactor.
And thatās where things stand.
excuse my "excellent" English
r/sfml • u/PitifulTheme411 • 26d ago
I'm using SFML for a project, and I want to create a maximized window. For what I am reading, this is not possible unless I manually write code for each platform (ie. windows, mac, linux) as SFML does not support this. Is there any way to circumvent this/mimic it? I don't want it to be fullscreen, and when I try using sf::VideoMode::getDesktopMode() then it leaves some space on the left and overextends on the right.
Is there really no way to do this in a cross platform way? I am not interested in writing platform-specific code, and would just likely move to a different library (even though I spent two days trying to get the library to link) if this is not possible. If you have any suggestions for that as well, I am all ears.
r/sfml • u/Loymdayddaud • Oct 09 '26
Explore a maze of stone, stone, pinches of gold dust, and... more stone. Find a key to escape, or spend your days wandering and dodging snakes. Templum Serpentis is a simple pixel art roguelike built around serpents and machetes - one of which is scattered randomly around the maze, and the other of which move in random directions attempting to find the player. Serpent pathfinding is basic: if they have line of sight to the player, they move in that direction; otherwise, they move in a random direction.
It's open source, so you can find the code here: https://github.com/TheGiraffe3/templum-serpentis . Criticism and comments welcome!
I couldn't have made this game without SFML. Thanks to the developers for creating such an awesome framework!
r/sfml • u/Pinwin12 • Oct 07 '26
Igor the Penguin is a small, chill platformer I originally released in December 2024. It now also has a level editor for creating your own levels.
Master Levels for Igor the Penguin is a standalone follow-up game made using the assets and engine from Igor the Penguin, featuring 10 new levels.
Igor the Penguin:
https://pinwinsoftware.com/Game/1/Igor_the_Penguin
Master Levels for Igor the Penguin:
https://pinwinsoftware.com/Game/9/Master_Levels_for_Igor_the_Penguin
ITP Editor:
r/sfml • u/Plus-Opposite-7088 • Sep 28 '26
I need to build a smfl project for the end of my first semester, more complex the project the better as it would be a very good learning oppurtunity.
r/sfml • u/batvour • Sep 25 '26

I am using SFML.Net and running its example. https://github.com/SFML/SFML.Net/blob/master/examples/window/Program.cs
When I resize the window, or maximize, or drag window to second display, it shows the same thing twice. Image posted is when window is maximized, the top left circle is where it should be, the lower one is flickering. However, the weird thing is, it doesn't ALWAYS show the same thing twice. From debugging I found the Wrong Circle only shows up every 3 frames, in other two frames the window is correct. This remains true when I limit frame rate or resize in different ways. However, sometimes if I maximize and undo maximize, the flickering of wrong circle goes away.
r/sfml • u/Alexx1610 • Sep 15 '26
Hi,
Iām a beginner in C++, and Iāve been exploring different C++ projects on GitHub. Iād really like to run some projects, test them and learn from them, but Iām having trouble setting up external libraries in VS Code ā especially SFML.
Iām not sure where SFML is supposed to be placed or how to configure it properly. Iāve seen tutorials where people modify project properties, but I canāt find anything similar in VS Code (maybe that only exists in Visual Studio Community?). I also tried adding the paths in tasks.json and c_cpp_properties.json, but I still couldnāt get it to work.
The strange part is that āGo to Definitionā works ā VS Code can open the SFML header files ā so it seems like IntelliSense knows where the files are. But compiler doesnāt find them when compiling, so I guess the compiler isnāt locating the SFML package correctly.
can i get some of your help?
Thanks in advance!

r/sfml • u/SpectralHorse • Sep 01 '26
[TLDR]: I released a free C++ library and free GUI application (Studio, SFML based) for procedurally generating animated pixel-art spaceships, with a wide range of configurable parameters!
Hello everyone!
Some of you (perhaps 5 or 10 of you :D) may have seen me post about a game I'm working on - Rogues in Space. While working on it, I, a kind of pretty bad pixel artist, started developing a procedural spaceship generator, the purpose of which was to just generate a very basic ship that I could manually "clean up" and animate.
Aaand well, I just kept adding generators for more and more things - hulls, engines, wings, weapons... In the end I even added animations and spritesheets!
At some point, when it was clear that this (now) library and GUI application were getting larger than the video game itself, it made more sense to cut it off as its own project instead of having it permanently embedded in the game codebase.
So, after doing all the new work that I've never originally intended, I've now released SpectralShipGen and SpectralShipGen Studio as open-source projects!
SpectralShipGen is the C++17 generation library itself, while SpectralShipGen Studio is a standalone GUI application (SFML based) for visually playing around with the generator and exporting ship images and animation spritesheets without needing to integrate the library into anything.
On the technical side, ships are generated deterministically from seeds, and how they look (and from which components/color palettes and what intensity), can be controlled through structural profiles, faction profiles, mentioned color palettes and plenty of other generation settings. Majority of the aspects of an existing ship (so engines, details, accessories, weapons, etc.) can be rerolled individually instead of regenerating everything, keeping the general construction of the ship mostly the same, except for the specific parts that you wish to change.
Saving and loading the recipes for said construction is also supported, as well as adding the ships to favorites/bookmarks, and browsing them later.
All ships are also generated with Idle animation and with (currently experimental) left/right/up/down movement and firing animations.
I've tried to keep the different visual identities fairly broad rather than making them into simple predefined ships. So, the same structural style or faction can still produce quite different results based on the seed and configuration.
The library itself is independent, while the Studio application does rely on SFML (and the library, of course) for the graphical rendering, button interactions, and everything else GUI related.
Interestingly, an unexpected amount of work towards this release ended up being in the boring-but-important category - regression/performance/robustness testing, establishing CI, writing (everyone's favorite) documentation, thinking about how licensing works, etc., so that these two can actually function as an independent library and a standalone application.
I've attached several examples of generated animations that I thought were interesting to show what the output can be, although they only cover just a tiny amount of what can be generated.
In case anyone likes what they're seeing and is wondering about using the generated output - anything you generate with it is yours to use however you want, including commercially. There's no attribution requirement and the source code licenses don't apply to the generated images or spritesheets.
Lastly, I'd also like to mention a couple of important topics.
I definitely don't see this ever replacing actual pixel artists - someone who's at least decent with pixel art can likely make a much better spaceship by hand. Something like this is, I think, much more useful if you're on a very tight art budget, if you need/want a bunch of ships generated during runtime (as you don't really need to save the generated spritesheet to disk in order to use it), if you're at a game jam and just need urgent assets.. Or if you just wanna generate a few hundred ships to see what odd things appear, because that can also be pretty entertaining (I may or may not have spent too much time doing just that).
Something that I also want to be fully transparent about, because I do think it will definitely be asked - the development/code writing on this project has been AI-assisted. However, that is the extent of it. There is no generative AI image creation anywhere in SpectralShipGen, reference images are NOT used, and there aren't any premade spritesheets or images "hidden" behind the library being chopped up and re-combined.
The ships are generated by the C++ code itself through procedural geometry, pixel masks, components (hull, engines, details, weapons, etc.) placing rules, seeded random decisions, and so on.
The nice thing about doing it with deterministic seeding way is that the same seed and the same configuration always give the same ship.
The amount of AI assistance during development was also one of the reasons I personally felt more comfortable making the project open source instead of keeping it completely proprietary. That's also not supposed to be some statement about how AI-assisted software should be licensed or what anyone else should do with their own work (that's a completely separate discussion) - it just felt like the right choice for me and this particular project.
As mentioned, the generated output is deliberately unrestricted as well - if you generate a ship image or spritesheet with SpectralShipGen (or Studio), you can do whatever you want with it. Use it in a commercial video game, redistribute it, paint over it, use it as a placeholder - attribution isn't required.
Links:
Library: https://github.com/SpectralHorse/SpectralShipGen
Studio: https://github.com/SpectralHorse/SpectralShipGen-Studio
Studio Download (from GitHub): https://github.com/SpectralHorse/SpectralShipGen-Studio/releases/tag/v1.0.0
I'd be very interested to hear about your thoughts - both about the generator itself and if the different ships actually feel like they have enough variety while still looking like they are thematically and systematically similar.
And, of course, if you end up generating something ridiculous with it - I'd love to see it! :)
r/sfml • u/Joe2001r • Aug 30 '26
I finished chapter 1-12, but I changed a lot from the author's source code
first, there were quite a lot of bugs in the author's source code.
The provided source code is not organized in well-defined libs, there was no mention of build config files anywhere in the book. I divided the project into 3 main libs (utils, core, ECS)
I used Conan to manage external library dependencies, and I used CMake to build my project.
It would be interesting if anyone of you would find it helpful, and please feel free to give your remarks regarding on how I could improve it.
Chapter 13 and 14 are remaining, I don't know if I'll continue.
Plus, you can play the game I coded using this engine that the book helped me code.
https://github.com/CrunchyPeanutButterJar/sfml-proj
Thanks for your time!
r/sfml • u/Ok-Hospital6348 • Aug 29 '26
title
r/sfml • u/Loymdayddaud • Aug 27 '26
I tend to assume that the latest version is better, but I've seen a few new projects recently that use SFML 2.6. And, since 2.6 was out for longer, more tutorials / Q&A exist for it than 3.0.
Is there a list of the tradeoffs between the versions that could explain why some people are using 2.6 still?
(and what's the benefit of 3.1 over 3.0? should 3.0 projects migrate to 3.1 just because they can?)
r/sfml • u/SpectralHorse • Aug 23 '26
Hello everyone!
I've been working on the combat for my C++/SFML space shooter game, `Rogues in Space`, and I wanted to share a showcase of some of the guns and skills currently in the game.
Each gun and skill have their own upgrade pools, so their behavior and stats can change quite a bit through the run. The video mostly shows their base versions, with short explanations of each mechanic included in the footage.
The game is built in C++17 with SFML 2.6.x. A good amount of what you're seeing here, including the gameplay rendering and visual effects, is running through my SFML-based rendering/post-processing setup.
I'd love to hear what you think about how the combat is looking so far, and I'm also happy to talk about the SFML/implementation side of anything shown in the video :)
And also, most importantly - do you feel like you could have fun with some of these combinations? :D
r/sfml • u/Consistent-Mouse-635 • Aug 20 '26
Hi all,
As the title suggests, I am looking for a way to keep the main program (so my update() and render() functions) running, whilst the window is being resized.
I have already tried multi-threading, keeping the event loop on the main thread, and having another loop calling the update() and render() functions on another thread. This requires me to use the win32 API to intercept the window's WM_SIZE message during resize, and update my own window size variable.
This approach sort of works, allowing my window size variable to correctly update whilst the user is resizing the window. However I don't have a good way to pass this to the sf::RenderWindow.
If I don't set anything, the sf::RenderWindow doesn't update its internal window size to the current window size. If I call sf::RenderWindow::setSize()+setView(), it updates the internal window size, but also results in graphical artifacts where the region SFML draws to the screen isn't in sync with the actual window size, and previous frames bleed into the current frame.
Does anyone have a better solution to this? Any help would be greatly appreciated.