mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 18:58:54 +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 {
|
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())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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)
|
||||||
|
@ -28,7 +28,7 @@ type Texture struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func createTexture(device *Device, width, height int, pixels []uint8) *Texture{
|
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)))
|
textureHeight := int(Clp2(uint64(height)))
|
||||||
if pixels != nil {
|
if pixels != nil {
|
||||||
if width != textureWidth {
|
if width != textureWidth {
|
||||||
|
Loading…
Reference in New Issue
Block a user