Should I use SFML for Games Development?


SFML stands for simple, fast media library and can be used for 2D games development. Rather than being specific for games development the library was created to cover several key aspects covering graphics, sound, networking, and input. SFML is available natively in C++ but is available in several languages due to the support from the community. SFML is open source and free under the zlib/png license. 

Key aspects of SFML

SFML has 5 key building blocks of system, audio, window, graphics and networking. Some are more self-descriptive than others. 


The system module covers low level aspects such as time, threads, and streams. This allows for multithreading which is running multiple processes asynchronously. Streams are mainly used for bringing in files in a streamed approach (unlike batching). 


The window module handles the interaction with OpenGL for painting pixels to the screen. It also covers input I.e. key presses and mouse movements. The window is the key element required for all other components and is the starting point when creating a new game 


The graphics module is pretty self-explanatory, it is used to handle images and shapes to the screen. You can draw 2D shapes directly to the window ns apply textures. SFML has built-in support for text and fonts so you can easily write text to the screen. As well as drawing images to the screen the graphics module also allows you to transform elements on the screen, for example rotation, scaling, and positioning. 

There is low level support for shader creation to cover times you want to work directly with the graphics card. This allows for special effects to be added plus any other customisations which can be made using shaders. 

Some basic camera controls are built-in using the concept of views. Views or sometimes known as view ports, allow you to draw to an area larger than the screen. With SFML you have control over what area you can see on the screen, you can move the view and update the view area when the window is resized. 


The audio module in SFML covers everything related to sound, whether it be background music or sound effects. In SFML the concept of sound and music are handled as two distinct entities. Music provides the ability to stream straight from the file and is used for your in-game background audio. Sounds are held in memory and should be used for timely small noises, for example a gun firing. The abilities of both are similar with the main difference between streaming and memory storage. 

As SFML is not just for games development and is a media library at heart then it also supports sound recording. Not one which is commonly used in games, but it is there if needed. 

3D sound is supported, this is when you make a noise from a specific location and depending on the listener you may or may not hear it and if you do the volume will be based on how far away you are. SFML handles this by setting a sound and listener location. For example, you may attach a sound moving along with a car with the engine running. You can then add a listener to your player. When your player gets nearer the car then the noise will get loud playing at a louder volume. As you move away and get far enough from the car the sound will stop. 


SFML supports low level networking for both TCP and UDP. This provides flexibility to create multiplayer games using the server client pattern. There is also support for HTTP and FTP but not something you would normally use in gaming. 

SFML Supported Languages 

The creators of SFML have created a .net nuget package which provides hooks into the underlying C++ code. This allows C# developers to benefit from SFML without the need to go to a low level. You will need the .net SDK to use the package. It is easy to start using the nuget package which has been constructed with the same modules as the C++ version. 

As SFML has been well used for a long time then there is a good community around its development. This means that SFML is accessible in a large [number of languages]. Some of the most popular are Python, Node,js, Ruby and Rust.  


What doesn’t SFML Suppy? 

Though SFML has plenty of features it does not cover everything a games engine would provide. So, using SFML is not for the faint hearted. Due to this most of the elements required for a game need to be built from the ground up. Examples are animations, collision, physics, tile maps, even the main game loop process.  

That said, there has been several addons created by the community for GUIs, animation, particle physics, lighting, video playback and tilemaps to name a few. 

SFML only has the capacity to support 2D graphics so isn’t useable for 3D games. 

As SFML is very low level then it is highly performant and customisable. You won’t be locked into a game engine and therefore aren’t required to work in any specific way. 

So, in summary SFML is a great media toolkit and will more than cover the basics which are required for 2D game development. You will need to be prepared to put in time and hard graft to create a game from the ground up. If you are looking to get up and running quickly then you may want to consider Godot, read our post with more information here.

Leave a Reply

Your email address will not be published. Required fields are marked *

WordPress Cookie Plugin by Real Cookie Banner