Getting Started with SFML in Visual Studio for Windows

Riley Entertainment Game Dev
4 min readSep 30, 2021

--

SFML, the Simple and Fast Multimedia Library, is a cross-platform API written in C++ used to manage windows and provide access to 2D graphics, audio, and networking features. The full source is available on Github, and the library is distributed under the zlib/png licence. The website provides a number of tutorials, and a full reference section.

This post will be covering how to set up SFML for development in Visual Studio for Windows. If you’re savvy enough and looking to get straight into it, you can just reference the tutorial found on the website itself. If you get stuck along the way, check back here for some extra tips.

Before I jump into the guide on getting set up in Visual Studio, I thought I’d address why I’m choosing to focus on SFML in the short-term.

SFML’s Development Status

As of September of 2021, the most recent release of SFML was version 2.5.1, roughly three years ago. Scanning the Github repository, ongoing development appears a little spotty since that time. Activity in the forums suggest there may be a bit of “analysis paralysis” going on when it comes to future releases:

  • Much of the codebase has aged, so there is discussion on updating it to the C++17 or C++20 standard.
  • Support for mobile platforms has been on the agenda for a long time.
  • Vulkan will eventually replace OpenGL, so SFML will ultimately need to be updated to support it.

Hopefully the presence of the SFML 2.6.0 project board, with tons of “done” items and only a few “open” items, is an indication that SFML is alive and well.

Why I Like SFML

SFML is really just a utility library that can be used to bypass a lot of low-level coding. It offers convenient ways to do all the low-level tasks necessary for game development, in a cross-platform manner:

  • Create and manage a game window.
  • Receive user interface events from the keyboard, mouse, or other controllers.
  • Load image and sound files into memory.
  • Draw shapes and textured sprites.
  • Play sound effects and music.
  • Send and receive network traffic.

SFML makes no assumptions on how your game engine should operate. This is the flexibility and control I was looking for when I was choosing a library. For myself, I enjoy the challenge and find it rewarding to build my own game loop and engine.

For my current game called The Colon Case, I’m also looking to limit its scope to a simpler 2D game engine, as I take the time and effort to learn more about game loops, sprite sheets, and so forth.

There are plenty of game design platforms that have large parts of the game engine built for you, allowing you to focus more immediately on the content of your game. If that’s the case, this blog might only be of passing interest to you, at least for the short term. You might look at platforms like Godot, Construct, Unity, or Unreal.

Manual Setup of SFML in Visual Studio

The SFML and Visual Studio tutorial page on the SFML website already provides everything you’ll need to get started. However, these pages would have been written in 2018, for an older version of Visual Studio. Here are a few additional notes:

  • The site strongly cautions that you need to match the SFML version you download with your version of Visual Studio. The download links for Visual Studio C++ 15 (2017) work fine with Visual Studio C++ 2019 as well.
  • In your project’s properties, under C/C++ -> General, add SFML’s include folder to the Additional Include Directories.
  • Under Linker -> General, add SFML’s lib folder to the Additional Library Directories.
  • I recommend linking to the static libraries, to avoid having to include SFML’s DLL files as part of your release. Under C/C++ -> Preprocessor, add SFML_STATIC to the Preprocessor Definitions.
  • Under Linker -> Input, add the SFML libraries you need to the Additional Dependencies.
  • The SFML distribution provides different library files for debug vs. release, and static vs. dynamic. For each configuration, you’ll need to be careful about which .lib file you specify.
  • Pay special attention to the additional dependency matrix shown on the SFML and Visual Studio tutorial page. At a minimum, you’ll probably need to add opengl32.lib and winmm.lib.

Example Visual Studio Project

I’ve provided an example SFML project over on Github. It has all the necessary project settings for debug and release, as well as 32-bit and 64-bit configurations. You’d only need to change the include and library directories to match where you installed SFML.

If you’re wondering whether there’s a less manual way of getting going with SFML, keep watching this blog! In my next post, I’ll be introducing the CMake build system. Soon after I’ll be discussing how to use CMake’s FetchContent module for SFML as an alternative to all this manual setup.

--

--