Skip to content

Commit 67668d8

Browse files
authored
Merge pull request #544 from JupiterRider/raylib_6
Update to raylib 6.0 + add purego support for desktop platforms
2 parents 4c35048 + 86a775a commit 67668d8

91 files changed

Lines changed: 38418 additions & 23694 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ Golang bindings for [raylib](http://www.raylib.com/), a simple and easy-to-use l
99

1010
raylib C source code is included and compiled together with bindings. Note that the first build can take a few minutes.
1111

12-
It is also possible to use raylib-go without cgo (Windows only; see requirements below).
12+
It is also possible to use raylib-go without cgo (see requirements below).
1313

1414
### Requirements
1515

16+
#### cgo
17+
1618
##### Ubuntu
1719

1820
apt-get install libgl1-mesa-dev libxi-dev libxcursor-dev libxrandr-dev libxinerama-dev libwayland-dev libxkbcommon-dev
@@ -27,20 +29,11 @@ On macOS, you need Xcode or Command Line Tools for Xcode (if you have `brew` ins
2729

2830
##### Windows
2931

30-
###### cgo
31-
3232
On Windows you need C compiler, like [Mingw-w64](https://mingw-w64.org) or [TDM-GCC](http://tdm-gcc.tdragon.net/).
3333
You can also build binary in [MSYS2](https://msys2.github.io/) shell.
3434

3535
To remove console window, build with `-ldflags "-H=windowsgui"`.
3636

37-
###### purego (without cgo, i.e. CGO_ENABLED=0)
38-
39-
Download the raylib.dll from the assets on the [releases page](https://github.com/raysan5/raylib/releases). It is contained in the `raylib-*_win64_msvc*.zip`.
40-
Put the raylib.dll into the root folder of your project or copy it into `C:\Windows\System32` for a system-wide installation.
41-
42-
It is also possible to build the DLL yourself. You can find more info at [raylib's wiki](https://github.com/raysan5/raylib/wiki/Working-on-Windows).
43-
4437
##### Android
4538

4639
[Android example](https://github.com/gen2brain/raylib-go/tree/master/examples/others/android/example).
@@ -49,6 +42,12 @@ It is also possible to build the DLL yourself. You can find more info at [raylib
4942

5043
For web bindings, refer to [Raylib-Go-Wasm](https://github.com/BrownNPC/Raylib-Go-Wasm); it should be largely compatible with this repository.
5144

45+
#### purego (without cgo, i.e. CGO_ENABLED=0)
46+
47+
You can use raylib-go on `Linux`, `macOS`, `Windows` and `FreeBSD` without the need of [cgo](https://go.dev/blog/cgo). 32-bit is not supported.
48+
49+
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.
50+
5251

5352
### Installation
5453

@@ -68,6 +67,7 @@ For web bindings, refer to [Raylib-Go-Wasm](https://github.com/BrownNPC/Raylib-G
6867
* `es3` - experimental support for OpenGL ES 3.0
6968
* `x11` - force X11 compatibility mode on Wayland (PLATFORM_DESKTOP/GLFW)
7069
* `wayland` - force Wayland only mode (PLATFORM_DESKTOP/GLFW)
70+
* `raylib_no_embed` - doesn't embed the pre-build shared libraries (only applies to purego version)
7171

7272
### Documentation
7373

@@ -99,7 +99,7 @@ func main() {
9999

100100
Check more [examples](https://github.com/gen2brain/raylib-go/tree/master/examples) organized by raylib modules.
101101

102-
### Cross-compile (Linux)
102+
### Cross-compile (on Linux with cgo)
103103

104104
To cross-compile for Windows install [MinGW](https://www.mingw-w64.org/) toolchain.
105105

examples/go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ require (
2020
)
2121

2222
require (
23-
github.com/ebitengine/purego v0.8.1 // indirect
23+
github.com/ebitengine/purego v0.10.0 // indirect
24+
github.com/jupiterrider/ffi v0.7.0 // indirect
2425
golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f // indirect
25-
golang.org/x/sys v0.27.0 // indirect
2626
)

examples/go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
github.com/ebitengine/purego v0.8.1 h1:sdRKd6plj7KYW33EH5As6YKfe8m9zbN9JMrOjNVF/BE=
2-
github.com/ebitengine/purego v0.8.1/go.mod h1:iIjxzd6CiRiOG0UyXP+V1+jWqUXVjPKLAI0mRfJZTmQ=
1+
github.com/ebitengine/purego v0.10.0 h1:QIw4xfpWT6GWTzaW5XEKy3HXoqrJGx1ijYHzTF0/ISU=
2+
github.com/ebitengine/purego v0.10.0/go.mod h1:iIjxzd6CiRiOG0UyXP+V1+jWqUXVjPKLAI0mRfJZTmQ=
33
github.com/jakecoffman/cp v1.2.1 h1:zkhc2Gpo9l4NLUZfeG3j33+3bQD7MkqPa+n5PdX+5mI=
44
github.com/jakecoffman/cp v1.2.1/go.mod h1:JjY/Fp6d8E1CHnu74gWNnU0+b9VzEdUVPoJxg2PsTQg=
5+
github.com/jupiterrider/ffi v0.7.0 h1:RKsl6Ascal+3kyAqR5Qcbp83LceQMLc1VZbPfHWoNzs=
6+
github.com/jupiterrider/ffi v0.7.0/go.mod h1:9dauhpOfNqrqk28fxuu0kkdeFtT9Qr4vbfigiuIXN7c=
57
github.com/neguse/go-box2d-lite v0.0.0-20170921151050-5d8ed9b7272b h1:+67TGbwfgeB5o03Rx+ZBW44zAQ+wUujcwdRA0p9CbJI=
68
github.com/neguse/go-box2d-lite v0.0.0-20170921151050-5d8ed9b7272b/go.mod h1:kvKwD9codtns5mvpA53V3vLnqFb/Ahcu8zgkGM0SIbI=
79
golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f h1:XdNn9LlyWAhLVp6P/i8QYBW+hlyhrhei9uErw2B5GJo=
810
golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f/go.mod h1:D5SMRVC3C2/4+F/DB1wZsLRnSNimn2Sp/NPsCrsv8ak=
9-
golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s=
10-
golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=

examples/models/animation/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ func main() {
5959
if rl.IsKeyDown(rl.KeySpace) {
6060
animFrameCount++
6161
animCurrent := anims[0]
62-
animFrameNum := animCurrent.FrameCount
62+
animFrameNum := animCurrent.KeyframeCount
6363

64-
rl.UpdateModelAnimation(model, anims[0], int32(animFrameCount))
64+
rl.UpdateModelAnimation(model, anims[0], float32(animFrameCount))
6565
if animFrameCount >= int(animFrameNum) {
6666
animFrameCount = 0
6767
}
@@ -73,7 +73,7 @@ func main() {
7373

7474
rl.DrawModelEx(model, position, rl.NewVector3(1, 0, 0), -90, rl.NewVector3(1, 1, 1), rl.White)
7575
// Draw translation cubes
76-
for i := int32(0); i < model.BoneCount; i++ {
76+
for i := int32(0); i < model.Skeleton.BoneCount; i++ {
7777
pose := anims[0].GetFramePose(animFrameCount, int(i))
7878
rl.DrawCube(pose.Translation, 0.2, 0.2, 0.2, rl.Red)
7979
}

examples/models/gltf_loading/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ func main() {
4949
}
5050

5151
animPlaying := modelAnims[animIndex]
52-
animCurrentFrame = (animCurrentFrame + 1) % int(animPlaying.FrameCount)
53-
rl.UpdateModelAnimation(model, animPlaying, int32(animCurrentFrame))
52+
animCurrentFrame = (animCurrentFrame + 1) % int(animPlaying.KeyframeCount)
53+
rl.UpdateModelAnimation(model, animPlaying, float32(animCurrentFrame))
5454

5555
rl.BeginDrawing()
5656

Lines changed: 66 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/*******************************************************************************************
22
*
3-
* raylib [models] example - Load models M3D
3+
* raylib [models] example - loading m3d
4+
*
5+
* Example complexity rating: [★★☆☆] 2/4
46
*
57
* Example originally created with raylib 4.5, last time updated with raylib 4.5
68
*
@@ -13,143 +15,109 @@
1315
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
1416
* BSD-like license that allows static linking with closed source software
1517
*
16-
* Copyright (c) 2022-2024 bzt (@bztsrc)
18+
* Copyright (c) 2022-2025 bzt (@bztsrc)
1719
*
1820
********************************************************************************************/
21+
1922
package main
2023

2124
import (
22-
rl "github.com/gen2brain/raylib-go/raylib"
23-
)
25+
"fmt"
2426

25-
const (
26-
screenWidth = 800
27-
screenHeight = 450
27+
rl "github.com/gen2brain/raylib-go/raylib"
2828
)
2929

30+
// ------------------------------------------------------------------------------------
31+
// Program main entry point
32+
// ------------------------------------------------------------------------------------
3033
func main() {
3134
// Initialization
32-
rl.InitWindow(screenWidth, screenHeight, "raylib [models] example - M3D model loading")
35+
//--------------------------------------------------------------------------------------
36+
const screenWidth, screenHeight = 800, 450
3337

34-
// Define the camera to look into our 3d world
35-
camera := rl.Camera{
36-
Position: rl.NewVector3(1.5, 1.5, 1.5),
37-
Target: rl.NewVector3(0.0, 0.4, 0.0),
38-
Up: rl.NewVector3(0.0, 1.0, 0.0),
39-
Fovy: 45.0,
40-
Projection: rl.CameraPerspective,
41-
}
42-
43-
position := rl.NewVector3(0.0, 0.0, 0.0)
38+
rl.InitWindow(screenWidth, screenHeight, "raylib [models] example - loading m3d")
39+
defer rl.CloseWindow() // Close window and OpenGL context
4440

45-
modelFileName := "cesium_man.m3d"
46-
drawMesh := true
47-
drawSkeleton := true
48-
animPlaying := false // Store anim state, what to draw
41+
// Define the camera to look into our 3d world
42+
var camera rl.Camera
43+
camera.Position = rl.Vector3{X: 1.5, Y: 1.5, Z: 1.5} // Camera position
44+
camera.Target.Y = 0.4 // Camera looking at point
45+
camera.Up.Y = 1 // Camera up vector (rotation towards target)
46+
camera.Fovy = 45 // Camera field-of-view Y
47+
camera.Projection = rl.CameraPerspective // Camera projection type
4948

5049
// Load model
51-
model := rl.LoadModel(modelFileName)
50+
model := rl.LoadModel("cesium_man.m3d") // Load the animated model mesh and basic data
51+
defer rl.UnloadModel(model) // Unload model
52+
var position rl.Vector3 // Set model position
5253

53-
// Load animations
54+
anims := rl.LoadModelAnimations("cesium_man.m3d") // Load animation data
55+
defer rl.UnloadModelAnimations(anims) // Unload model animations data
56+
animCount := uint32(len(anims))
5457

55-
animFrameCounter := 0
56-
animID := 0
57-
anims := rl.LoadModelAnimations(modelFileName)
58-
animsCount := int32(len(anims))
58+
// Animation playing variables
59+
var animIndex uint32 // Current animation playing
60+
var animCurrentFrame float32 // Current animation frame (supporting interpolated frames)
5961

60-
rl.DisableCursor()
61-
rl.SetTargetFPS(60)
62+
rl.SetTargetFPS(60) // Set our game to run at 60 frames-per-second
63+
//--------------------------------------------------------------------------------------
6264

6365
// Main game loop
64-
for !rl.WindowShouldClose() {
66+
for !rl.WindowShouldClose() { // Detect window close button or ESC key
6567
// Update
66-
rl.UpdateCamera(&camera, rl.CameraFirstPerson)
67-
68-
if animsCount > 0 {
69-
// Play animation when space bar is held down (or step one frame with N)
70-
if rl.IsKeyDown(rl.KeySpace) || rl.IsKeyPressed(rl.KeyN) {
71-
animFrameCounter++
72-
if animFrameCounter >= int(anims[animID].FrameCount) {
73-
animFrameCounter = 0
74-
}
75-
rl.UpdateModelAnimation(model, anims[animID], int32(animFrameCounter))
76-
animPlaying = true
77-
}
78-
79-
// Select animation by pressing C
80-
if rl.IsKeyPressed(rl.KeyC) {
81-
animFrameCounter = 0
82-
animID++
83-
if animID >= int(animsCount) {
84-
animID = 0
85-
}
86-
rl.UpdateModelAnimation(model, anims[animID], 0)
87-
animPlaying = true
88-
}
68+
//----------------------------------------------------------------------------------
69+
rl.UpdateCamera(&camera, rl.CameraOrbital)
70+
71+
// Select current animation
72+
if rl.IsKeyPressed(rl.KeyRight) {
73+
animIndex = (animIndex + 1) % animCount
74+
} else if rl.IsKeyPressed(rl.KeyLeft) {
75+
animIndex = (animIndex + animCount - 1) % animCount
8976
}
9077

91-
// Toggle skeleton drawing
92-
if rl.IsKeyPressed(rl.KeyB) {
93-
drawSkeleton = !drawSkeleton
94-
}
95-
96-
// Toggle mesh drawing
97-
if rl.IsKeyPressed(rl.KeyM) {
98-
drawMesh = !drawMesh
78+
// Update model animation
79+
animCurrentFrame += 1
80+
if animCurrentFrame >= float32(anims[animIndex].KeyframeCount) {
81+
animCurrentFrame = 0
9982
}
83+
rl.UpdateModelAnimation(model, anims[animIndex], animCurrentFrame)
84+
//----------------------------------------------------------------------------------
10085

10186
// Draw
87+
//----------------------------------------------------------------------------------
10288
rl.BeginDrawing()
10389

10490
rl.ClearBackground(rl.RayWhite)
10591

10692
rl.BeginMode3D(camera)
10793

10894
// Draw 3d model with texture
109-
if drawMesh {
110-
rl.DrawModel(model, position, 1.0, rl.White)
111-
}
112-
113-
// Draw the animated skeleton
114-
if drawSkeleton {
115-
modelBones := model.GetBones()
116-
modelPoses := model.GetBindPose()
117-
anim := anims[animID]
118-
animBones := anim.GetBones()
119-
for bone := 0; bone < int(model.BoneCount)-1; bone++ {
120-
if !animPlaying || animsCount == 0 {
121-
// Display the bind-pose skeleton
122-
rl.DrawCube(modelPoses[bone].Translation, 0.04, 0.04, 0.04, rl.Red)
123-
if modelBones[bone].Parent >= 0 {
124-
rl.DrawLine3D(modelPoses[bone].Translation, modelPoses[modelBones[bone].Parent].Translation, rl.Red)
125-
}
126-
} else {
127-
// // Display the frame-pose skeleton
128-
pos := anim.GetFramePose(animFrameCounter, bone).Translation
129-
rl.DrawCube(pos, 0.05, 0.05, 0.05, rl.Red)
130-
if animBones[bone].Parent >= 0 {
131-
endPos := anim.GetFramePose(animFrameCounter, int(animBones[bone].Parent)).Translation
132-
rl.DrawLine3D(pos, endPos, rl.Red)
133-
}
95+
if !rl.IsKeyDown(rl.KeySpace) {
96+
rl.DrawModel(model, position, 1, rl.White)
97+
} else {
98+
// Draw the animated skeleton
99+
100+
// Loop to (boneCount - 1) because the last one is a special "no bone" bone,
101+
// needed to workaround buggy models without a -1, a cube is always drawn at the origin
102+
for i := 0; i < int(model.Skeleton.BoneCount)-1; i++ {
103+
framePose := anims[animIndex].GetFramePose(int(animCurrentFrame), i).Translation
104+
// Display the frame-pose skeleton
105+
rl.DrawCube(framePose, 0.05, 0.05, 0.05, rl.Red)
106+
if model.Skeleton.GetBones()[i].Parent >= 0 {
107+
rl.DrawLine3D(framePose, anims[animIndex].GetFramePose(int(animCurrentFrame), int(model.Skeleton.GetBones()[i].Parent)).Translation, rl.Red)
134108
}
135109
}
136110
}
137111

138-
rl.DrawGrid(10, 1.0)
112+
rl.DrawGrid(10, 1)
139113

140114
rl.EndMode3D()
141115

142-
rl.DrawText("PRESS SPACE to PLAY MODEL ANIMATION", 10, screenHeight-80, 10, rl.Maroon)
143-
rl.DrawText("PRESS N to STEP ONE ANIMATION FRAME", 10, screenHeight-60, 10, rl.DarkGray)
144-
rl.DrawText("PRESS C to CYCLE THROUGH ANIMATIONS", 10, screenHeight-40, 10, rl.DarkGray)
145-
rl.DrawText("PRESS M to toggle MESH, B to toggle SKELETON DRAWING", 10, screenHeight-20, 10, rl.DarkGray)
146-
rl.DrawText("(c) CesiumMan model by KhronosGroup", screenWidth-210, screenHeight-20, 10, rl.Gray)
116+
rl.DrawText(fmt.Sprintf("Current animation: %s", anims[animIndex].GetName()), 10, 10, 20, rl.LightGray)
117+
rl.DrawText("Press SPACE to draw skeleton", 10, 40, 20, rl.Maroon)
118+
rl.DrawText("(c) CesiumMan model by KhronosGroup", int32(rl.GetScreenWidth()-210), int32(rl.GetScreenHeight()-20), 10, rl.Gray)
147119

148120
rl.EndDrawing()
121+
//----------------------------------------------------------------------------------
149122
}
150-
151-
// De-Initialization
152-
rl.UnloadModelAnimations(anims)
153-
rl.UnloadModel(model)
154-
rl.CloseWindow()
155123
}

examples/others/rlgl_instanced_quads/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ func main() {
141141
// -----------------------------------------------------------------
142142
// Custom shader
143143
// -----------------------------------------------------------------
144-
shaderID := rl.LoadShaderCode(vertexShaderCode, fragmentShaderCode)
144+
shaderID := rl.LoadShaderProgram(vertexShaderCode, fragmentShaderCode)
145145
defer rl.UnloadShaderProgram(shaderID)
146146
mvpLoc := rl.GetLocationUniform(shaderID, "mvp")
147147

examples/shaders/shapes_textures/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package main
22

33
import (
4-
"github.com/gen2brain/raylib-go/raylib"
4+
rl "github.com/gen2brain/raylib-go/raylib"
55
)
66

77
func main() {
@@ -27,7 +27,7 @@ func main() {
2727
rl.DrawText("USING DEFAULT SHADER", 20, 40, 10, rl.Red)
2828

2929
rl.DrawCircle(80, 120, 35, rl.DarkBlue)
30-
rl.DrawCircleGradient(80, 220, 60, rl.Green, rl.SkyBlue)
30+
rl.DrawCircleGradient(rl.Vector2{X: 80, Y: 220}, 60, rl.Green, rl.SkyBlue)
3131
rl.DrawCircleLines(80, 340, 80, rl.DarkBlue)
3232

3333
// Activate our custom shader to be applied on next shapes/textures drawings

examples/shapes/basic_shapes/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package main
22

33
import (
4-
"github.com/gen2brain/raylib-go/raylib"
4+
rl "github.com/gen2brain/raylib-go/raylib"
55
)
66

77
func main() {
@@ -21,7 +21,7 @@ func main() {
2121
rl.DrawLine(18, 42, screenWidth-18, 42, rl.Black)
2222

2323
rl.DrawCircle(screenWidth/4, 120, 35, rl.DarkBlue)
24-
rl.DrawCircleGradient(screenWidth/4, 220, 60, rl.Green, rl.SkyBlue)
24+
rl.DrawCircleGradient(rl.Vector2{X: float32(screenWidth / 4), Y: 220}, 60, rl.Green, rl.SkyBlue)
2525
rl.DrawCircleLines(screenWidth/4, 340, 80, rl.DarkBlue)
2626

2727
rl.DrawRectangle(screenWidth/4*2-60, 100, 120, 60, rl.Red)

raylib/cgo_linux.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ GLFWbool _glfwConnectNull(int platformID, _GLFWplatform* platform) {
4141
#cgo linux CFLAGS: -Iexternal/glfw/include -DPLATFORM_DESKTOP -Wno-stringop-overflow
4242
#cgo linux LDFLAGS: -lm -pthread -ldl -lrt -lxkbcommon
4343
#cgo linux,!x11 LDFLAGS: -lwayland-client -lwayland-cursor -lwayland-egl
44+
#cgo linux,!wayland LDFLAGS: -lX11
4445
4546
#cgo linux,x11 CFLAGS: -D_GLFW_X11
4647
#cgo linux,wayland CFLAGS: -D_GLFW_WAYLAND

0 commit comments

Comments
 (0)