From d4ef198c6d876fc7768765a52ce6cc0828f414d4 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Tue, 18 Jun 2013 01:26:46 +0900 Subject: [PATCH] Call game.Update --- examples/glut/main.go | 18 +++++++++++++++++- graphics/device.go | 1 - 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/examples/glut/main.go b/examples/glut/main.go index d82296a26..e1a8c359c 100644 --- a/examples/glut/main.go +++ b/examples/glut/main.go @@ -20,6 +20,7 @@ import "C" import ( "image/color" "os" + "time" "unsafe" "github.com/hajimehoshi/go-ebiten/graphics" ) @@ -33,7 +34,7 @@ func (game *DemoGame) Update() { } func (game *DemoGame) Draw(g *graphics.GraphicsContext, offscreen *graphics.Texture) { - g.Fill(&color.RGBA{R: 0, G: 0, B: 255, A: 255}) + g.Fill(&color.RGBA{R: 128, G: 128, B: 255, A: 255}) } //export display @@ -75,11 +76,26 @@ func main() { C.setDisplayFunc() C.setIdleFunc() + ch := make(chan bool, 1) game := &DemoGame{} device = graphics.NewDevice(screenWidth, screenHeight, screenScale, func(g *graphics.GraphicsContext, offscreen *graphics.Texture) { + ch<- true game.Draw(g, offscreen) + <-ch }) + go func() { + const frameTime = time.Second / 60 + lastTime := time.Now() + for { + ch<- true + game.Update() + <-ch + time.Sleep(frameTime - time.Since(lastTime)) + lastTime = time.Now() + } + }() + C.glutMainLoop() } diff --git a/graphics/device.go b/graphics/device.go index caaa78a26..47f9e38ab 100644 --- a/graphics/device.go +++ b/graphics/device.go @@ -35,7 +35,6 @@ func (device *Device) Update() { C.glTexParameteri(C.GL_TEXTURE_2D, C.GL_TEXTURE_MAG_FILTER, C.GL_NEAREST) g.SetOffscreen(device.offscreenTexture) g.Clear() - // TODO: lock this! device.drawFunc(g, device.offscreenTexture) g.flush()