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

logo

raylib-go

TravisCI Build Status AppVeyor Build status GoDoc Go Report Card Examples

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

Requirements

Ubuntu
X11
apt-get install libgl1-mesa-dev libxi-dev libxcursor-dev libxrandr-dev libxinerama-dev 
Wayland
apt-get install libgl1-mesa-dev libwayland-dev libxkbcommon-dev 
Fedora
X11
dnf install mesa-libGL-devel libXi-devel libXcursor-devel libXrandr-devel libXinerama-devel
Wayland
dnf install mesa-libGL-devel wayland-devel libxkbcommon-devel
macOS

On macOS you need Xcode or Command Line Tools for Xcode.

Windows

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

Android

Android example.

Raspberry Pi

RPi example.

Installation

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

Build tags

  • noaudio - disables audio functions
  • opengl21 - uses OpenGL 2.1 backend (default is 3.3 on desktop)
  • opengl11 - uses OpenGL 1.1 backend (pseudo OpenGL 1.1 style)
  • wayland - builds against Wayland libraries

Documentation

Documentation on GoDoc. Also check raylib cheatsheet.

Example

package main

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

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

	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()
	}

	rl.CloseWindow()
}

Check more examples organized by raylib modules.

License

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

Owner
Milan Nikolic
SysAdmin / Developer
Milan Nikolic
Comments
  • How do I redistribute my prototype-game?

    How do I redistribute my prototype-game?

    I was making a game prototype, and I tried to send it to someone who volunteered to test the game (we're both using Windows 10, and I compiled the game on Windows 10 (Home)). I built the code using go build ./rsrc/code. But when they try to open the exe (RuntDeale/code.exe), they get this error: image

    The code execution cannot proceed because
    libwinpthread-1.dll was not found. Reinstalling the program
    may fix this problem.
    

    How can I fix this? My GoLang version is: go1.16.4 windows/amd64.

    Thanks.
    Cheers!

  • Windows MSYS2 - endian.h

    Windows MSYS2 - endian.h

     MINGW64 ~
    $ go get -v github.com/gen2brain/raylib-go/raylib
    github.com/gen2brain/raylib-go/raylib
    # github.com/gen2brain/raylib-go/raylib
    In file included from C:\goworksp\src\github.com\gen2brain\raylib-go\raylib\audio.c:89:0:
    C:\goworksp\src\github.com\gen2brain\raylib-go\raylib\external/dr_flac.h:685:20: fatal error: endian.h: No such file or directory
     #include <endian.h>
                        ^
    compilation terminated.
    

    I have no endian.h file in MSYS2.

  • Model loading examples render a cube and not the model

    Model loading examples render a cube and not the model

    I tested two examples, examples/shaders/model_shader and examples/models/obj_loading and neither render the expected model, but instead render a black cube.

    Steps to reproduce: Git clone the repo, cd to examples, run "go run ./models/obj_loading".

    This was an issue a while ago when I first started using the library but it was fixed at some point. It's sad to see this being an issue once again.

    1636815951

    INFO: Initializing raylib 3.8-dev
    INFO: DISPLAY: Device initialized successfully
    INFO:     > Display size: 3840 x 2160
    INFO:     > Render size:  800 x 450
    INFO:     > Screen size:  800 x 450
    INFO:     > Viewport offsets: 0, 0
    INFO: GLAD: OpenGL extensions loaded successfully
    INFO: GL: Supported extensions count: 229
    INFO: GL: OpenGL device information:
    INFO:     > Vendor:   AMD
    INFO:     > Renderer: Radeon RX Vega (VEGA10, DRM 3.40.0, 5.11.0-40-generic, LLVM 12.0.0)
    INFO:     > Version:  4.6 (Core Profile) Mesa 21.0.3
    INFO:     > GLSL:     4.60
    INFO: GL: DXT compressed textures supported
    INFO: GL: ETC2/EAC compressed textures supported
    INFO: TEXTURE: [ID 1] Texture loaded successfully (1x1 - 1 mipmaps)
    INFO: TEXTURE: [ID 1] Default texture loaded successfully
    INFO: SHADER: [ID 1] Vertex shader compiled successfully
    INFO: SHADER: [ID 2] Fragment shader compiled successfully
    INFO: SHADER: [ID 3] Program shader loaded successfully
    INFO: SHADER: [ID 3] Default shader loaded successfully
    INFO: RLGL: Render batch vertex buffers loaded successfully in RAM (CPU)
    INFO: RLGL: Render batch vertex buffers loaded successfully in VRAM (GPU)
    INFO: RLGL: Default OpenGL state initialized successfully
    INFO: TEXTURE: [ID 2] Texture loaded successfully (128x128 - 1 mipmaps)
    INFO: FONT: Default font loaded successfully
    WARNING: FILEIO: [castle.obj] Failed to open text file
    WARNING: MESH: [castle.obj] Failed to load mesh data, default to cube mesh
    INFO: VAO: [ID 2] Mesh uploaded successfully to VRAM (GPU)
    WARNING: MATERIAL: [castle.obj] Failed to load material data, default to white material
    WARNING: FILEIO: [castle_diffuse.png] Failed to open file
    INFO: TIMER: Target time per frame: 16.667 milliseconds
    INFO: VAO: [ID 2] Unloaded vertex array data from VRAM (GPU)
    INFO: MODEL: Unloaded model (and meshes) from RAM and VRAM
    INFO: TEXTURE: [ID 2] Unloaded texture data from VRAM (GPU)
    INFO: SHADER: [ID 3] Default shader unloaded successfully
    INFO: TEXTURE: [ID 1] Default texture unloaded successfully
    INFO: Window closed successfully
    
  • Bigger textures sometimes, randomly won't load to GPU

    Bigger textures sometimes, randomly won't load to GPU

    It's hard to say with precision what's causing this because it's an intermittent problem, I don't seem to be able to find an exact pattern of behaviour.

    All the examples that come with raylib-go work just fine, and I wrote a couple of my own that work just fine, loading textures and painting them on screen. However once I started to create slightly more complex tests, I began to experience problems with some textures. I worked to narrow down the problem to the bare minimum, and I realised that the bare minimum code that comes with the examples also exhibits this problem if you leave the code unmodified, and you change the texture images you use.

    For example, if I compile any of the raylib-go examples in the textures examples folder, and I run them unmodified they work just fine. Then I only change the image texture the example uses without changing anything of the code, and I start getting errors when I attempt to load the texture to GPU. (the texture load function complains and doesn't return a texture handle).

    So I tried different texture sizes. I created different PNG files of different sizes, and ran the code unmodified, only changing the texture files.

    The texture samples appear to always work just fine for texture sizes of under 512 x 512 pixels in size. Problems begin to appear after I increase the texture size beyond 512 x 512 pixels, the texture sometimes, apparently randomly, won't load to GPU. This behaviour happens more frequently as you increase the texture size. For example, if you attempt to load a 1024 x 1024 texture, that increases the frequency of failures, the programs fail more often. If you create textures of 2048 x 2048 and above, the frequency of failures is completely unpredictable, and programs fail to load textures of that size more than 50% of the time.

    I'm using Ubuntu 16.04 with XGL extensions, and the Compiz manager, on an Intel Compute Stick that comes with a typical Intel GPU. This is the raylib output log when programs in the examples/textures folder are started.

    INFO: Initializing raylib (v1.7.0) INFO: Display device initialized successfully INFO: Display size: 1920 x 1080 INFO: Render size: 800 x 450 INFO: Screen size: 800 x 450 INFO: Viewport offsets: 0, 0 INFO: GLAD: OpenGL extensions loaded successfully INFO: OpenGL 3.3 Core profile supported INFO: GPU: Vendor: Intel Open Source Technology Center INFO: GPU: Renderer: Mesa DRI Intel(R) Bay Trail INFO: GPU: Version: 3.3 (Core Profile) Mesa 12.0.6 INFO: GPU: GLSL: 3.30

  • Textured models examples do not render properly

    Textured models examples do not render properly

    When I apply textures to built-in procedural objects(cube, sphere, torus, billboard etc.) they display OK, but when the model is loaded from .obj, this happens:

    bug000 bug001 bug_002

    When I inspect the meshes of these objects from Go, they display incorrect array lengths(very large values) and attempting to access an array index of the vertices triggers a segfault.

    I also attempted to load an obj file manually, using pure Go code and rl.NewMesh(), but have not yet succeeded in making it display.

  • no buildable Go source files

    no buildable Go source files

    Hi, I get

    package github.com/gen2brain/raylib-go: no buildable Go source files in ...
    

    on macOS with glfw3 and openal-soft installed with brew and linked.

  • Wayland Support missing Headers

    Wayland Support missing Headers

    When building with the wayland tag, following error occurs:

    # github.com/gen2brain/raylib-go/raylib
    In file included from ./external/glfw/src/internal.h:171:0,
                     from ./external/glfw/src/context.c:28,
                     from /.../go/src/github.com/gen2brain/raylib-go/raylib/cgo_linux.go:6:
    ./external/glfw/src/wl_platform.h:54:10: fatal error: wayland-relative-pointer-unstable-v1-client-protocol.h: No such file or directory
     #include "wayland-relative-pointer-unstable-v1-client-protocol.h"
              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    

    For more information please see:

    • https://github.com/go-gl/glfw/pull/199
    • https://github.com/go-gl/glfw/wiki/Development

    Thanks!

  • Help: Can't Translate

    Help: Can't Translate "core_2d_camera_mouse_zoom" Example to Go

    I'm trying to follow the 2D Camera Mouse Zoom example.

    I've managed to translate most of it to Go, but I can't find equivalent functions in raylib-go for the following section:

    // Draw the 3d grid, rotated 90 degrees and centered around 0,0 
    // just so we have something in the XY plane
    rlPushMatrix();
        rlTranslatef(0, 25*50, 0);
        rlRotatef(90, 1, 0, 0);
        DrawGrid(100, 50);
    rlPopMatrix();
    

    Here's my broken code for the section:

    // Not sure what to do with `matrix` here.
    matrix := rl.MatrixTranslate(0, 25*50, 0)
    matrix = rl.MatrixRotate(rl.Vector3{X: 90, Y: 1, Z: 0}, 0)
    rl.DrawGrid(100, 50)
    _ = matrix
    

    How do I translate the code from the example to Go?

  • Windows build from linux gives error undefined function

    Windows build from linux gives error undefined function

    When I try to build a binary for the windows platform as well as darwin an error pops up

    gen2brain/raylib-go/raylib/raylib.go:1120:9: undefined: LoadImageEx

    2019-03-23-223618_842x374_scrot

    This is my small Program which loads an image, creates a texture and draws into the screen (I've not added all of the code here).

  • Why is RayMath and its types separate from its package?

    Why is RayMath and its types separate from its package?

    @gen2brain I find it difficult to understand why is Vector2/3, Quaternions and Matrix structs separate from their respective math functions.

    Instead of #raymath.Normalize(v *raylib.Vector2) { ... &v = normval} Bundle all Vector2/3, Quaternions and Matrix into Raymath and pass the structs as recievers to the functions?

    Example: func (v Vector2) Normalize() Vector2 { return normalizedVector }

    That way whenever a vector2 needs to be normalized, they don't have to be called from two different packages and just do this: normVec2 := raymath.NewVector2(1,1).Normalized()


    normVec2 := raymath.NewVector2(1,1).Normalized() versus vec2 := raylib.NewVector2(1,1,1) normVec2 := raymath.Normalize(vec2)

  • audio examples hanging

    audio examples hanging

    Hi I'm on Arch Linux. All examples run fine with the exception of audio. When I run e.g. "module_playing" it opens the window but only shows a black screen. I hear nothing and Gnome asks me to close the hanging program.

    I wonder if you have an idea what causes this? All of these examples run fine when I compile them for original raylib(C) 1.8.0.

  • add toturial to new android ndk

    add toturial to new android ndk

    I was trying to compile library, but new parth of ndk was chalange, all headers seems is included, but I do not know why it write error with ";", maybe will hood to add next example ...

    export ndk=/home/matejmag/Android/Sdk/ndk/25.1.8937393
    export ANDROID_SYSROOT=${ndk}/toolchains/llvm/prebuilt/linux-x86_64/sysroot
    export ANDROID_PLATFORM=${ndk}/platforms/android-16/arch-arm
    export ANDROID_TOOLCHAIN=${ANDROID_SYSROOT}/usr/lib/aarch64-linux-android
    GOOS=android \
    GOARCH=arm64 \
    CC=${ndk}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android21-clang \
    CXX=${ndk}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android21-clang++ \
    CGO_CFLAGS="-I${ANDROID_SYSROOT}/usr/include -I${ANDROID_SYSROOT}/usr/include/arm-linux-androideabi --sysroot=${ANDROID_SYSROOT}" \
    CGO_LDFLAGS="-L${ANDROID_SYSROOT}/usr/lib/arm-linux-androideabi
    -I${ANDROID_SYSROOT}usr/include/GLES
     -I${ANDROID_SYSROOT}usr/include/GLES2
     -I${ANDROID_SYSROOT}usr/include/GLES3
     -I${ANDROID_SYSROOT}usr/include/EGL
     -I${ndk}/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/aarch64-linux-android/asm
     -I${ndk}/toolchains/llvm/prebuilt/linux-x86_64/include/c++/4.9.x
     -I${ANDROID_TOOLCHAIN}
      -lpthread
     -I${ANDROID_TOOLCHAIN}/33 --sysroot=${ANDROID_TOOLCHAIN}/33" \
    CGO_ENABLED=1 \
    go build -buildmode=c-shared -ldflags="-s -w" \
    -o=android/libs/armeabi-v7a/libexample.so
    
  • missing raylib.h

    missing raylib.h

    repo: example gui

    Here is an example of trying to run one of the example gui apps. Every time I try run go run main.go I get this error.

    When I don't try to build the raygui app. It compiles fine. Am I running this wrong?

    go run main.go           
    # github.com/gen2brain/raylib-go/raygui
    In file included from ../../../../pkg/mod/github.com/gen2brain/raylib-go/[email protected]/raygui.go:5:
    ./raygui.h:209:14: fatal error: raylib.h: No such file or directory
      209 |     #include "raylib.h"
          |              ^~~~~~~~~~
    compilation terminated.
    
  • Just wondering about Basic Lighting

    Just wondering about Basic Lighting

    You are probably busy though I would really like to be able to complete the Basic Lighting Raylib Shaders example, it is not added however would be really great if it could be.

  • Add example build

    Add example build

    Hello,

    I think we can add go build for each example for checking build.

    https://github.com/gen2brain/raylib-go/blob/ce3c8e83dd6dbccab1472e6f8e33ab8b15d9844a/.github/workflows/build.yml#L21

    Have fun.

  • Update rres

    Update rres

    Rres now have a final format, Go rres and the resources example should be updated. Also, there are many FromMemory functions that didn't exist before.

Bampf is a simple 3D arcade style game. Collect Energy Cores in order to finish a level. Teleport (bampf) to safety or use cloaking abilities to avoid Sentinels.

Bampf Bampf is a simple 3D arcade style game. Collect energy cores in order to finish a level. Teleport (bampf) to safety or use cloaking abilities to

Dec 12, 2022
Dabulang is an interpreted object-oriented programming language aimed towards game development.

Dabulang (ダブ言語) Dabulang is an interpreted object-oriented programming language aimed towards game development. The language's standard library has a

Sep 14, 2022
basicbots is a programming game where you program your robot to compete against other robot.
basicbots is a programming game where you program your robot to compete against other robot.

basicbots What is baiscbots? basicbots is a programming game where you program your robot to compete agaist other robots. What is the inspiration? My

Jan 8, 2022
Use random bot scanning the internet to seed a Conways Game of Life running on a small LCD on my desk

botnet-fishbowl Use random bots scanning the internet to seed a Conways Game of Life running on a small LCD on my desk Conways Game of Life tends to r

Dec 9, 2022
A dead simple 2D game library for Go
A dead simple 2D game library for Go

Ebiten (v2) A dead simple 2D game library for Go Ebiten is an open source game library for the Go programming language. Ebiten's simple API allows you

Dec 28, 2022
A simple Go library for 3D ray-tracing rendering, implementing the book Ray Tracing in One Weekend.
A simple Go library for 3D ray-tracing rendering, implementing the book Ray Tracing in One Weekend.

Ray Tracing in Go A Go implementation of the book Ray Tracing in One Weekend. The repository provides a library to describe and render your own scenes

Sep 23, 2022
build and animate objects according to verlet physics. pure golang library
build and animate objects according to verlet physics. pure golang library

verlet build and animate objects according to verlet physics. pure golang library Examples depend on pixel library, see requirements to build them: wo

Dec 22, 2022
Golang writen 3D render library and some game-relative concepts

Golang writen 3D render library and some game-relative concepts.

Jun 6, 2022
This is a "simple" game server. Main functionalities are matching and establishing a connection between players
This is a

Game Server This is a "simple" game server. Main functionalities are matching and establishing a connection between players How to Run? run the server

Aug 28, 2022
A simple and (currently) deterministic decision management service written in go

dang This is a simple and (currently) deterministic decision management service written in Go. Inspired by (but not yet conforming to) the DMN spec. L

Dec 10, 2021
The simple and light self-hosted custom event analytics you were looking for.

Dead-Simple-Game-Analytics What is Dead Simple Game Analytics? An extremely simple self-hosted system to log your game analytics events. No fluff or o

Oct 23, 2022
Simple 2D game to teach myself various things about game development and ECS, etc

2d-grass-game I really don't know what to name this game. Its a big grass field, and its in 2d so....2D Grass game This is a simple 2D game to teach m

Jan 17, 2022
A hand-crafted 2D game library in Go
A hand-crafted 2D game library in Go

Pixel A hand-crafted 2D game library in Go. Take a look into the features to see what it can do. go get github.com/faiface/pixel If you are using Mod

Dec 31, 2022
Helper library to transform TMX tile maps into a simpler format for Ebiten

Ebitmx Ebitmx is a super simple parser to help render TMX maps when using Ebiten for your games. Right now is super limited to XML and CSV data struct

Nov 16, 2022
Rock-paper-scissors game library
Rock-paper-scissors game library

jankensheep Rock-paper-scissors game library Examples Play with two players:

May 13, 2022
Golang library for connecting to EOSIO SHIP

go-eosio-ship go-eosio-ship is a golang library built on top of go-eosio for con

Jan 3, 2022
Battleblips - Work in progress multiplayer terminal base battleship game written in Go (with mouse support!) using tcell library
Battleblips - Work in progress multiplayer terminal base battleship game written in Go (with mouse support!) using tcell library

battleblips Work in progress multiplayer terminal base battleship game written in Go (with mouse support!) using tcell library (see https://github.com

Apr 26, 2022
Donburi is just another Entity Component System library for Ebiten inspired by legion.
Donburi is just another Entity Component System library for Ebiten inspired by legion.

Donburi Donburi is just another Entity Component System library for Ebiten inspired by legion. It aims to be a feature rich and high performance ECS L

Dec 15, 2022
Spaceshooter - A port to go of the pygame Space Shooter game using the ebiten library
Spaceshooter - A port to go of the pygame Space Shooter game using the ebiten library

Space Shooter This is a port to go of the pygame Space Shooter (https://github.c

Sep 29, 2022