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 коммит произвёл David Crawshaw
Родитель 159023b619
Коммит 80ead7f4f8
1 изменённых файлов: 22 добавлений и 11 удалений

Просмотреть файл

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