Categorygithub.com/NiftySoft/go-raylib
repository
0.0.0-20210517025552-dca22cd4e4a2
Repository: https://github.com/niftysoft/go-raylib.git
Documentation: pkg.go.dev

# Packages

No description provided by the author
No description provided by the author
No description provided by the author

# README

go-raylib

go-raylib is a simple and easy-to-use library to enjoy videogames programming.

Bindings

HeaderSupported
raylib.h:heavy_check_mark:
raymath.h:heavy_check_mark:
physac.h:heavy_check_mark:
raygui.h:heavy_check_mark:
ricons.h:heavy_check_mark:

Platforms

OSSupported
Mac:heavy_check_mark:
Linux:heavy_check_mark:
Windows:heavy_check_mark:

Version

go-raylib binding raylib C 3.5 release version

Performance

High performance, same with the raylib C version.

Development Tools

I use sublime text and customize tools.

c-for-go automatic C-Go bindings generator for raylib C version.

LSP use mistune instead mdpopups.

language-formatter general code format tool.

gopls fix go-raylib code autocomplete slow.

Theme-Mariana general color scheme.

Memory

For example

multext := rl.NewMultiText([]string{"Hello World!"})

The method will check if memory is requested through cgo.

If it detects, panic Cgo memory alloced, please use func AllocMultiText.

Rewrite.

multext, men := rl.AllocMultiText([]string{"Hello World!"})
multext.GC(mem)

Don't forget, call GC() for register, it can be automated management.

Difference

There are some differences between the processing in Go and C.

In C

char multiTextBoxText[256] = "Multi text box";

In Go

multiTextBoxText := rg.NewBytes("Multi text box", 256)

In C

const char *listViewExList[8] = { "This", "is", "a", "list view", "with", "disable", "elements", "amazing!" };

In Go

listViewExList, mem := rg.AllocMultiText([]string{"This", "is", "a", "list view", "with", "disable", "elements", "amazing!"})
listViewExList.GC(mem)

In C

int dropsCount = 0;
char **droppedFiles = GetDroppedFiles(&dropsCount);
const char *droppedFilePath = droppedFiles[0];

In Go

dropsCount := int32(0)
droppedFiles := rl.GetDroppedFiles(&dropsCount)
droppedFilePath := rl.ToString(droppedFiles, 0)

In C

Texture2D texture = LoadTexture("resources/cubicmap_atlas.png");
model.materials[0].maps[MAP_DIFFUSE].texture = texture;

In Go

texture := rl.LoadTexture("../models/resources/cubicmap_atlas.png")
model.Materialser(0).Mapser(rl.MAP_DIFFUSE).Texture = texture

Usage

Step 1: Get the go-raylib code

go get -u github.com/chunqian/go-raylib

Step 2: Write the code

package main

import (
    rl "github.com/chunqian/go-raylib/raylib"

    "runtime"
)

func init() {
    runtime.LockOSThread()
}

func main() {
    screenWidth := int32(800)
    screenHeight := int32(450)

    rl.InitWindow(screenWidth, screenHeight, "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()
    }
}

Step 3: Build the code

Macos Linux

export GO111MODULE="on"
export CGO_ENABLED=1
go mod init github.com/chunqian/go-raylib-example
go build

Windows

set GO111MODULE=on
set CGO_ENABLED=1
set GOARCH=386
go mod init github.com/chunqian/go-raylib-example
go build

Require

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.

Ubuntu

sudo apt-get install libasound2-dev mesa-common-dev libx11-dev libxrandr-dev libxi-dev xorg-dev libgl1-mesa-dev libglu1-mesa-dev

Examples

Complete with +60 code examples!

CategoryExampleSupported
audiomodule_playing:heavy_check_mark:
audiomultichannel_sound:heavy_check_mark:
audiomusic_stream:heavy_check_mark:
audioraw_stream:heavy_check_mark:
audiosound_loading:heavy_check_mark:
core2d_camera:heavy_check_mark:
core2d_camera_platformer:heavy_check_mark:
core3d_camera_first_person:heavy_check_mark:
core3d_camera_free:heavy_check_mark:
core3d_camera_mode:heavy_check_mark:
core3d_picking:heavy_check_mark:
corebasic_window:heavy_check_mark:
coredrop_files:heavy_check_mark:
coreinput_gestures:heavy_check_mark:
coreinput_keys:heavy_check_mark:
coreinput_mouse:heavy_check_mark:
coreinput_mouse_wheel:heavy_check_mark:
coreinput_multitouch:heavy_check_mark:
corerandom_values:heavy_check_mark:
corescissor:heavy_check_mark:
corestorage_values:heavy_check_mark:
corevr_simulator:heavy_check_mark:
corewindow_letterbox:heavy_check_mark:
coreworld_screen:heavy_check_mark:
guicontrols_test_suite:heavy_check_mark:
guiscroll_panel:heavy_check_mark:
modelsanimation:heavy_check_mark:
modelsbillboard:heavy_check_mark:
modelsbox_collisions:heavy_check_mark:
modelscubicmap:heavy_check_mark:
modelsfirst_person_maze:heavy_check_mark:
modelsloading:heavy_check_mark:
modelsmaterial_pbr:heavy_check_mark:
modelsmesh_generation:heavy_check_mark:
modelsmesh_picking:heavy_check_mark:
modelsorthographic_projection:heavy_check_mark:
modelsskybox:heavy_check_mark:
modelswaving_cubes:heavy_check_mark:
modelsyaw_pitch_roll:heavy_check_mark:
physacdemo:heavy_check_mark:
physacfriction:heavy_check_mark:
shaderspostprocessing:heavy_check_mark:
shadersbasic_lighting:heavy_check_mark:
shaderseratosthenes:heavy_check_mark:
shadersfog:heavy_check_mark:
shadersjulia_set:heavy_check_mark:
shadersmodel_shader:heavy_check_mark:
shaderspalette_switch:heavy_check_mark:
textfont_filters:heavy_check_mark:
textfont_loading:heavy_check_mark:
textfont_sdf:heavy_check_mark:
textfont_spritefont:heavy_check_mark:
textformat_text:heavy_check_mark:
textinput_box:heavy_check_mark:
textraylib_fonts:heavy_check_mark:
textrectangle_bounds:heavy_check_mark:
textunicode:heavy_check_mark:
textwriting_anim:heavy_check_mark:
texturesbunnymark:heavy_check_mark:
texturesrectangle:heavy_check_mark:

License

go-raylib is licensed under an unmodified zlib/libpng license, which is an OSI-certified, BSD-like license that allows static linking with closed source software. Check LICENSE for further details.