Android example can now be built on desktop
This commit is contained in:
parent
56debbf236
commit
e365f75e34
5 changed files with 43 additions and 15 deletions
|
@ -2,6 +2,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
"runtime"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
"github.com/gen2brain/raylib-go/raylib"
|
"github.com/gen2brain/raylib-go/raylib"
|
||||||
|
@ -24,7 +25,11 @@ func run(app unsafe.Pointer) {
|
||||||
|
|
||||||
raylib.SetConfigFlags(raylib.FlagVsyncHint)
|
raylib.SetConfigFlags(raylib.FlagVsyncHint)
|
||||||
|
|
||||||
raylib.InitWindow(screenWidth, screenHeight, app)
|
if runtime.GOOS != "android" {
|
||||||
|
raylib.InitWindow(screenWidth, screenHeight, "Android example")
|
||||||
|
} else {
|
||||||
|
raylib.InitWindow(screenWidth, screenHeight, app)
|
||||||
|
}
|
||||||
|
|
||||||
raylib.InitAudioDevice()
|
raylib.InitAudioDevice()
|
||||||
|
|
||||||
|
@ -44,7 +49,7 @@ func run(app unsafe.Pointer) {
|
||||||
for !windowShouldClose {
|
for !windowShouldClose {
|
||||||
raylib.UpdateMusicStream(ambient)
|
raylib.UpdateMusicStream(ambient)
|
||||||
|
|
||||||
if raylib.IsKeyDown(raylib.KeyBack) {
|
if runtime.GOOS == "android" && raylib.IsKeyDown(raylib.KeyBack) || raylib.WindowShouldClose() {
|
||||||
windowShouldClose = true
|
windowShouldClose = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,4 +127,5 @@ func run(app unsafe.Pointer) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
run(nil)
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,6 @@ void android_main(struct android_app *app) {
|
||||||
|
|
||||||
void init_asset_manager(void *state) {
|
void init_asset_manager(void *state) {
|
||||||
struct android_app *app;
|
struct android_app *app;
|
||||||
app = (struct android_app *)state;
|
app = (struct android_app *)state;
|
||||||
asset_manager = app->activity->assetManager;
|
asset_manager = app->activity->assetManager;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,11 +23,15 @@ import (
|
||||||
var callbackHolder func(unsafe.Pointer)
|
var callbackHolder func(unsafe.Pointer)
|
||||||
|
|
||||||
// Initialize Window and OpenGL Graphics
|
// Initialize Window and OpenGL Graphics
|
||||||
func InitWindow(width int32, height int32, app unsafe.Pointer) {
|
func InitWindow(width int32, height int32, t interface{}) {
|
||||||
cwidth := (C.int)(width)
|
cwidth := (C.int)(width)
|
||||||
cheight := (C.int)(height)
|
cheight := (C.int)(height)
|
||||||
C.InitWindow(cwidth, cheight, app)
|
|
||||||
C.init_asset_manager(app)
|
app, ok := t.(unsafe.Pointer)
|
||||||
|
if ok {
|
||||||
|
C.InitWindow(cwidth, cheight, app)
|
||||||
|
C.init_asset_manager(app)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sets callback function
|
// Sets callback function
|
||||||
|
|
|
@ -10,12 +10,21 @@ import "C"
|
||||||
import "unsafe"
|
import "unsafe"
|
||||||
|
|
||||||
// Initialize Window and OpenGL Graphics
|
// Initialize Window and OpenGL Graphics
|
||||||
func InitWindow(width int32, height int32, title string) {
|
func InitWindow(width int32, height int32, t interface{}) {
|
||||||
cwidth := (C.int)(width)
|
cwidth := (C.int)(width)
|
||||||
cheight := (C.int)(height)
|
cheight := (C.int)(height)
|
||||||
ctitle := C.CString(title)
|
|
||||||
defer C.free(unsafe.Pointer(ctitle))
|
title, ok := t.(string)
|
||||||
C.InitWindow(cwidth, cheight, ctitle)
|
if ok {
|
||||||
|
ctitle := C.CString(title)
|
||||||
|
defer C.free(unsafe.Pointer(ctitle))
|
||||||
|
C.InitWindow(cwidth, cheight, ctitle)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sets callback function
|
||||||
|
func SetCallbackFunc(func(unsafe.Pointer)) {
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shows cursor
|
// Shows cursor
|
||||||
|
|
|
@ -15,12 +15,21 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// Initialize Window and OpenGL Graphics
|
// Initialize Window and OpenGL Graphics
|
||||||
func InitWindow(width int32, height int32, title string) {
|
func InitWindow(width int32, height int32, t interface{}) {
|
||||||
cwidth := (C.int)(width)
|
cwidth := (C.int)(width)
|
||||||
cheight := (C.int)(height)
|
cheight := (C.int)(height)
|
||||||
ctitle := C.CString(title)
|
|
||||||
defer C.free(unsafe.Pointer(ctitle))
|
title, ok := t.(string)
|
||||||
C.InitWindow(cwidth, cheight, ctitle)
|
if ok {
|
||||||
|
ctitle := C.CString(title)
|
||||||
|
defer C.free(unsafe.Pointer(ctitle))
|
||||||
|
C.InitWindow(cwidth, cheight, ctitle)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sets callback function
|
||||||
|
func SetCallbackFunc(func(unsafe.Pointer)) {
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shows cursor
|
// Shows cursor
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue