Merge pull request #308 from JupiterRider/master
First approach for purego
This commit is contained in:
commit
8c380e0735
5 changed files with 3848 additions and 4 deletions
21
README.md
21
README.md
|
@ -9,17 +9,19 @@ Golang bindings for [raylib](http://www.raylib.com/), a simple and easy-to-use l
|
|||
|
||||
raylib C source code is included and compiled together with bindings. Note that the first build can take a few minutes.
|
||||
|
||||
It is also possible to use raylib-go without cgo (Windows only; see requirements below).
|
||||
|
||||
### Requirements
|
||||
|
||||
##### Ubuntu
|
||||
|
||||
###### X11
|
||||
|
||||
apt-get install libgl1-mesa-dev libxi-dev libxcursor-dev libxrandr-dev libxinerama-dev
|
||||
apt-get install libgl1-mesa-dev libxi-dev libxcursor-dev libxrandr-dev libxinerama-dev
|
||||
|
||||
###### Wayland
|
||||
###### Wayland
|
||||
|
||||
apt-get install libgl1-mesa-dev libwayland-dev libxkbcommon-dev
|
||||
apt-get install libgl1-mesa-dev libwayland-dev libxkbcommon-dev
|
||||
|
||||
##### Fedora
|
||||
|
||||
|
@ -27,7 +29,7 @@ raylib C source code is included and compiled together with bindings. Note that
|
|||
|
||||
dnf install mesa-libGL-devel libXi-devel libXcursor-devel libXrandr-devel libXinerama-devel
|
||||
|
||||
###### Wayland
|
||||
###### Wayland
|
||||
|
||||
dnf install mesa-libGL-devel wayland-devel libxkbcommon-devel
|
||||
|
||||
|
@ -37,6 +39,17 @@ On macOS you need Xcode or Command Line Tools for Xcode.
|
|||
|
||||
##### Windows
|
||||
|
||||
###### purego (without cgo)
|
||||
|
||||
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`.
|
||||
Put the raylib.dll into the root folder of your project or copy it into `C:\Windows\System32` for a system-wide installation.
|
||||
|
||||
As of November 15, 2023, raylib 5.0 is the required version.
|
||||
|
||||
It is also possible build the dll yourself. You can find more infos at [raylib's wiki](https://github.com/raysan5/raylib/wiki/Working-on-Windows).
|
||||
|
||||
###### cgo
|
||||
|
||||
On Windows you need C compiler, like [Mingw-w64](https://mingw-w64.org) or [TDM-GCC](http://tdm-gcc.tdragon.net/).
|
||||
You can also build binary in [MSYS2](https://msys2.github.io/) shell.
|
||||
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
module github.com/gen2brain/raylib-go/raylib
|
||||
|
||||
go 1.21
|
||||
|
||||
require (
|
||||
github.com/ebitengine/purego v0.5.0
|
||||
golang.org/x/sys v0.14.0
|
||||
)
|
||||
|
|
4
raylib/go.sum
Normal file
4
raylib/go.sum
Normal file
|
@ -0,0 +1,4 @@
|
|||
github.com/ebitengine/purego v0.5.0 h1:JrMGKfRIAM4/QVKaesIIT7m/UVjTj5GYhRSQYwfVdpo=
|
||||
github.com/ebitengine/purego v0.5.0/go.mod h1:ah1In8AOtksoNK6yk5z1HTJeUkC1Ez4Wk2idgGslMwQ=
|
||||
golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
|
||||
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
44
raylib/purego_windows.go
Normal file
44
raylib/purego_windows.go
Normal file
|
@ -0,0 +1,44 @@
|
|||
//go:build !cgo && windows
|
||||
// +build !cgo,windows
|
||||
|
||||
package rl
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"unsafe"
|
||||
|
||||
"github.com/ebitengine/purego"
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
const (
|
||||
libname = "raylib.dll"
|
||||
requiredVersion = "5.0"
|
||||
)
|
||||
|
||||
// loadLibrary loads the raylib dll and panics on error
|
||||
func loadLibrary() uintptr {
|
||||
handle, err := windows.LoadLibrary(libname)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot load library %s: %w", libname, err))
|
||||
}
|
||||
|
||||
proc, err := windows.GetProcAddress(handle, "raylib_version")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
version := windows.BytePtrToString(**(***byte)(unsafe.Pointer(&proc)))
|
||||
if version != requiredVersion {
|
||||
panic(fmt.Errorf("version %s of %s doesn't match the required version %s", version, libname, requiredVersion))
|
||||
}
|
||||
|
||||
return uintptr(handle)
|
||||
}
|
||||
|
||||
func traceLogCallbackWrapper(fn TraceLogCallbackFun) uintptr {
|
||||
return purego.NewCallback(func(logLevel int32, text *byte) uintptr {
|
||||
fn(int(logLevel), windows.BytePtrToString(text))
|
||||
return 0
|
||||
})
|
||||
}
|
3778
raylib/raylib_purego.go
Normal file
3778
raylib/raylib_purego.go
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue