From 0ab7dca5e41d3a245da83cc8d681f11047bb652e Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Wed, 19 Jun 2013 01:14:55 +0900 Subject: [PATCH] Refactoring --- examples/glut/main.go | 7 ++++++- graphics/graphics_context.go | 15 +++++++++++---- graphics/texture.go | 2 +- ui/ui.go | 5 ----- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/examples/glut/main.go b/examples/glut/main.go index 1c321f86e..9aaa7be84 100644 --- a/examples/glut/main.go +++ b/examples/glut/main.go @@ -92,6 +92,7 @@ func (ui *GlutUI) Run(device *graphics.Device) { type DemoGame struct { ebitenTexture *graphics.Texture + x int } func (game *DemoGame) Update() { @@ -109,6 +110,7 @@ func (game *DemoGame) Update() { game.ebitenTexture = currentUI.device.NewTextureFromImage(img) } + game.x++ } func (game *DemoGame) Draw(g *graphics.GraphicsContext, offscreen *graphics.Texture) { @@ -116,9 +118,12 @@ func (game *DemoGame) Draw(g *graphics.GraphicsContext, offscreen *graphics.Text if game.ebitenTexture == nil { return } + geometryMatrix := graphics.IdentityGeometryMatrix() + geometryMatrix.SetTx(graphics.AffineMatrixElement(game.x)) + geometryMatrix.SetTy(graphics.AffineMatrixElement(game.x)) g.DrawTexture(game.ebitenTexture, 0, 0, game.ebitenTexture.Width, game.ebitenTexture.Height, - graphics.IdentityGeometryMatrix(), + geometryMatrix, graphics.IdentityColorMatrix()) } diff --git a/graphics/graphics_context.go b/graphics/graphics_context.go index b6baaef3b..2185632d6 100644 --- a/graphics/graphics_context.go +++ b/graphics/graphics_context.go @@ -8,7 +8,6 @@ import "C" import ( "fmt" "image/color" - "math" "unsafe" ) @@ -110,10 +109,20 @@ func (context *GraphicsContext) DrawTexture(texture *Texture, C.glDisableClientState(C.GL_VERTEX_ARRAY) } +func abs(x int) int { + if x < 0 { + return -x + } + return x +} + func (context *GraphicsContext) SetOffscreen(texture *Texture) { framebuffer := C.GLuint(0) if texture != nil { framebuffer = context.getFramebuffer(texture) + if framebuffer == context.mainFramebuffer { + panic("invalid framebuffer") + } } else { framebuffer = context.mainFramebuffer } @@ -136,9 +145,7 @@ func (context *GraphicsContext) SetOffscreen(texture *Texture) { tx = -1 ty = 1 } - C.glViewport(0, 0, - C.GLsizei(math.Abs(float64(width))), - C.GLsizei(math.Abs(float64(height)))) + C.glViewport(0, 0, C.GLsizei(abs(width)), C.GLsizei(abs(height))) e11 := float32(2.0) / float32(width) e22 := float32(2.0) / float32(height) e41 := float32(tx) diff --git a/graphics/texture.go b/graphics/texture.go index 9601ca183..8840ad0bc 100644 --- a/graphics/texture.go +++ b/graphics/texture.go @@ -28,7 +28,7 @@ type Texture struct { } func createTexture(device *Device, width, height int, pixels []uint8) *Texture{ - textureWidth := int(Clp2(uint64(width))) + textureWidth := int(Clp2(uint64(width))) textureHeight := int(Clp2(uint64(height))) if pixels != nil { if width != textureWidth { diff --git a/ui/ui.go b/ui/ui.go index c3447577b..a0e1b56f6 100644 --- a/ui/ui.go +++ b/ui/ui.go @@ -10,8 +10,3 @@ type UI interface { ScreenScale() int Run(device *graphics.Device) } - -func ExecuteOnUIThread(f func()) { - // TODO: implement! - f() -}