mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
Refactoring
This commit is contained in:
parent
d4fd3adc53
commit
0ab7dca5e4
@ -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())
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user