Refactoring

This commit is contained in:
Hajime Hoshi 2013-06-19 01:14:55 +09:00
parent d4fd3adc53
commit 0ab7dca5e4
4 changed files with 18 additions and 11 deletions

View File

@ -92,6 +92,7 @@ func (ui *GlutUI) Run(device *graphics.Device) {
type DemoGame struct { type DemoGame struct {
ebitenTexture *graphics.Texture ebitenTexture *graphics.Texture
x int
} }
func (game *DemoGame) Update() { func (game *DemoGame) Update() {
@ -109,6 +110,7 @@ func (game *DemoGame) Update() {
game.ebitenTexture = currentUI.device.NewTextureFromImage(img) game.ebitenTexture = currentUI.device.NewTextureFromImage(img)
} }
game.x++
} }
func (game *DemoGame) Draw(g *graphics.GraphicsContext, offscreen *graphics.Texture) { 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 { if game.ebitenTexture == nil {
return return
} }
geometryMatrix := graphics.IdentityGeometryMatrix()
geometryMatrix.SetTx(graphics.AffineMatrixElement(game.x))
geometryMatrix.SetTy(graphics.AffineMatrixElement(game.x))
g.DrawTexture(game.ebitenTexture, g.DrawTexture(game.ebitenTexture,
0, 0, game.ebitenTexture.Width, game.ebitenTexture.Height, 0, 0, game.ebitenTexture.Width, game.ebitenTexture.Height,
graphics.IdentityGeometryMatrix(), geometryMatrix,
graphics.IdentityColorMatrix()) graphics.IdentityColorMatrix())
} }

View File

@ -8,7 +8,6 @@ import "C"
import ( import (
"fmt" "fmt"
"image/color" "image/color"
"math"
"unsafe" "unsafe"
) )
@ -110,10 +109,20 @@ func (context *GraphicsContext) DrawTexture(texture *Texture,
C.glDisableClientState(C.GL_VERTEX_ARRAY) C.glDisableClientState(C.GL_VERTEX_ARRAY)
} }
func abs(x int) int {
if x < 0 {
return -x
}
return x
}
func (context *GraphicsContext) SetOffscreen(texture *Texture) { func (context *GraphicsContext) SetOffscreen(texture *Texture) {
framebuffer := C.GLuint(0) framebuffer := C.GLuint(0)
if texture != nil { if texture != nil {
framebuffer = context.getFramebuffer(texture) framebuffer = context.getFramebuffer(texture)
if framebuffer == context.mainFramebuffer {
panic("invalid framebuffer")
}
} else { } else {
framebuffer = context.mainFramebuffer framebuffer = context.mainFramebuffer
} }
@ -136,9 +145,7 @@ func (context *GraphicsContext) SetOffscreen(texture *Texture) {
tx = -1 tx = -1
ty = 1 ty = 1
} }
C.glViewport(0, 0, C.glViewport(0, 0, C.GLsizei(abs(width)), C.GLsizei(abs(height)))
C.GLsizei(math.Abs(float64(width))),
C.GLsizei(math.Abs(float64(height))))
e11 := float32(2.0) / float32(width) e11 := float32(2.0) / float32(width)
e22 := float32(2.0) / float32(height) e22 := float32(2.0) / float32(height)
e41 := float32(tx) e41 := float32(tx)

View File

@ -10,8 +10,3 @@ type UI interface {
ScreenScale() int ScreenScale() int
Run(device *graphics.Device) Run(device *graphics.Device)
} }
func ExecuteOnUIThread(f func()) {
// TODO: implement!
f()
}