mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
Add graphics.Rectangle
This commit is contained in:
parent
88eeb6d65d
commit
a374565e37
@ -57,7 +57,7 @@ func (game *RotatingImage) Draw(g graphics.GraphicsContext, offscreen graphics.T
|
|||||||
geometryMatrix.Translate(centerX-tx/2, centerY-ty/2)
|
geometryMatrix.Translate(centerX-tx/2, centerY-ty/2)
|
||||||
|
|
||||||
g.DrawTexture(game.ebitenTexture.ID,
|
g.DrawTexture(game.ebitenTexture.ID,
|
||||||
0, 0, int(tx), int(ty),
|
graphics.Rectangle{0, 0, int(tx), int(ty)},
|
||||||
geometryMatrix,
|
geometryMatrix,
|
||||||
matrix.IdentityColor())
|
matrix.IdentityColor())
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,7 @@ func (sprite *Sprite) Draw(g graphics.GraphicsContext) {
|
|||||||
geometryMatrix.Translate(float64(sprite.x), float64(sprite.y))
|
geometryMatrix.Translate(float64(sprite.x), float64(sprite.y))
|
||||||
|
|
||||||
g.DrawTexture(sprite.texture.ID,
|
g.DrawTexture(sprite.texture.ID,
|
||||||
0, 0, sprite.texture.Width, sprite.texture.Height,
|
graphics.Rectangle{0, 0, sprite.texture.Width, sprite.texture.Height},
|
||||||
geometryMatrix,
|
geometryMatrix,
|
||||||
matrix.IdentityColor())
|
matrix.IdentityColor())
|
||||||
}
|
}
|
||||||
|
@ -11,11 +11,18 @@ type Device interface {
|
|||||||
TextureFactory() TextureFactory
|
TextureFactory() TextureFactory
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Rectangle struct {
|
||||||
|
X int
|
||||||
|
Y int
|
||||||
|
Width int
|
||||||
|
Height int
|
||||||
|
}
|
||||||
|
|
||||||
type GraphicsContext interface {
|
type GraphicsContext interface {
|
||||||
Clear()
|
Clear()
|
||||||
Fill(color color.Color)
|
Fill(color color.Color)
|
||||||
DrawTexture(textureId TextureID,
|
DrawTexture(textureId TextureID,
|
||||||
srcX, srcY, srcWidth, srcHeight int,
|
src Rectangle,
|
||||||
geometryMatrix matrix.Geometry, colorMatrix matrix.Color)
|
geometryMatrix matrix.Geometry, colorMatrix matrix.Color)
|
||||||
SetOffscreen(textureId TextureID)
|
SetOffscreen(textureId TextureID)
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ func (device *Device) Update() {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
g.DrawTexture(device.offscreenTexture.ID,
|
g.DrawTexture(device.offscreenTexture.ID,
|
||||||
0, 0, device.screenWidth, device.screenHeight,
|
graphics.Rectangle{0, 0, device.screenWidth, device.screenHeight},
|
||||||
geometryMatrix, matrix.IdentityColor())
|
geometryMatrix, matrix.IdentityColor())
|
||||||
g.flush()
|
g.flush()
|
||||||
}
|
}
|
||||||
|
@ -66,8 +66,7 @@ func (context *GraphicsContext) DrawRect(x, y, width, height int, clr color.Colo
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (context *GraphicsContext) DrawTexture(
|
func (context *GraphicsContext) DrawTexture(
|
||||||
textureID graphics.TextureID,
|
textureID graphics.TextureID, src graphics.Rectangle,
|
||||||
srcX, srcY, srcWidth, srcHeight int,
|
|
||||||
geometryMatrix matrix.Geometry, colorMatrix matrix.Color) {
|
geometryMatrix matrix.Geometry, colorMatrix matrix.Color) {
|
||||||
|
|
||||||
texture := context.textures[textureID]
|
texture := context.textures[textureID]
|
||||||
@ -76,9 +75,9 @@ func (context *GraphicsContext) DrawTexture(
|
|||||||
C.glBindTexture(C.GL_TEXTURE_2D, texture.id)
|
C.glBindTexture(C.GL_TEXTURE_2D, texture.id)
|
||||||
|
|
||||||
x1 := float32(0)
|
x1 := float32(0)
|
||||||
x2 := float32(srcWidth)
|
x2 := float32(src.Width)
|
||||||
y1 := float32(0)
|
y1 := float32(0)
|
||||||
y2 := float32(srcHeight)
|
y2 := float32(src.Height)
|
||||||
vertex := [...]float32{
|
vertex := [...]float32{
|
||||||
x1, y1,
|
x1, y1,
|
||||||
x2, y1,
|
x2, y1,
|
||||||
@ -86,10 +85,10 @@ func (context *GraphicsContext) DrawTexture(
|
|||||||
x2, y2,
|
x2, y2,
|
||||||
}
|
}
|
||||||
|
|
||||||
tu1 := float32(srcX) / float32(texture.textureWidth)
|
tu1 := float32(src.X) / float32(texture.textureWidth)
|
||||||
tu2 := float32(srcX+srcWidth) / float32(texture.textureWidth)
|
tu2 := float32(src.X+src.Width) / float32(texture.textureWidth)
|
||||||
tv1 := float32(srcY) / float32(texture.textureHeight)
|
tv1 := float32(src.Y) / float32(texture.textureHeight)
|
||||||
tv2 := float32(srcY+srcHeight) / float32(texture.textureHeight)
|
tv2 := float32(src.Y+src.Height) / float32(texture.textureHeight)
|
||||||
texCoord := [...]float32{
|
texCoord := [...]float32{
|
||||||
tu1, tv1,
|
tu1, tv1,
|
||||||
tu2, tv1,
|
tu2, tv1,
|
||||||
|
Loading…
Reference in New Issue
Block a user