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

Overview

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.

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!

    opened by CalinZBaenen 17
  • 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.

    opened by 5k3105 17
  • 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
    
    opened by MelonFunction 13
  • 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

    opened by haiitch 13
  • 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.

    opened by triplefox 11
  • 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.

    opened by allochi 11
  • 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!

    opened by r0l1 10
  • 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).

    opened by katsifolis 9
  • 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)

    opened by vaiktorg 9
  • 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.

    opened by dbriemann 9
  • Is building for mobile and web target supported?

    Is building for mobile and web target supported?

    I ask because raylib offers building for the web via emscripten and building natively for at least Android.

    Are these features also available for raylib-go?

    opened by dbriemann 9
  • 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.

    opened by gen2brain 0
  • Rewrite/redesign raygui

    Rewrite/redesign raygui

    Raygui was rewritten in Go a long time ago. In the meantime, the C version is rewritten and new features are added. Some possible actions now are to rewrite again in Go or maybe use modernc ccgo and work with that. The other possibility is to create C bindings, which would require a lot of code duplications and will be more difficult to maintain as noted in PR https://github.com/gen2brain/raylib-go/pull/183.

    opened by gen2brain 0
  • Accessing OpenGL methods from within raylib-go

    Accessing OpenGL methods from within raylib-go

    Is it possible to access OpenGL methods from within raylib-go? I'm trying to port some c camera code (rlFPCamera.c) and I need access to methods like rlDrawRenderBatchActive, rlMatrixMode, rlPushMatrix, and rlLoadIdentity.

    opened by Technerder 5
  • Support OpenBSD?

    Support OpenBSD?

    Hi, it doesn't seem that OpenBSD is supported. (Note that in core.c, it notes that OpenBSD is supported by raylib) Running

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

    on OpenBSD -current (as of today) returns:

    github.com/gen2brain/raylib-go (download)
    github.com/gen2brain/raylib-go/raylib
    # github.com/gen2brain/raylib-go/raylib
    core.c:736:1: warning: control reaches end of non-void function [-Wreturn-type]
    core.c:1360:1: warning: control reaches end of non-void function [-Wreturn-type]
    core.c:1917:37: error: use of undeclared identifier 'gamepadReady'
    core.c:1931:9: error: use of undeclared identifier 'gamepadReady'; did you mean 'gamepadName'?
    core.c:1929:17: note: 'gamepadName' declared here
    core.c:1970:37: error: use of undeclared identifier 'gamepadReady'
    core.c:1970:97: error: use of undeclared identifier 'gamepadAxisState'
    core.c:1982:37: error: use of undeclared identifier 'gamepadReady'
    core.c:1983:10: error: use of undeclared identifier 'currentGamepadState'
    core.c:1983:50: error: use of undeclared identifier 'previousGamepadState'
    core.c:1984:10: error: use of undeclared identifier 'currentGamepadState'
    core.c:1996:37: error: use of undeclared identifier 'gamepadReady'
    core.c:1997:10: error: use of undeclared identifier 'currentGamepadState'
    core.c:2009:37: error: use of undeclared identifier 'gamepadReady'
    core.c:2010:10: error: use of undeclared identifier 'currentGamepadState'
    core.c:2010:50: error: use of undeclared identifier 'previousGamepadState'
    core.c:2011:10: error: use of undeclared identifier 'currentGamepadState'
    core.c:2023:37: error: use of undeclared identifier 'gamepadReady'
    core.c:2024:10: error: use of undeclared identifier 'currentGamepadState'
    core.c:2045:10: error: use of undeclared identifier 'currentMouseState'; did you mean 'currentKeyState'?
    core.c:320:13: note: 'currentKeyState' declared here
    core.c:2045:39: error: use of undeclared identifier 'previousMouseState'; did you mean 'previousKeyState'?
    core.c:319:13: note: 'previousKeyState' declared here
    core.c:2045:71: error: use of undeclared identifier 'currentMouseState'; did you mean 'currentKeyState'?
    core.c:320:13: note: 'currentKeyState' declared here
    fatal error: too many errors emitted, stopping now [-ferror-limit=]
    

    Is there anything I'm missing? Most of the requirements (Xlib and such) are in the base system.

    Thanks for looking into this.

    opened by refacto 6
Releases(v6.5.0)
Owner
Milan Nikolic
SysAdmin / Developer
Milan Nikolic
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

null 39 Apr 7, 2021
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

Job Vonk 0 Sep 14, 2022
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

Bill Jones 23 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

Remy 34 Dec 15, 2021
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

Hajime Hoshi 7.1k Sep 25, 2022
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

Yuto Takahashi 54 Sep 8, 2022
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

Paolo Calao 23 Sep 8, 2022
Golang writen 3D render library and some game-relative concepts

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

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

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

eco 8 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

ida 0 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

Nesh 2 Mar 29, 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

James Wynne III 1 Jan 17, 2022
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

Michal Štrba 4.1k Sep 25, 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

Raúl 19 Jun 16, 2022
Rock-paper-scissors game library

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

Genta Kamitani 6 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

null 0 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 (see https://github.com

null 1 Apr 26, 2022
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

yohamta 27 Sep 16, 2022
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

Jesús Espino 4 Apr 28, 2022