SFML provides a simple interface to the various components of your PC, to ease the development of games and multimedia applications. It is composed of five modules: system, window, graphics, audio and network.
Discover their features more in detail in the tutorials and the API documentation.
With SFML, your application can compile and run out of the box on the most common operating systems: Windows, Linux, Mac OS X and soon Android & iOS.
Pre-compiled SDKs for your favorite OS are available on the download page.
SFML has official bindings for the C and .Net languages. And thanks to its active community, it is also available in many other languages such as Java, Ruby, Python, Go, and more.
Learn more about them on the bindings page.
Version | Release Date |
---|---|
1.0 | 2007-07-01 |
1.1 | 2007-09-18 |
1.2 | 2008-07-16 |
1.3 | 2008-06-22 |
1.4 | 2009-01-07 |
1.5 | 2009-06-04 |
1.6 | 2010-04-06 |
2.0 | 2013-04-29 |
2.1 | 2013-07-27 |
2.2 | 2014-12-17 |
2.3 | 2015-05-09 |
2.3.1 | 2015-07-11 |
2.3.2 | 2015-10-12 |
2.4.0 | 2016-08-10 |
2.4.1 | 2016-11-04 |
2.4.2 | 2017-02-08 |
If everything whas been set up correctly, the following snippet will show a window titled "SFML works!" with a green circle:
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
sf::CircleShape shape(100.f);
shape.setFillColor(sf::Color::Green);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.draw(shape);
window.display();
}
return 0;
}
Let's write a small program which will open a window, and write "Hello World" on the screen.
#include <SFML\Graphics.hpp>
#include <cassert>
int main() {
sf::RenderWindow sfmlWin(sf::VideoMode(600, 360), "Hello World SFML Window");
sf::Font font;
//You need to pass the font file location
if (!font.loadFromFile(/*
Put the filename that identify the font file you want to load*/"myfont.ttf")) {
return -1;
}
sf::Text message("Hello, World !", font);
while (sfmlWin.isOpen()) {
sf::Event e;
while (sfmlWin.pollEvent(e)) {
switch (e.type) {
case sf::Event::EventType::Closed:
sfmlWin.close();
break;
}
}
sfmlWin.clear();
sfmlWin.draw(message);
sfmlWin.display();
}
return 0;
}
Let's explain what we did there.
First, we created a sf::Font
object. We need this object to store the font data that we will use to display the text. After that, we called the loadFromFile
method, used to load the font in the memory. We should note that SFML don't know about your system fonts, so you need to provide a filename, not a font name
After that, we created a sf::Text
object. We call a 3 parameter constructor taking :
Since the sf::Text
object is ready, we just need to draw it in the main sfml loop, by calling the draw method on the sfmlWin
render window object that we created before
First of all you need to download the SFML SDK. Then, in order to start developing SFML applications, you have to install the following items:
SFML is available either as dylibs or as frameworks. Only one type of binary is required although both can be installed simultaneously on the same system. We recommend using the frameworks.
SFML depends on a few external libraries on Mac OS X. Copy the content of extlibs to /Library/Frameworks.
If you use Xcode, installing the templates is strongly recommended. Copy the SFML directory from templates to /Library/Developer/Xcode/Templates (create the folders if they don't exist yet).
There are different approaches to the installation of SFML on Linux:
Option 1 is the preferred one; if the version of SFML that you want to install is available in the official repository, then install it using your package manager. For example, on Debian you would do:
sudo apt-get install libsfml-dev
Option 2 requires more work: you need to ensure all of SFML's dependencies including their development headers are available, make sure CMake is installed, and manually execute some commands. This will result in a package which is tailored to your system. If you want to go this way, there's a dedicated tutorial on building SFML yourself.
Finally, option 3 is a good choice for quick installation if SFML is not available as an official package. Download the SDK from the download page, unpack it and copy the files to your preferred location: either a separate path in your personal folder (like /home/me/sfml), or a standard path (like /usr/local).
If you already had an older version of SFML installed, make sure that it won't conflict with the new version!
The most common way to install SFML on windows is to download the official SDK
You can then unpack the archive and use it in your environment of choice.
Although it's still heavily in development, if you use Visual studio 2017 or newer, you can also install SFML via vcpkg which integrates with visual studio, greatly simplifying the installation process:
vcpkg install sfml