2
0
mirror of synced 2025-02-21 14:08:14 +00:00

sprite: Use gl.Context instead of package-level OpenGL calls.

The package-level OpenGL calls in golang.org/x/mobile/gl were removed.
This change fixes the example sprite app to use their replacement.

Change-Id: I1884e9292133375194c963e71540acaef0908d66
Reviewed-on: https://go-review.googlesource.com/15051
Reviewed-by: David Crawshaw <crawshaw@golang.org>
This commit is contained in:
Paul Hankin 2015-09-26 12:29:15 +09:00 committed by David Crawshaw
parent 159023b619
commit 80ead7f4f8

View File

@ -60,6 +60,7 @@ var (
func main() { func main() {
app.Main(func(a app.App) { app.Main(func(a app.App) {
var glctx gl.Context
visible, sz := false, size.Event{} visible, sz := false, size.Event{}
for e := range a.Events() { for e := range a.Events() {
switch e := a.Filter(e).(type) { switch e := a.Filter(e).(type) {
@ -67,15 +68,18 @@ func main() {
switch e.Crosses(lifecycle.StageVisible) { switch e.Crosses(lifecycle.StageVisible) {
case lifecycle.CrossOn: case lifecycle.CrossOn:
visible = true visible = true
glctx, _ = e.DrawContext.(gl.Context)
onStart(glctx)
case lifecycle.CrossOff: case lifecycle.CrossOff:
visible = false visible = false
onStop()
} }
case size.Event: case size.Event:
sz = e sz = e
case paint.Event: case paint.Event:
onPaint(sz)
a.Publish()
if visible { if visible {
onPaint(glctx, sz)
a.Publish()
// Keep animating. // Keep animating.
a.Send(paint.Event{}) a.Send(paint.Event{})
} }
@ -84,15 +88,22 @@ func main() {
}) })
} }
func onPaint(sz size.Event) { func onStart(glctx gl.Context) {
if scene == nil { images = glutil.NewImages(glctx)
images = glutil.NewImages() fps = debug.NewFPS(images)
fps = debug.NewFPS(images) eng = glsprite.Engine(images)
eng = glsprite.Engine(images) loadScene()
loadScene() }
}
gl.ClearColor(1, 1, 1, 1) func onStop() {
gl.Clear(gl.COLOR_BUFFER_BIT) eng.Release()
fps.Release()
images.Release()
}
func onPaint(glctx gl.Context, sz size.Event) {
glctx.ClearColor(1, 1, 1, 1)
glctx.Clear(gl.COLOR_BUFFER_BIT)
now := clock.Time(time.Since(startTime) * 60 / time.Second) now := clock.Time(time.Since(startTime) * 60 / time.Second)
eng.Render(scene, now, sz) eng.Render(scene, now, sz)
fps.Draw(sz) fps.Draw(sz)