Volver al ranking

gen2brain/raylib-go

C

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

game-engineraylibandroidrpigolangvideo-game
Crecimiento de estrellas
Estrellas
2.5k
Forks
210
Crecimiento semanal
Issues
8
1k2k
ene 2017mar 2020may 2023jul 2026
README

logo

raylib-go

Build Status GoDoc Go Report Card 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 requirements below).

Requirements

cgo

Ubuntu
apt-get install libgl1-mesa-dev libxi-dev libxcursor-dev libxrandr-dev libxinerama-dev libwayland-dev libxkbcommon-dev
Fedora
dnf install mesa-libGL-devel libXi-devel libXcursor-devel libXrandr-devel libXinerama-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.

Wasm

For web bindings, refer to Raylib-Go-Wasm; it should be largely compatible with this repository.

purego (without cgo, i.e. CGO_ENABLED=0)

You can use raylib-go on Linux, macOS, Windows and FreeBSD without the need of cgo. 32-bit is not supported.

The shared libraries (.dll, .so, .dylib) of raylib are already embedded for Linux arm64/amd64, macOS arm64/amd64 and Windows arm64/amd64. The build tag raylib_no_embed or the environment variable RAYLIB_NO_EMBED=1 can disable this feature.

Installation

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

Build tags

  • drm - build for Linux native DRM mode, including Raspberry Pi 4 and other devices (PLATFORM_DRM)
  • sdl - build for SDL backend (PLATFORM_DESKTOP_SDL)
  • sdl3 - build for SDL3 backend (PLATFORM_DESKTOP_SDL3)
  • rgfw - build for RGFW backend (PLATFORM_DESKTOP_RGFW)
  • noaudio - disables audio functions
  • opengl43 - uses OpenGL 4.3 backend
  • opengl21 - uses OpenGL 2.1 backend (default is 3.3 on desktop)
  • opengl11 - uses OpenGL 1.1 backend (pseudo OpenGL 1.1 style)
  • es2 - uses OpenGL ES 2.0 backend (can be used to link against Google's ANGLE)
  • es3 - experimental support for OpenGL ES 3.0
  • x11 - force X11 compatibility mode on Wayland (PLATFORM_DESKTOP/GLFW)
  • wayland - force Wayland only mode (PLATFORM_DESKTOP/GLFW)
  • raylib_no_embed - doesn't embed the pre-build shared libraries (only applies to purego version)

Documentation

Documentation on GoDoc. Also check raylib cheatsheet. If you have problems or need assistance there is an active community in the #raylib-go channel of 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.

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 (console) x86-64 (stripped to external PDB), for MS Windows, 11 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 (console) Intel 80386 (stripped to external PDB), for MS Windows, 9 sections

To cross-compile for macOS install OSXCross toolchain.

$ CGO_ENABLED=1 CC=x86_64-apple-darwin21.1-clang GOOS=darwin GOARCH=amd64 go build -ldflags "-linkmode external -s -w '-extldflags=-mmacosx-version-min=10.15'"
$ file basic_window
basic_window: Mach-O 64-bit x86_64 executable, flags:<NOUNDEFS|DYLDLINK|TWOLEVEL>

$ CGO_ENABLED=1 CC=aarch64-apple-darwin21.1-clang GOOS=darwin GOARCH=arm64 go build -ldflags "-linkmode external -s -w '-extldflags=-mmacosx-version-min=12.0.0'"
$ file basic_window
basic_window: Mach-O 64-bit arm64 executable, flags:<NOUNDEFS|DYLDLINK|TWOLEVEL|PIE>

License

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

Repositorios relacionados
godotengine/godot

Godot Engine – Multi-platform 2D and 3D game engine

C++MIT Licensegame-enginegodot
godotengine.org
114.4k26k
ocornut/imgui

Dear ImGui: Bloat-free Graphical User interface for C++ with minimal dependencies

C++MIT Licenseguigamedev
74.9k11.9k
bevyengine/bevy

A refreshingly simple data-driven game engine built in Rust

Rustcrates.ioApache License 2.0bevygamedev
bevy.org
47.3k4.7k
raysan5/raylib

A simple and easy-to-use library to enjoy videogames programming

Czlib Licenseraylibc
raylib.com
34k3.2k
BabylonJS/Babylon.js

Babylon.js is a powerful, beautiful, simple, and open game and rendering engine packed into a friendly JavaScript framework.

TypeScriptnpmApache License 2.0webglwebgl2
babylonjs.com
25.8k3.7k
libgdx/libgdx

Desktop/Android/HTML5/iOS Java game development framework

JavaMavenApache License 2.0libgdxjava
libgdx.com
25.2k6.5k
4ian/GDevelop

🎮 Open-source, cross-platform 2D/3D/multiplayer game engine designed for everyone.

JavaScriptnpmOthergamejavascript
gdevelop.io
25k1.5k
leereilly/games

Archived — A list of games, add-ons, maps, etc. hosted on GitHub. Any genre. Any platform. Any engine.

game-enginehtml5-games
24.9k3.5k
cocos2d/cocos2d-x

Cocos2d-x is a suite of open-source, cross-platform, game-development tools utilized by millions of developers across the globe. Its core has evolved to serve as the foundation for Cocos Creator 1.x & 2.x.

C++cocos2dcocos2d-x
cocos.com/en/cocos2d-x
19.1k7.1k
kitao/pyxel

A retro game engine for Python

Rustcrates.ioOthergamegame-development
17.6k929
aframevr/aframe

:a: Web framework for building virtual reality experiences.

JavaScriptnpmMIT Licensevrwebvr
aframe.io
17.6k4.4k
OpenRA/OpenRA

Open Source real-time strategy game engine for early Westwood games such as Command & Conquer: Red Alert written in C# using SDL and OpenGL. Runs on Windows, Linux, *BSD and Mac OS X.

C#GNU General Public License v3.0game-enginestrategy-game-engine
openra.net
17.1k3k