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 {
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())
}

View File

@ -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)

View File

@ -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 {

View File

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