Awesome Go

raylib-go

CategoryGame Development
SubcategoryGame Development
Stars2,580

Go bindings for [raylib](https://www.raylib.com/), a simple and easy-to-use library to learn videogames programming

About raylib-go

logo

raylib-go

Build Status Go Reference Examples

Golang bindings for raylib, a simple and easy-to-use library to enjoy videogames programming.

raylib C source code is included and compiled together with bindings. Note that the first build can take a few minutes.

It is also possible to use raylib-go without cgo (see below).

Requirements

cgo

Ubuntu
apt-get install libegl1-mesa-dev libgbm-dev libdrm-dev libxi-dev libxrandr-dev libxext-dev libwayland-dev libxkbcommon-dev
Fedora
dnf install mesa-libEGL-devel mesa-libgbm-devel libdrm-devel libXi-devel libXrandr-devel libXext-devel wayland-devel libxkbcommon-devel
macOS

On macOS, you need Xcode or Command Line Tools for Xcode (if you have brew installed, you already have this).

Windows

On Windows you need C compiler, like Mingw-w64 or TDM-GCC. You can also build binary in MSYS2 shell.

To remove console window, build with -ldflags "-H=windowsgui".

Android

Android example.

iOS

iOS example.

Wasm

Wasm example.

purego (without cgo)

You can use raylib-go on Linux, macOS, Windows and FreeBSD without the need of cgo, i.e. with CGO_ENABLED=0, or with the nocgo build tag when cgo is enabled. 32-bit is not supported.

The shared libraries of raylib are embedded for Linux, macOS and Windows on amd64 and arm64. With the build tag extlib nothing is embedded and the system raylib library is loaded instead.

On FreeBSD nothing is embedded, the system raylib library is loaded; build with -gcflags="github.com/ebitengine/purego/internal/fakecgo=-std".

Installation

go get github.com/gen2brain/raylib-go/raylib

Build tags

Platforms (cgo, default is the native platform: Win32 on Windows, Cocoa on macOS, X11 on BSD, and on Linux Wayland, X11 and DRM selected at runtime):

TagDescription
glfwGLFW backend (PLATFORM_DESKTOP_GLFW)
drmLinux native DRM mode only, including Raspberry Pi and other devices (PLATFORM_DRM)
sdlSDL backend (PLATFORM_DESKTOP_SDL)
sdl3SDL3 backend (PLATFORM_DESKTOP_SDL3)
rgfwRGFW backend (PLATFORM_DESKTOP_RGFW)
waylandNative Wayland backend only, Linux only (PLATFORM_DESKTOP_WAYLAND)
x11Native X11 backend only, Linux and BSD (PLATFORM_DESKTOP_X11)
memoryHeadless, renders to memory (PLATFORM_MEMORY)
termuxTermux on Android (X11)

On Linux the default platform (PLATFORM_DESKTOP_LINUX) uses Wayland if WAYLAND_DISPLAY is set, X11 if DISPLAY is set, and DRM otherwise; the environment variable RAYLIB_PLATFORM (wayland, x11 or drm) selects one.

Graphics API (cgo, default is OpenGL 3.3 on desktop, OpenGL ES 2.0 on Linux arm64):

TagDescription
opengl43OpenGL 4.3
opengl33OpenGL 3.3
opengl21OpenGL 2.1
opengl11OpenGL 1.1 (pseudo OpenGL 1.1 style)
es2OpenGL ES 2.0 (can be used to link against Google's ANGLE)
es3OpenGL ES 3.0 (experimental)
softwareSoftware renderer (rlsw)

Options:

TagDescription
glfw_x11GLFW with X11 only (implies glfw)
glfw_waylandGLFW with Wayland only (implies glfw)
noaudioDisable audio functions
nocgoUse the purego backend even when cgo is enabled
extlibLoad the system raylib library instead of the embedded one (used with purego)

Documentation

Documentation on pkg.go.dev. Also check raylib cheatsheet. If you have problems or need assistance there is an active community on the Raylib Discord Server that can help.

Example

package main

import rl "github.com/gen2brain/raylib-go/raylib"

func main() {
  rl.InitWindow(800, 450, "raylib [core] example - basic window")
  defer rl.CloseWindow()

  rl.SetTargetFPS(60)

  for !rl.WindowShouldClose() {
    rl.BeginDrawing()

    rl.ClearBackground(rl.RayWhite)
    rl.DrawText("Congrats! You created your first window!", 190, 200, 20, rl.LightGray)

    rl.EndDrawing()
  }
}

Check more examples organized by raylib modules.

Packaging

rlpkg builds and signs packages: a Windows .exe with icon or an .msix, a macOS .app, a Linux tarball, .deb or .rpm, an Android .apk or .aab, an iOS .ipa and a WebAssembly site.

go install github.com/gen2brain/raylib-go/cmd/rlpkg@latest
rlpkg package --os android --install ./game

Cross-compile (on Linux with cgo)

To cross-compile for Windows, install MinGW toolchain.

$ CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc GOOS=windows GOARCH=amd64 go build -ldflags "-s -w"
$ file basic_window.exe
basic_window.exe: PE32+ executable for MS Windows 10.00 (console), x86-64, 5 sections

$ CGO_ENABLED=1 CC=i686-w64-mingw32-gcc GOOS=windows GOARCH=386 go build -ldflags "-s -w"
$ file basic_window.exe
basic_window.exe: PE32 executable for MS Windows 10.00 (console), Intel i386, 4 sections

To cross-compile for Windows on ARM, install LLVM MinGW toolchain.

$ CGO_ENABLED=1 CC=aarch64-w64-mingw32-clang GOOS=windows GOARCH=arm64 go build -ldflags "-s -w"
$ file basic_window.exe
basic_window.exe: PE32+ executable for MS Windows 10.00 (console), ARM64, 6 sections

To cross-compile for macOS, install OSXCross toolchain. Ready-made SDK tarballs are available here.

$ CGO_ENABLED=1 CC=x86_64-apple-darwin25.1-clang GOOS=darwin GOARCH=amd64 go build -ldflags "-s -w"
$ file basic_window
basic_window: Mach-O 64-bit x86_64 executable, flags:<NOUNDEFS|DYLDLINK|TWOLEVEL|WEAK_DEFINES|BINDS_TO_WEAK|PIE>

$ CGO_ENABLED=1 CC=aarch64-apple-darwin25.1-clang GOOS=darwin GOARCH=arm64 go build -ldflags "-s -w"
$ file basic_window
basic_window: Mach-O 64-bit arm64 executable, flags:<NOUNDEFS|DYLDLINK|TWOLEVEL|WEAK_DEFINES|BINDS_TO_WEAK|PIE>

License

raylib-go is licensed under an unmodified zlib/libpng license. View LICENSE.

Frequently Asked Questions

What is raylib-go?

raylib-go is a Game Development library for the Go programming language. Go bindings for [raylib](https://www.raylib.com/), a simple and easy-to-use library to learn videogames programming

How many GitHub stars does raylib-go have?

raylib-go has 2,580 GitHub stars in the directory's latest synchronization.

How do I install raylib-go?

Install raylib-go with the Go module system using `go get gen2brain/raylib-go`. Check the repository for the current installation instructions.

What category does raylib-go belong to?

raylib-go is listed under Game Development, specifically Game Development.

← Back to Game Development