mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-26 02:42:02 +01:00
Remove graphics.Point and graphics.Size
This commit is contained in:
parent
fad8fb7a98
commit
79a68a425b
@ -57,10 +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,
|
||||||
graphics.Rectangle{
|
graphics.Rect{0, 0, int(tx), int(ty)},
|
||||||
graphics.Point{0, 0},
|
|
||||||
graphics.Size{int(tx), int(ty)},
|
|
||||||
},
|
|
||||||
geometryMatrix,
|
geometryMatrix,
|
||||||
matrix.IdentityColor())
|
matrix.IdentityColor())
|
||||||
}
|
}
|
||||||
|
@ -110,10 +110,10 @@ func (game *Sprites) Draw(g graphics.GraphicsContext, offscreen graphics.Texture
|
|||||||
texture := game.ebitenTexture
|
texture := game.ebitenTexture
|
||||||
for _, sprite := range game.sprites {
|
for _, sprite := range game.sprites {
|
||||||
location := graphics.TextureLocation{
|
location := graphics.TextureLocation{
|
||||||
Location: graphics.Point{sprite.x, sprite.y},
|
LocationX: sprite.x,
|
||||||
Source: graphics.Rectangle{
|
LocationY: sprite.y,
|
||||||
graphics.Point{0, 0},
|
Source: graphics.Rect{
|
||||||
graphics.Size{texture.Width, texture.Height},
|
0, 0, texture.Width, texture.Height,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
locations = append(locations, location)
|
locations = append(locations, location)
|
||||||
|
@ -11,31 +11,24 @@ type Device interface {
|
|||||||
TextureFactory() TextureFactory
|
TextureFactory() TextureFactory
|
||||||
}
|
}
|
||||||
|
|
||||||
type Point struct {
|
type Rect struct {
|
||||||
X int
|
X int
|
||||||
Y int
|
Y int
|
||||||
}
|
Width int
|
||||||
|
|
||||||
type Size struct {
|
|
||||||
Width int
|
|
||||||
Height int
|
Height int
|
||||||
}
|
}
|
||||||
|
|
||||||
type Rectangle struct {
|
|
||||||
Location Point
|
|
||||||
Size Size
|
|
||||||
}
|
|
||||||
|
|
||||||
type TextureLocation struct {
|
type TextureLocation struct {
|
||||||
Location Point
|
LocationX int
|
||||||
Source Rectangle
|
LocationY int
|
||||||
|
Source Rect
|
||||||
}
|
}
|
||||||
|
|
||||||
type GraphicsContext interface {
|
type GraphicsContext interface {
|
||||||
Clear()
|
Clear()
|
||||||
Fill(color color.Color)
|
Fill(color color.Color)
|
||||||
DrawTexture(textureId TextureID,
|
DrawTexture(textureId TextureID,
|
||||||
source Rectangle,
|
source Rect,
|
||||||
geometryMatrix matrix.Geometry, colorMatrix matrix.Color)
|
geometryMatrix matrix.Geometry, colorMatrix matrix.Color)
|
||||||
DrawTextures(textureId TextureID,
|
DrawTextures(textureId TextureID,
|
||||||
locations []TextureLocation,
|
locations []TextureLocation,
|
||||||
|
@ -56,9 +56,8 @@ func (device *Device) Update() {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
g.DrawTexture(device.offscreenTexture.ID,
|
g.DrawTexture(device.offscreenTexture.ID,
|
||||||
graphics.Rectangle{
|
graphics.Rect{
|
||||||
graphics.Point{0, 0},
|
0, 0, device.screenWidth, device.screenHeight,
|
||||||
graphics.Size{device.screenWidth, device.screenHeight},
|
|
||||||
},
|
},
|
||||||
geometryMatrix, matrix.IdentityColor())
|
geometryMatrix, matrix.IdentityColor())
|
||||||
g.flush()
|
g.flush()
|
||||||
|
@ -66,14 +66,9 @@ func (context *GraphicsContext) DrawRect(x, y, width, height int, clr color.Colo
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (context *GraphicsContext) DrawTexture(
|
func (context *GraphicsContext) DrawTexture(
|
||||||
textureID graphics.TextureID, source graphics.Rectangle,
|
textureID graphics.TextureID, source graphics.Rect,
|
||||||
geometryMatrix matrix.Geometry, colorMatrix matrix.Color) {
|
geometryMatrix matrix.Geometry, colorMatrix matrix.Color) {
|
||||||
locations := []graphics.TextureLocation{
|
locations := []graphics.TextureLocation{{0, 0, source}}
|
||||||
{
|
|
||||||
graphics.Point{0, 0},
|
|
||||||
source,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
context.DrawTextures(textureID, locations,
|
context.DrawTextures(textureID, locations,
|
||||||
geometryMatrix, colorMatrix)
|
geometryMatrix, colorMatrix)
|
||||||
}
|
}
|
||||||
@ -87,7 +82,6 @@ func (context *GraphicsContext) DrawTextures(
|
|||||||
context.setShaderProgram(geometryMatrix, colorMatrix)
|
context.setShaderProgram(geometryMatrix, colorMatrix)
|
||||||
C.glBindTexture(C.GL_TEXTURE_2D, texture.id)
|
C.glBindTexture(C.GL_TEXTURE_2D, texture.id)
|
||||||
|
|
||||||
|
|
||||||
vertexAttrLocation := getAttributeLocation(context.currentShaderProgram, "vertex")
|
vertexAttrLocation := getAttributeLocation(context.currentShaderProgram, "vertex")
|
||||||
textureAttrLocation := getAttributeLocation(context.currentShaderProgram, "texture")
|
textureAttrLocation := getAttributeLocation(context.currentShaderProgram, "texture")
|
||||||
|
|
||||||
@ -96,10 +90,10 @@ func (context *GraphicsContext) DrawTextures(
|
|||||||
C.glEnableVertexAttribArray(C.GLuint(vertexAttrLocation))
|
C.glEnableVertexAttribArray(C.GLuint(vertexAttrLocation))
|
||||||
C.glEnableVertexAttribArray(C.GLuint(textureAttrLocation))
|
C.glEnableVertexAttribArray(C.GLuint(textureAttrLocation))
|
||||||
for _, location := range locations {
|
for _, location := range locations {
|
||||||
x1 := float32(location.Location.X)
|
x1 := float32(location.LocationX)
|
||||||
x2 := float32(location.Location.X + location.Source.Size.Width)
|
x2 := float32(location.LocationX + location.Source.Width)
|
||||||
y1 := float32(location.Location.Y)
|
y1 := float32(location.LocationY)
|
||||||
y2 := float32(location.Location.Y + location.Source.Size.Height)
|
y2 := float32(location.LocationY + location.Source.Height)
|
||||||
vertex := [...]float32{
|
vertex := [...]float32{
|
||||||
x1, y1,
|
x1, y1,
|
||||||
x2, y1,
|
x2, y1,
|
||||||
@ -108,10 +102,10 @@ func (context *GraphicsContext) DrawTextures(
|
|||||||
}
|
}
|
||||||
|
|
||||||
src := location.Source
|
src := location.Source
|
||||||
tu1 := float32(src.Location.X) / float32(texture.textureWidth)
|
tu1 := float32(src.X) / float32(texture.textureWidth)
|
||||||
tu2 := float32(src.Location.X+src.Size.Width) / float32(texture.textureWidth)
|
tu2 := float32(src.X+src.Width) / float32(texture.textureWidth)
|
||||||
tv1 := float32(src.Location.Y) / float32(texture.textureHeight)
|
tv1 := float32(src.Y) / float32(texture.textureHeight)
|
||||||
tv2 := float32(src.Location.Y+src.Size.Height) / 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