updated gogl backend to work on ios as well, updated ios example

This commit is contained in:
Thomas Friedel 2019-02-24 16:30:17 +01:00
parent 654d9b1796
commit f8aa4d62ce
5 changed files with 19 additions and 10 deletions

View file

@ -16,7 +16,7 @@
// //
package gl package gl
// #cgo darwin LDFLAGS: -framework OpenGL // #cgo darwin LDFLAGS: -framework OpenGLES
// #cgo linux,!android LDFLAGS: -lGL // #cgo linux,!android LDFLAGS: -lGL
// #cgo freebsd,!android LDFLAGS: -lGL // #cgo freebsd,!android LDFLAGS: -lGL
// #cgo windows LDFLAGS: -lopengl32 // #cgo windows LDFLAGS: -lopengl32
@ -49,7 +49,7 @@ package gl
// typedef float GLfloat; // typedef float GLfloat;
// typedef double GLdouble; // typedef double GLdouble;
// typedef char GLchar; // typedef char GLchar;
// #include <KHR/khrplatform.h> // #include "khrplatform.h"
// typedef unsigned int GLenum; // typedef unsigned int GLenum;
// typedef unsigned char GLboolean; // typedef unsigned char GLboolean;
// typedef unsigned int GLbitfield; // typedef unsigned int GLbitfield;

View file

@ -1,4 +1,4 @@
// +build !android // +build !android,!ios
// Code generated by glow (https://github.com/go-gl/glow). DO NOT EDIT. // Code generated by glow (https://github.com/go-gl/glow). DO NOT EDIT.
// This file implements GlowGetProcAddress for every supported platform. The // This file implements GlowGetProcAddress for every supported platform. The

View file

@ -1,3 +1,5 @@
// +build android ios
// Code generated by glow (https://github.com/go-gl/glow). DO NOT EDIT. // Code generated by glow (https://github.com/go-gl/glow). DO NOT EDIT.
// This file implements GlowGetProcAddress for every supported platform. The // This file implements GlowGetProcAddress for every supported platform. The
@ -17,7 +19,14 @@ package gl
/* /*
#cgo android LDFLAGS: -lGLESv2 #cgo android LDFLAGS: -lGLESv2
#include <GLES2/gl2.h> #cgo android CFLAGS: -DANDROID
#cgo ios CFLAGS: -DIOS
#ifdef ANDROID
#include <GLES2/gl2.h>
#endif
#ifdef IOS
#include <OpenGLES/ES2/GL.h>
#endif
*/ */
import "C" import "C"
import "unsafe" import "unsafe"

View file

@ -1,5 +1,7 @@
As of this writing, gomobile does not support go modules. In this case this project can only be compiled while it is in the GOPATH/src directory.
Run this command: Run this command:
gomobile bind -target ios gomobile bind -target ios -tags ios
Then add the resulting Example.framework into the Xcode project, and it should compile and run from there Then add the resulting Example.framework into the Xcode project, and it should compile and run from there

View file

@ -2,10 +2,9 @@ package example
import ( import (
"math" "math"
"time"
"github.com/tfriedel6/canvas" "github.com/tfriedel6/canvas"
"github.com/tfriedel6/canvas/glimpl/ios" "github.com/tfriedel6/canvas/backend/gogl"
) )
var cv *canvas.Canvas var cv *canvas.Canvas
@ -16,12 +15,11 @@ func TouchEvent(typ string, x, y int) {
} }
func LoadGL(w, h int) { func LoadGL(w, h int) {
err := canvas.LoadGL(glimplios.GLImpl{}) backend, err := goglbackend.New(0, 0, w, h)
if err != nil { if err != nil {
time.Sleep(100 * time.Millisecond)
panic(err) panic(err)
} }
cv = canvas.New(0, 0, w, h) cv = canvas.New(backend)
} }
func DrawFrame() { func DrawFrame() {