Add RGFW backend

This commit is contained in:
Milan Nikolic 2024-05-08 10:30:05 +02:00
parent 1868520849
commit 7810550d63
No known key found for this signature in database
GPG key ID: 9229D0EAA3AA4E75
23 changed files with 8110 additions and 28 deletions

View file

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

19
raylib/cgo_darwin_rgfw.go Normal file
View file

@ -0,0 +1,19 @@
//go:build darwin && rgfw && !sdl
// +build darwin,rgfw,!sdl
package rl
/*
#cgo darwin LDFLAGS: -framework Foundation -framework AppKit -framework CoreVideo
#cgo darwin CFLAGS: -x objective-c -Wno-deprecated-declarations -Wno-implicit-const-int-float-conversion -DPLATFORM_DESKTOP_RGFW
#cgo darwin,!es2,!es3 LDFLAGS: -framework OpenGL
#cgo darwin,opengl11,!es2,!es3 CFLAGS: -DGRAPHICS_API_OPENGL_11
#cgo darwin,opengl21,!es2,!es3 CFLAGS: -DGRAPHICS_API_OPENGL_21
#cgo darwin,opengl43,!es2,!es3 CFLAGS: -DGRAPHICS_API_OPENGL_43
#cgo darwin,!opengl11,!opengl21,!opengl43,!es2,!es3 CFLAGS: -DGRAPHICS_API_OPENGL_33
#cgo darwin,es2,!es3 CFLAGS: -DGRAPHICS_API_OPENGL_ES2
#cgo darwin,es3,!es2 CFLAGS: -DGRAPHICS_API_OPENGL_ES3
*/
import "C"

View file

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

View file

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

View file

@ -0,0 +1,19 @@
//go:build freebsd && rgfw && !linux && !drm && !sdl && !android
// +build freebsd,rgfw,!linux,!drm,!sdl,!android
package rl
/*
#cgo freebsd CFLAGS: -I. -I/usr/local/include -DPLATFORM_DESKTOP_RGFW
#cgo freebsd LDFLAGS: -L/usr/local/lib -lX11 -lXrandr -lXinerama -lXi -lXxf86vm -lXcursor -lm -lpthread -ldl -lrt
#cgo freebsd,!es2,!es3 LDFLAGS: -lGL
#cgo freebsd,opengl11,!es2,!es3 CFLAGS: -DGRAPHICS_API_OPENGL_11
#cgo freebsd,opengl21,!es2,!es3 CFLAGS: -DGRAPHICS_API_OPENGL_21
#cgo freebsd,opengl43,!es2,!es3 CFLAGS: -DGRAPHICS_API_OPENGL_43
#cgo freebsd,!opengl11,!opengl21,!opengl43,!es2,!es3 CFLAGS: -DGRAPHICS_API_OPENGL_33
#cgo freebsd,es2,!es3 CFLAGS: -DGRAPHICS_API_OPENGL_ES2
#cgo freebsd,es3,!es2 CFLAGS: -DGRAPHICS_API_OPENGL_ES3
*/
import "C"

View file

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

View file

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

View file

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

20
raylib/cgo_linux_rgfw.go Normal file
View file

@ -0,0 +1,20 @@
//go:build linux && rgfw && !drm && !sdl && !android
// +build linux,rgfw,!drm,!sdl,!android
package rl
/*
#cgo linux,!es2 LDFLAGS: -lm
#cgo linux CFLAGS: -DPLATFORM_DESKTOP_RGFW -Wno-builtin-declaration-mismatch -Wno-discarded-qualifiers -Wno-int-conversion
#cgo linux LDFLAGS: -lX11 -lXrandr -lXinerama -lXi -lXxf86vm -lXcursor -lm -lpthread -ldl -lrt
#cgo linux,!es2,!es3 LDFLAGS: -lGL
#cgo linux,opengl11,!es2,!es3 CFLAGS: -DGRAPHICS_API_OPENGL_11
#cgo linux,opengl21,!es2,!es3 CFLAGS: -DGRAPHICS_API_OPENGL_21
#cgo linux,opengl43,!es2,!es3 CFLAGS: -DGRAPHICS_API_OPENGL_43
#cgo linux,!opengl11,!opengl21,!opengl43,!es2,!es3 CFLAGS: -DGRAPHICS_API_OPENGL_33
#cgo linux,es2,!es3 CFLAGS: -DGRAPHICS_API_OPENGL_ES2
#cgo linux,es3,!es2 CFLAGS: -DGRAPHICS_API_OPENGL_ES3
*/
import "C"

View file

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

View file

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

View file

@ -0,0 +1,19 @@
//go:build openbsd && rgfw && !linux && !sdl && !drm && !android
// +build openbsd,rgfw,!linux,!sdl,!drm,!android
package rl
/*
#cgo openbsd CFLAGS: -I. -I/usr/X11R6/include -DPLATFORM_DESKTOP_RGFW
#cgo openbsd LDFLAGS: -L/usr/X11R6/lib -lX11 -lXrandr -lXinerama -lXi -lXxf86vm -lXcursor -lm -lpthread -ldl -lrt
#cgo openbsd,!es2,!es3 LDFLAGS: -lGL
#cgo openbsd,opengl11,!es2,!es3 CFLAGS: -DGRAPHICS_API_OPENGL_11
#cgo openbsd,opengl21,!es2,!es3 CFLAGS: -DGRAPHICS_API_OPENGL_21
#cgo openbsd,opengl43,!es2,!es3 CFLAGS: -DGRAPHICS_API_OPENGL_43
#cgo openbsd,!opengl11,!opengl21,!opengl43,!es2,!es3 CFLAGS: -DGRAPHICS_API_OPENGL_33
#cgo openbsd,es2,!es3 CFLAGS: -DGRAPHICS_API_OPENGL_ES2
#cgo openbsd,es3,!es2 CFLAGS: -DGRAPHICS_API_OPENGL_ES3
*/
import "C"

View file

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

View file

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

View file

@ -0,0 +1,19 @@
//go:build windows && rgfw && !sdl
// +build windows,rgfw,!sdl
package rl
/*
#cgo windows LDFLAGS: -lgdi32 -lwinmm
#cgo windows CFLAGS: -Iexternal -DPLATFORM_DESKTOP_RGFW -Wno-stringop-overflow -Wno-discarded-qualifiers
#cgo windows,!es2,!es3 LDFLAGS: -lopengl32
#cgo windows,opengl11,!es2,!es3 CFLAGS: -DGRAPHICS_API_OPENGL_11
#cgo windows,opengl21,!es2,!es3 CFLAGS: -DGRAPHICS_API_OPENGL_21
#cgo windows,opengl43,!es2,!es3 CFLAGS: -DGRAPHICS_API_OPENGL_43
#cgo windows,!opengl11,!opengl21,!opengl43,!es2,!es3 CFLAGS: -DGRAPHICS_API_OPENGL_33
#cgo windows,es2,!es3 CFLAGS: -DGRAPHICS_API_OPENGL_ES2
#cgo windows,es3,!es2 CFLAGS: -DGRAPHICS_API_OPENGL_ES3
*/
import "C"

View file

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

6353
raylib/external/RGFW.h vendored Normal file

File diff suppressed because it is too large Load diff

View file

@ -116,6 +116,7 @@ func (a *asset) Read(p []byte) (n int, err error) {
if n == 0 && len(p) > 0 {
return 0, io.EOF
}
return n, nil
}
@ -124,11 +125,13 @@ func (a *asset) Seek(offset int64, whence int) (int64, error) {
if off == -1 {
return 0, fmt.Errorf("bad result for offset=%d, whence=%d", offset, whence)
}
return int64(off), nil
}
func (a *asset) Close() error {
C.AAsset_close(a.ptr)
return nil
}

View file

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

View file

@ -0,0 +1,102 @@
//go:build rgfw && !sdl && !drm && !android
// +build rgfw,!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 sdl && !drm && !android
// +build sdl,!drm,!android
//go:build sdl && !rgfw && !drm && !android
// +build sdl,!rgfw,!drm,!android
package rl
@ -43,6 +43,7 @@ func HideCursor() {
func IsCursorHidden() bool {
ret := C.IsCursorHidden()
v := bool(ret)
return v
}
@ -50,6 +51,7 @@ func IsCursorHidden() bool {
func IsCursorOnScreen() bool {
ret := C.IsCursorOnScreen()
v := bool(ret)
return v
}
@ -67,6 +69,7 @@ func DisableCursor() {
func IsFileDropped() bool {
ret := C.IsFileDropped()
v := bool(ret)
return v
}
@ -94,5 +97,6 @@ func OpenAsset(name string) (Asset, error) {
if err != nil {
return nil, err
}
return f, nil
}

View file

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

File diff suppressed because it is too large Load diff