Up-to-date Go bindings for SFML, the Simple and Fast Multimedia Library.
Switch branches/tags
Nothing to show
Clone or download



Up-to-date Go bindings for SFML, the Simple and Fast Multimedia Library.

These bindings are entirely generated using SWIG and the official C bindings of SFML.
Hence they should be fairly easy to maintain & keep in sync with future releases from upstream.

Table of Contents


I have only tested these on darwin/amd64, using the latest macOS Sierra.
Feel free to open issues and/or PRs if you're running into problems on other platforms.



Assuming both libraries and their header files are correctly installed and available through the standard paths of your system:

$ go get -u gopkg.in/teh-cmc/go-sfml.v24/...

That's it!


The generated APIs very closely follow those of SFML's C bindings: the tutorials & documentation available for the official C++ implementation, as well as an editor with a well configured Go-autocompletion, will get you a long way.


The original C & C++ implementations of SFML come with 5 modules: Audio, Graphics, Network, System and Window.

Of these 5 modules:

  • Audio, Graphics & Window come with complete Go packages counterparts
  • System also has a dedicated Go package, but only contains the sfVector2 & sfVector3 classes; everything else is already available in one form or another in Go's standard library
  • Network has been entirely discard, use Go's standard library instead


Here's a straightforward example of creating a window and handling events:

package main

import (


func init() { runtime.LockOSThread() }

func main() {
	vm := window.NewSfVideoMode()
	defer window.DeleteSfVideoMode(vm)

	/* Create the main window */
	cs := window.NewSfContextSettings()
	defer window.DeleteSfContextSettings(cs)
	w := graphics.SfRenderWindow_create(vm, "SFML window", uint(window.SfResize|window.SfClose), cs)
	defer window.SfWindow_destroy(w)

	ev := window.NewSfEvent()
	defer window.DeleteSfEvent(ev)

	/* Start the game loop */
	for window.SfWindow_isOpen(w) > 0 {
		/* Process events */
		for window.SfWindow_pollEvent(w, ev) > 0 {
			/* Close window: exit */
			if ev.GetXtype() == window.SfEventType(window.SfEvtClosed) {
		graphics.SfRenderWindow_clear(w, graphics.GetSfRed())

For comparison's sake, the exact same thing in C:

#include <SFML/Window.h>
#include <SFML/Graphics.h>

int main() {
    sfVideoMode mode = {800, 600, 32};
    sfRenderWindow* window;
    sfEvent event;

    /* Create the main window */
    window = sfRenderWindow_create(mode, "SFML window", sfResize | sfClose, NULL);
    if (!window)
        return 1;

    /* Start the game loop */
    while (sfRenderWindow_isOpen(window)) {
        /* Process events */
        while (sfRenderWindow_pollEvent(window, &event)) {
            /* Close window : exit */
            if (event.type == sfEvtClosed)
        /* Clear the screen */
        sfRenderWindow_clear(window, sfRed);

    /* Cleanup resources */

License License

The Zlib/libpng - see LICENSE for more details.

Copyright (c) 2017 Clement 'cmc' Rey cr.rey.clement@gmail.com @teh_cmc