raylib-go

gen2brainZlib活跃维护

raylib 的 Go 语言绑定,让 Go 开发者能直接调用这套简单易用的游戏编程库来写 2D/3D 小游戏,支持 Android 和树莓派等平台。

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

暂无版本2,564star210fork同步于 2026-11-07 07:34 UTC

怎么上手

由 README 提炼,执行前请确认
go get -v -u github.com/gen2brain/raylib-go/raylib
硬件要求按 README 说明

README 未说明显存要求;纯 Go 模式支持 Linux、macOS、Windows、FreeBSD 的 arm64/amd64,不支持 32 位;DRM 构建标签可用于树莓派 4 等设备。

下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

用 Go 语言调用 raylib 写小游戏和图形程序,无需手写 C 绑定

raylib 的 Go 语言绑定,让 Go 开发者能直接调用这套简单易用的游戏编程库来写 2D/3D 小游戏,支持 Android 和树莓派等平台。

核心能力

  • 内置 raylib C 源码,随绑定一起编译
  • 支持纯 Go 模式,CGO_ENABLED=0 也能用
  • 预编译共享库已内嵌 Linux/macOS/Windows
  • 提供 drm、sdl、opengl 等多种构建标签
  • 按 raylib 模块组织大量示例可参考

容易踩的坑

首次编译会连同 raylib C 源码一起构建,可能耗时数分钟;cgo 模式在 Linux 需先装 libgl1-mesa-dev、libxi-dev 等开发库,Windows 需 MinGW-w64 或 TDM-GCC;纯 Go 模式不支持 32 位平台。

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

0 个版本

暂无 release 数据(可能没有发版,或尚未同步)。

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    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.