go-raylib

module
v0.0.0-...-dca22cd Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 17, 2021 License: Zlib

README

go-raylib

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

Bindings
Header Supported
raylib.h
raymath.h
physac.h
raygui.h
ricons.h
Platforms
OS Supported
Mac
Linux
Windows
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!

Category Example Supported
audio module_playing
audio multichannel_sound
audio music_stream
audio raw_stream
audio sound_loading
core 2d_camera
core 2d_camera_platformer
core 3d_camera_first_person
core 3d_camera_free
core 3d_camera_mode
core 3d_picking
core basic_window
core drop_files
core input_gestures
core input_keys
core input_mouse
core input_mouse_wheel
core input_multitouch
core random_values
core scissor
core storage_values
core vr_simulator
core window_letterbox
core world_screen
gui controls_test_suite
gui scroll_panel
models animation
models billboard
models box_collisions
models cubicmap
models first_person_maze
models loading
models material_pbr
models mesh_generation
models mesh_picking
models orthographic_projection
models skybox
models waving_cubes
models yaw_pitch_roll
physac demo
physac friction
shaders postprocessing
shaders basic_lighting
shaders eratosthenes
shaders fog
shaders julia_set
shaders model_shader
shaders palette_switch
text font_filters
text font_loading
text font_sdf
text font_spritefont
text format_text
text input_box
text raylib_fonts
text rectangle_bounds
text unicode
text writing_anim
textures bunnymark
textures rectangle

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL