Simple and Fast Multimedia Library
lastmod 2019-04-08created 2014-04-1327 edits
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.
Overview
SFML (Simple and Fast Multimedia Library) is a multimedia API made by the French company Laurent Gomila. It was created with the aim of replacing the existing cross-platform multimedia API Simple DirectMedia Layer (SDL). It was initially based on C++, but as new versions were released it came to support various languages such as C# and JAVA, and even Python and Ruby. As befits a multimedia library, it supports libraries for graphics, sound, input/output, networking, and more.
Details
SFML's strengths are that it is fast, easy to use, and object-oriented. Whereas SDL was built on the C language without object-oriented considerations, SFML is an API designed from the start with object-oriented development in mind, so it is easy to support from other modern object-oriented languages (C#, JAVA) as well. Its interface is also intuitive, and if you are familiar with object orientation, there is little difficulty in using the library. In other words, it is convenient and easy. It is even easier than SDL, which is reputed to be an easy graphics API. In terms of ease of use alone, it rivals winbgi, developed by Borland in the past. And it covers not only graphics but also sound, input/output, and network libraries. On top of that, it is fast.
However, it also has quite a few drawbacks. First of all, it is minor. SDL has been around for quite a while, so it has been used a lot and is also widely used in commercial programs.1 By contrast, SFML's version 1.6, which is regarded as reasonably usable, came out in 2010. The difference in track record shows up as differences in the size of the related community, related development books, references, source code, and so on, which makes development difficult. For example, more than 10 books on SDL have been published, whereas the first development book for SFML, SFML Game Development, was published on June 24, 2013.
SFML's future is still uncertain, but it is expected that in the long run it could threaten SDL's position. Above all, being an object-oriented library is a huge merit for development, so that alone is reason enough to use SFML.
Dependencies
libogg, flac, freetype, libvorbis
Ducumentation
Getting started
- SFML and Linux
- Compiling SFML with CMake
How to install in Ubuntu
System module
- Handling time
- Threads
- User data streams
Window module
- Opening and managing an SFML window
- Events explained
- Keyboard, mouse and joysticks
- Using OpenGL in a SFML window
Graphics module
- Drawing 2D stuff
- Sprites and textures
- Text and fonts
- Shapes
- Designing your own entities with vertex arrays
- Position, rotation, scale: transforming entities
- Adding special effects with shaders
- Controlling the 2D camera with views
Audio module
- Playing sounds and music
- Recording audio
- Custom audio streams
- Spatialization: Sounds in 3D
Network module
- Communication using sockets
- Using and extending packets
- Web requests with HTTP
- File transfers with FTP
Simple example
#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/Graphics/CircleShape.hpp>
#include <SFML/System/Clock.hpp>
#include <SFML/Window/Event.hpp>
int runDefaultSfml()
{
sf::RenderWindow window(sf::VideoMode(200, 200), LIBWORLD_MAIN_TITLE);
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;
}
Troubleshooting
Font rendering bug
When reading a font with sf::Font::loadFromMemory(), not all of the font data can be preloaded, so the buffer the data points to must remain valid until the sf::Font object loads a new font or is destroyed.
Project
- Sources · SFML/SFML Wiki · GitHub
- Projects · SFML/SFML Wiki · GitHub
- imgui-sfml (imgui)
- SFGUI
- sefMovie
- Thor
- ObEngine
- Github - SelbaWard - A collection of SFML drawables
- Github - Swoosh - SFML Activity and Segue Mini Library
- Tiled Map Editor (tiled)
See also
Favorite site
- SFML website
- Wikipedia (en) explanation of SFML
- Namuwiki - SFML
- [Recommended] SFML Projects
- Using OpenGL in a SFML window
- HowTo: SFML on Android
SFML on Android(NDK)
SFML on wxWidgets
- Integrating to a wxWidgets interface (SFML 1.6)
References
-
Notable examples include the Linux versions of Civilization: Call to Power and SimCity 3000, Second Life, Open TTD, and others. ↩