Skip to content
gen2brainPublic

About

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

Topics

Resources

Stars

2.6k stars

Watchers

22 watching

Forks

Latest commit

 

History

1,357 Commits

Folders and files

Repository files navigation

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):

Tag Description
glfw GLFW backend (PLATFORM_DESKTOP_GLFW)
drm Linux native DRM mode only, including Raspberry Pi and other devices (PLATFORM_DRM)
sdl SDL backend (PLATFORM_DESKTOP_SDL)
sdl3 SDL3 backend (PLATFORM_DESKTOP_SDL3)
rgfw RGFW backend (PLATFORM_DESKTOP_RGFW)
wayland Native Wayland backend only, Linux only (PLATFORM_DESKTOP_WAYLAND)
x11 Native X11 backend only, Linux and BSD (PLATFORM_DESKTOP_X11)
memory Headless, renders to memory (PLATFORM_MEMORY)
termux Termux 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):

Tag Description
opengl43 OpenGL 4.3
opengl33 OpenGL 3.3
opengl21 OpenGL 2.1
opengl11 OpenGL 1.1 (pseudo OpenGL 1.1 style)
es2 OpenGL ES 2.0 (can be used to link against Google's ANGLE)
es3 OpenGL ES 3.0 (experimental)
software Software renderer (rlsw)

Options:

Tag Description
glfw_x11 GLFW with X11 only (implies glfw)
glfw_wayland GLFW with Wayland only (implies glfw)
noaudio Disable audio functions
nocgo Use the purego backend even when cgo is enabled
extlib Load 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.

About

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

Topics

Resources

Stars

2.6k stars

Watchers

22 watching

Forks

Releases

Used by

Contributors

Languages