Add SDL backend

This commit is contained in:
Milan Nikolic 2023-11-04 13:08:38 +01:00
parent 15fba7e9ac
commit af9daf8452
No known key found for this signature in database
GPG key ID: 9229D0EAA3AA4E75
24 changed files with 6485 additions and 89 deletions

View file

@ -42,19 +42,15 @@ You can also build binary in [MSYS2](https://msys2.github.io/) shell.
[Android example](https://github.com/gen2brain/raylib-go/tree/master/examples/others/android/example).
##### Raspberry Pi
[RPi example](https://github.com/gen2brain/raylib-go/tree/master/examples/others/rpi/basic_window).
### Installation
go get -v -u github.com/gen2brain/raylib-go/raylib
### Build tags
* `drm` - build for Linux native mode, including Raspberry Pi 4 and other devices (PLATFORM_DRM)
* `rpi` - build for Raspberry Pi platform (PLATFORM_RPI)
* `wayland` - build against Wayland libraries
* `drm` - build for Linux native DRM mode, including Raspberry Pi 4 and other devices (PLATFORM_DRM)
* `sdl` - build for SDL backend instead of internal GLFW (PLATFORM_DESKTOP_SDL)
* `wayland` - build against Wayland libraries (internal GLFW)
* `noaudio` - disables audio functions
* `opengl43` - uses OpenGL 4.3 backend
* `opengl21` - uses OpenGL 2.1 backend (default is 3.3 on desktop)
@ -75,6 +71,7 @@ import rl "github.com/gen2brain/raylib-go/raylib"
func main() {
rl.InitWindow(800, 450, "raylib [core] example - basic window")
defer rl.CloseWindow()
rl.SetTargetFPS(60)
for !rl.WindowShouldClose() {

View file

@ -1,18 +0,0 @@
### Raspberry Pi example
To cross compile example for Raspberry Pi you will need [RPi toolchain](https://github.com/raspberrypi/tools/tree/master/arm-bcm2708) and [userspace libraries](https://github.com/raspberrypi/firmware) (opt/vc).
Export path to RPi toolchain:
export RPI_HOME=/opt/tools/arm-bcm2708/arm-linux-gnueabihf
Add toolchain bin directory to PATH:
export PATH=${RPI_HOME}/bin:${PATH}
And compile example:
CC=arm-linux-gnueabihf-gcc \
CGO_CFLAGS="-I/opt/vc/include -I/opt/vc/include/interface/vcos -I/opt/vc/include/interface/vmcs_host/linux -I/opt/vc/include/interface/vcos/pthreads --sysroot=${RPI_HOME}/arm-linux-gnueabihf/sysroot" \
CGO_LDFLAGS="-L/opt/vc/lib -L/opt/vc/lib64 --sysroot=${RPI_HOME}/arm-linux-gnueabihf/sysroot" \
CGO_ENABLED=1 GOOS=linux GOARCH=arm go build

View file

@ -1,21 +0,0 @@
package main
import "github.com/gen2brain/raylib-go/raylib"
func main() {
rl.InitWindow(800, 450, "raylib [rpi] 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()
}

View file

@ -1,5 +1,5 @@
//go:build darwin
// +build darwin
//go:build darwin && !sdl
// +build darwin,!sdl
package rl

19
raylib/cgo_darwin_sdl.go Normal file
View file

@ -0,0 +1,19 @@
//go:build darwin && sdl
// +build darwin,sdl
package rl
/*
#cgo darwin LDFLAGS: -framework Cocoa -framework IOKit -framework CoreVideo -framework CoreFoundation
#cgo darwin CFLAGS: -x objective-c -Wno-deprecated-declarations -Wno-implicit-const-int-float-conversion -DPLATFORM_DESKTOP_SDL
#cgo darwin pkg-config: sdl2
#cgo darwin,!angle LDFLAGS: -framework OpenGL
#cgo darwin,opengl11,!angle CFLAGS: -DGRAPHICS_API_OPENGL_11
#cgo darwin,opengl21,!angle CFLAGS: -DGRAPHICS_API_OPENGL_21
#cgo darwin,opengl43,!angle CFLAGS: -DGRAPHICS_API_OPENGL_43
#cgo darwin,!opengl11,!opengl21,!opengl43,!angle CFLAGS: -DGRAPHICS_API_OPENGL_33
#cgo darwin,angle CFLAGS: -DGRAPHICS_API_OPENGL_ES2
*/
import "C"

View file

@ -1,5 +1,5 @@
//go:build freebsd && !linux && !drm && !rpi && !android
// +build freebsd,!linux,!drm,!rpi,!android
//go:build freebsd && !linux && !drm && !sdl && !android
// +build freebsd,!linux,!drm,!sdl,!android
package rl

21
raylib/cgo_freebsd_sdl.go Normal file
View file

@ -0,0 +1,21 @@
//go:build freebsd && !linux && !drm && sdl && !android
// +build freebsd,!linux,!drm,sdl,!android
package rl
/*
#cgo freebsd CFLAGS: -I. -I/usr/local/include -DPLATFORM_DESKTOP_SDL
#cgo freebsd LDFLAGS: -L/usr/local/lib
#cgo freebsd LDFLAGS: -lm -pthread -ldl -lrt -lX11
#cgo freebsd pkg-config: sdl2
#cgo freebsd,!angle LDFLAGS: -lGL
#cgo freebsd,opengl11,!angle CFLAGS: -DGRAPHICS_API_OPENGL_11
#cgo freebsd,opengl21,!angle CFLAGS: -DGRAPHICS_API_OPENGL_21
#cgo freebsd,opengl43,!angle CFLAGS: -DGRAPHICS_API_OPENGL_43
#cgo freebsd,!opengl11,!opengl21,!opengl43,!angle CFLAGS: -DGRAPHICS_API_OPENGL_33
#cgo freebsd,angle CFLAGS: -DGRAPHICS_API_OPENGL_ES2
*/
import "C"

View file

@ -1,5 +1,5 @@
//go:build linux && !drm && !rpi && !android
// +build linux,!drm,!rpi,!android
//go:build linux && !drm && !sdl && !android
// +build linux,!drm,!sdl,!android
package rl

View file

@ -1,5 +1,5 @@
//go:build linux && drm && !rpi && !android
// +build linux,drm,!rpi,!android
//go:build linux && drm && !sdl && !android
// +build linux,drm,!sdl,!android
package rl

19
raylib/cgo_linux_sdl.go Normal file
View file

@ -0,0 +1,19 @@
//go:build linux && !drm && sdl && !android
// +build linux,!drm,sdl,!android
package rl
/*
#cgo linux CFLAGS: -DPLATFORM_DESKTOP_SDL -Wno-stringop-overflow
#cgo linux LDFLAGS: -lm -pthread -ldl -lrt -lX11
#cgo linux pkg-config: sdl2
#cgo linux,!angle LDFLAGS: -lGL
#cgo linux,opengl11,!angle CFLAGS: -DGRAPHICS_API_OPENGL_11
#cgo linux,opengl21,!angle CFLAGS: -DGRAPHICS_API_OPENGL_21
#cgo linux,opengl43,!angle CFLAGS: -DGRAPHICS_API_OPENGL_43
#cgo linux,!opengl11,!opengl21,!opengl43,!angle CFLAGS: -DGRAPHICS_API_OPENGL_33
#cgo linux,angle CFLAGS: -DGRAPHICS_API_OPENGL_ES2
*/
import "C"

View file

@ -1,5 +1,5 @@
//go:build openbsd && !linux && !drm && !rpi && !android
// +build openbsd,!linux,!drm,!rpi,!android
//go:build openbsd && !linux && !drm && !sdl && !android
// +build openbsd,!linux,!drm,!sdl,!android
package rl

21
raylib/cgo_openbsd_sdl.go Normal file
View file

@ -0,0 +1,21 @@
//go:build openbsd && !linux && !drm && sdl && !android
// +build openbsd,!linux,!drm,sdl,!android
package rl
/*
#cgo openbsd CFLAGS: -I. -I/usr/X11R6/include -DPLATFORM_DESKTOP_SDL
#cgo openbsd LDFLAGS: -L/usr/X11R6/lib
#cgo openbsd LDFLAGS: -lm -pthread -lX11
#cgo openbsd pkg-config: sdl2
#cgo openbsd,!angle LDFLAGS: -lGL
#cgo openbsd,opengl11,!angle CFLAGS: -DGRAPHICS_API_OPENGL_11
#cgo openbsd,opengl21,!angle CFLAGS: -DGRAPHICS_API_OPENGL_21
#cgo openbsd,opengl43,!angle CFLAGS: -DGRAPHICS_API_OPENGL_43
#cgo openbsd,!opengl11,!opengl21,!opengl43,!angle CFLAGS: -DGRAPHICS_API_OPENGL_33
#cgo openbsd,angle CFLAGS: -DGRAPHICS_API_OPENGL_ES2
*/
import "C"

View file

@ -1,5 +1,5 @@
//go:build windows
// +build windows
//go:build windows && !sdl
// +build windows,!sdl
package rl

18
raylib/cgo_windows_sdl.go Normal file
View file

@ -0,0 +1,18 @@
//go:build windows && sdl
// +build windows,sdl
package rl
/*
#cgo windows LDFLAGS: -lgdi32 -lwinmm -lole32 -lSDL2
#cgo windows CFLAGS: -Iexternal -DPLATFORM_DESKTOP_SDL
#cgo windows,!angle LDFLAGS: -lopengl32
#cgo windows,opengl11,!angle CFLAGS: -DGRAPHICS_API_OPENGL_11
#cgo windows,opengl21,!angle CFLAGS: -DGRAPHICS_API_OPENGL_21
#cgo windows,opengl43,!angle CFLAGS: -DGRAPHICS_API_OPENGL_43
#cgo windows,!opengl11,!opengl21,!opengl43,!angle CFLAGS: -DGRAPHICS_API_OPENGL_33
#cgo windows,angle CFLAGS: -DGRAPHICS_API_OPENGL_ES2
*/
import "C"

View file

@ -1,5 +1,5 @@
//go:build !rpi && !drm && !android
// +build !rpi,!drm,!android
//go:build !sdl && !drm && !android
// +build !sdl,!drm,!android
package rl

View file

@ -0,0 +1,98 @@
//go:build sdl && !drm && !android
// +build sdl,!drm,!android
package rl
/*
#include "raylib.h"
#include <stdlib.h>
*/
import "C"
import (
"os"
"unsafe"
)
// InitWindow - Initialize Window and OpenGL Graphics
func InitWindow(width int32, height int32, title string) {
cwidth := (C.int)(width)
cheight := (C.int)(height)
ctitle := C.CString(title)
defer C.free(unsafe.Pointer(ctitle))
C.InitWindow(cwidth, cheight, ctitle)
}
// SetCallbackFunc - Sets callback function
func SetCallbackFunc(func()) {
}
// ShowCursor - Shows cursor
func ShowCursor() {
C.ShowCursor()
}
// HideCursor - Hides cursor
func HideCursor() {
C.HideCursor()
}
// IsCursorHidden - Returns true if cursor is not visible
func IsCursorHidden() bool {
ret := C.IsCursorHidden()
v := bool(ret)
return v
}
// IsCursorOnScreen - Check if cursor is on the current screen.
func IsCursorOnScreen() bool {
ret := C.IsCursorOnScreen()
v := bool(ret)
return v
}
// EnableCursor - Enables cursor
func EnableCursor() {
C.EnableCursor()
}
// DisableCursor - Disables cursor
func DisableCursor() {
C.DisableCursor()
}
// IsFileDropped - Check if a file have been dropped into window
func IsFileDropped() bool {
ret := C.IsFileDropped()
v := bool(ret)
return v
}
// LoadDroppedFiles - Load dropped filepaths
func LoadDroppedFiles() []string {
ret := C.LoadDroppedFiles()
defer C.UnloadDroppedFiles(ret)
tmpslice := (*[1 << 24]*C.char)(unsafe.Pointer(ret.paths))[:ret.count:ret.count]
gostrings := make([]string, ret.count)
for i, s := range tmpslice {
gostrings[i] = C.GoString(s)
}
return gostrings
}
// UnloadDroppedFiles - Unload dropped filepaths
func UnloadDroppedFiles() {
}
// OpenAsset - Open asset
func OpenAsset(name string) (Asset, error) {
f, err := os.Open(name)
if err != nil {
return nil, err
}
return f, nil
}

View file

@ -1,5 +1,5 @@
//go:build linux && drm && !rpi && !android
// +build linux,drm,!rpi,!android
//go:build linux && drm && !sdl && !android
// +build linux,drm,!sdl,!android
package rl

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

1942
raylib/platforms/rcore_drm.c Normal file

File diff suppressed because it is too large Load diff

View file

@ -14,7 +14,7 @@ func SetGesturesEnabled(gestureFlags uint32) {
// IsGestureDetected - Check if a gesture have been detected
func IsGestureDetected(gesture Gestures) bool {
cgesture := (C.int)(gesture)
cgesture := (C.uint)(gesture)
ret := C.IsGestureDetected(cgesture)
v := bool(ret)
return v

View file

@ -438,7 +438,7 @@ func SetModelMeshMaterial(model *Model, meshId int32, materialId int32) {
func LoadModelAnimations(fileName string) []ModelAnimation {
cfileName := C.CString(fileName)
defer C.free(unsafe.Pointer(cfileName))
ccount := C.uint(0)
ccount := C.int(0)
ret := C.LoadModelAnimations(cfileName, &ccount)
v := (*[1 << 24]ModelAnimation)(unsafe.Pointer(ret))[:int(ccount)]
return v
@ -460,7 +460,7 @@ func UnloadModelAnimation(anim ModelAnimation) {
// UnloadModelAnimations - Unload animation array data
func UnloadModelAnimations(animations []ModelAnimation) {
C.UnloadModelAnimations((*C.ModelAnimation)(unsafe.Pointer(&animations[0])), (C.uint)(len(animations)))
C.UnloadModelAnimations((*C.ModelAnimation)(unsafe.Pointer(&animations[0])), (C.int)(len(animations)))
}
// IsModelAnimationValid - Check model animation skeleton match

View file

@ -575,30 +575,6 @@ func GenImageColor(width, height int, col color.RGBA) *Image {
return v
}
// GenImageGradientV - Generate image: vertical gradient
func GenImageGradientV(width, height int, top, bottom color.RGBA) *Image {
cwidth := (C.int)(width)
cheight := (C.int)(height)
ctop := colorCptr(top)
cbottom := colorCptr(bottom)
ret := C.GenImageGradientV(cwidth, cheight, *ctop, *cbottom)
v := newImageFromPointer(unsafe.Pointer(&ret))
return v
}
// GenImageGradientH - Generate image: horizontal gradient
func GenImageGradientH(width, height int, left, right color.RGBA) *Image {
cwidth := (C.int)(width)
cheight := (C.int)(height)
cleft := colorCptr(left)
cright := colorCptr(right)
ret := C.GenImageGradientH(cwidth, cheight, *cleft, *cright)
v := newImageFromPointer(unsafe.Pointer(&ret))
return v
}
// GenImageGradientRadial - Generate image: radial gradient
func GenImageGradientRadial(width, height int, density float32, inner, outer color.RGBA) *Image {
cwidth := (C.int)(width)