You know that feeling when things that used to work just fine break down for no obvious reason? Early last autumn I had to finally upgrade my operating system, because it was too far behind the curve. Unfortunately I couldn't also upgrade the hardware. And while most things work anyway, for better or worse, some have strange issues that make them unusable.

That happens to include SDL and anything built on it.

Yep, imagine that. A game developer's system, unable to run well the single most ubiquitous piece of infrastructure in all of game development. And never mind that it means not being able to play anything made in Ren'Py (bummer). How about anything that uses Pygame or sdlBasic — in other words, a lot of my own games.

I already use too many different programming libraries and such to make games. But until the situation is resolved, I need something that works on my potato of a machine. As it happens, something was at my fingertips all along, waiting for me to take a look already.

That something is the Simple and Fast Multimedia Library, a.k.a. SFML, and as usual I've known about it for a while before several people reminding me of it around the same time finally pushed me to give it a try.

At first it seems like SFML has quite a few dependencies, but those are all libraries that seem to come preinstalled on Linux desktops, and on second thought Pygame has many large dependencies of its own. I'm just used to having it around. Also SFML itself is tiny: like three megabytes for the library proper, development files and the bindings for Python 2/3. More about them later.

It may be due to SFML being written in C++, and in a thoughtful way at that. Sticking to the old '98 standard, too. The tutorials are crystal-clear, and cover all the important topics. Example code also works out of the box even though I have the slightly older 2.4 version. Changing the code in simple ways works smoothly as well. To wit:


#include <SFML/Graphics.hpp>

int main() {
	sf::RenderWindow window(sf::VideoMode(320, 200), "Hello, SFML!");
	//window.setVerticalSyncEnabled(true);
	window.setFramerateLimit(60);
	
	sf::CircleShape shape(10.f);
	shape.setFillColor(sf::Color::Green);

	sf::Clock clock;
	float fps = 60;
	
	while (window.isOpen()) {
		sf::Time elapsed = clock.restart();
		sf::Event event;
		
		while (window.pollEvent(event)) {
			if (event.type == sf::Event::Closed)
				window.close();
		}

		fps += 1 / elapsed.asSeconds();
		fps /= 2; // Average new and previous values.

		window.clear();
		for (float i = 0; i < fps; i += 10) {
			shape.setPosition(i * 3 + 10, 10);
			window.draw(shape);
		}
		window.display();
	}

	return 0;
}

Yup, the main loop looks very familiar, which is a plus. Drawing is a bit odd, because it uses OpenGL. At least you get a usable range of shapes, comlete with thick countours if you need that; much better than what Pyglet gives you.

Oops, did I just compare SFML to a Python-specific library again? Can't help it, that's my language of choice. And SFML does have bindings to it, along with several others. Problem is, the PySFML site is blank, and on GitHub there's no documentation, only a few examples that... don't work in the version shipped with Ubuntu Bionic Beaver, which seems incomplete. With a bit of patience however it's not hard to figure out how to translate things:


from __future__ import division

from sfml import sf

window = sf.RenderWindow(sf.VideoMode(320, 200), "Hello, SFML!")
# window.vertical_synchronization = True
window.framerate_limit = 60

shape = sf.CircleShape(10.0)
shape.fill_color = sf.Color.GREEN

clock = sf.Clock()
fps = 60

while window.is_open:
	elapsed = clock.restart()
	
	for event in window.events:
		if isinstance(event, sf.CloseEvent):
			window.close()
	
	fps += 1 / elapsed.seconds;
	fps /= 2; # Average new and previous values.
	
	window.clear()
	for i in range(0, int(fps), 10):
		shape.position = (i * 3 + 10, 10)
		window.draw(shape)
	window.display()

Which works, all right, but I'd rather not rely on it too much in this state. Should be enough for prototyping at least.

Anyway, that's as far as I got in one day. It remains to be seen how the text and sound systems work. (Sprites are probably fine.) And otherwise SFML is surprisingly cooperative, allowing for easy integration with common GUI toolkits, not to mention pretty much anything else that renders on OpenGL. The community is also present in many places, from a good old forum to Discord, and maintains extra documentation complementing the official one.

The only obstacle right now is, I already have plans for this spring and don't need another distraction. But I'm bound to need a break sooner or later.