mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-13 22:47:26 +01:00
Remove RenderTarget.Width/Height
This commit is contained in:
parent
20f9a990ac
commit
5679120f29
@ -19,6 +19,13 @@ type Rects struct {
|
|||||||
rectColor *color.RGBA
|
rectColor *color.RGBA
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
rectTextureWidth = 16
|
||||||
|
rectTextureHeight = 16
|
||||||
|
offscreenWidth = 256
|
||||||
|
offscreenHeight = 240
|
||||||
|
)
|
||||||
|
|
||||||
func New() *Rects {
|
func New() *Rects {
|
||||||
return &Rects{
|
return &Rects{
|
||||||
rectTextureInited: false,
|
rectTextureInited: false,
|
||||||
@ -29,8 +36,8 @@ func New() *Rects {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (game *Rects) Init(tf graphics.TextureFactory) {
|
func (game *Rects) Init(tf graphics.TextureFactory) {
|
||||||
game.rectTexture = tf.NewRenderTarget(16, 16)
|
game.rectTexture = tf.NewRenderTarget(rectTextureWidth, rectTextureHeight)
|
||||||
game.offscreen = tf.NewRenderTarget(256, 240)
|
game.offscreen = tf.NewRenderTarget(offscreenWidth, offscreenHeight)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (game *Rects) Update(context ebiten.GameContext) {
|
func (game *Rects) Update(context ebiten.GameContext) {
|
||||||
@ -41,18 +48,18 @@ func (game *Rects) Update(context ebiten.GameContext) {
|
|||||||
game.rectBounds.Height =
|
game.rectBounds.Height =
|
||||||
rand.Intn(context.ScreenHeight() - game.rectBounds.Y)
|
rand.Intn(context.ScreenHeight() - game.rectBounds.Y)
|
||||||
|
|
||||||
game.rectColor.R = uint8(rand.Intn(256))
|
game.rectColor.R = uint8(rand.Intn(math.MaxUint8))
|
||||||
game.rectColor.G = uint8(rand.Intn(256))
|
game.rectColor.G = uint8(rand.Intn(math.MaxUint8))
|
||||||
game.rectColor.B = uint8(rand.Intn(256))
|
game.rectColor.B = uint8(rand.Intn(math.MaxUint8))
|
||||||
game.rectColor.A = uint8(rand.Intn(256))
|
game.rectColor.A = uint8(rand.Intn(math.MaxUint8))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (game *Rects) rectGeometryMatrix() matrix.Geometry {
|
func (game *Rects) rectGeometryMatrix() matrix.Geometry {
|
||||||
geometryMatrix := matrix.IdentityGeometry()
|
geometryMatrix := matrix.IdentityGeometry()
|
||||||
scaleX := float64(game.rectBounds.Width) /
|
scaleX := float64(game.rectBounds.Width) /
|
||||||
float64(game.rectTexture.Width())
|
float64(rectTextureWidth)
|
||||||
scaleY := float64(game.rectBounds.Height) /
|
scaleY := float64(game.rectBounds.Height) /
|
||||||
float64(game.rectTexture.Height())
|
float64(rectTextureHeight)
|
||||||
geometryMatrix.Scale(scaleX, scaleY)
|
geometryMatrix.Scale(scaleX, scaleY)
|
||||||
geometryMatrix.Translate(
|
geometryMatrix.Translate(
|
||||||
float64(game.rectBounds.X), float64(game.rectBounds.Y))
|
float64(game.rectBounds.X), float64(game.rectBounds.Y))
|
||||||
|
@ -19,7 +19,6 @@ type TexturePart struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Context interface {
|
type Context interface {
|
||||||
Screen() RenderTarget
|
|
||||||
Clear()
|
Clear()
|
||||||
Fill(r, g, b uint8)
|
Fill(r, g, b uint8)
|
||||||
DrawTexture(textureID TextureID,
|
DrawTexture(textureID TextureID,
|
||||||
@ -29,6 +28,7 @@ type Context interface {
|
|||||||
parts []TexturePart,
|
parts []TexturePart,
|
||||||
geometryMatrix matrix.Geometry,
|
geometryMatrix matrix.Geometry,
|
||||||
colorMatrix matrix.Color)
|
colorMatrix matrix.Color)
|
||||||
|
ResetOffscreen()
|
||||||
SetOffscreen(renderTargetID RenderTargetID)
|
SetOffscreen(renderTargetID RenderTargetID)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,8 +50,6 @@ type TextureID int
|
|||||||
type RenderTarget interface {
|
type RenderTarget interface {
|
||||||
Texture() Texture
|
Texture() Texture
|
||||||
ID() RenderTargetID
|
ID() RenderTargetID
|
||||||
Width() int
|
|
||||||
Height() int
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type RenderTargetID int
|
type RenderTargetID int
|
||||||
|
@ -51,10 +51,6 @@ func (context *Context) Init() {
|
|||||||
context.screenWidth, context.screenHeight).(*RenderTarget)
|
context.screenWidth, context.screenHeight).(*RenderTarget)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (context *Context) Screen() graphics.RenderTarget {
|
|
||||||
return context.screen
|
|
||||||
}
|
|
||||||
|
|
||||||
func (context *Context) Clear() {
|
func (context *Context) Clear() {
|
||||||
context.Fill(0, 0, 0)
|
context.Fill(0, 0, 0)
|
||||||
}
|
}
|
||||||
@ -136,6 +132,10 @@ func (context *Context) DrawTextureParts(
|
|||||||
C.glDisableClientState(C.GL_VERTEX_ARRAY)
|
C.glDisableClientState(C.GL_VERTEX_ARRAY)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (context *Context) ResetOffscreen() {
|
||||||
|
context.setOffscreen(context.screen)
|
||||||
|
}
|
||||||
|
|
||||||
func abs(x int) int {
|
func abs(x int) int {
|
||||||
if x < 0 {
|
if x < 0 {
|
||||||
return -x
|
return -x
|
||||||
@ -189,7 +189,7 @@ func (context *Context) projectionMatrix() [16]float32 {
|
|||||||
e41 = -1
|
e41 = -1
|
||||||
e42 = -1
|
e42 = -1
|
||||||
} else {
|
} else {
|
||||||
height := float32(texture.Height())
|
height := float32(texture.height)
|
||||||
e11 = float32(2) / float32(texture.textureWidth)
|
e11 = float32(2) / float32(texture.textureWidth)
|
||||||
e22 = -1 * float32(2) / float32(texture.textureHeight)
|
e22 = -1 * float32(2) / float32(texture.textureHeight)
|
||||||
e41 = -1
|
e41 = -1
|
||||||
|
@ -34,7 +34,7 @@ func (device *Device) Update(draw func(graphics.Context)) {
|
|||||||
C.glEnable(C.GL_TEXTURE_2D)
|
C.glEnable(C.GL_TEXTURE_2D)
|
||||||
C.glTexParameteri(C.GL_TEXTURE_2D, C.GL_TEXTURE_MIN_FILTER, C.GL_NEAREST)
|
C.glTexParameteri(C.GL_TEXTURE_2D, C.GL_TEXTURE_MIN_FILTER, C.GL_NEAREST)
|
||||||
C.glTexParameteri(C.GL_TEXTURE_2D, C.GL_TEXTURE_MAG_FILTER, C.GL_NEAREST)
|
C.glTexParameteri(C.GL_TEXTURE_2D, C.GL_TEXTURE_MAG_FILTER, C.GL_NEAREST)
|
||||||
context.SetOffscreen(context.Screen().ID())
|
context.ResetOffscreen()
|
||||||
context.Clear()
|
context.Clear()
|
||||||
|
|
||||||
draw(context)
|
draw(context)
|
||||||
@ -53,7 +53,7 @@ func (device *Device) Update(draw func(graphics.Context)) {
|
|||||||
{0, scale, 0},
|
{0, scale, 0},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
context.DrawTexture(context.Screen().Texture().ID(),
|
context.DrawTexture(context.screen.Texture().ID(),
|
||||||
geometryMatrix, matrix.IdentityColor())
|
geometryMatrix, matrix.IdentityColor())
|
||||||
context.flush()
|
context.flush()
|
||||||
}
|
}
|
||||||
|
@ -144,11 +144,3 @@ func (renderTarget *RenderTarget) Texture() graphics.Texture {
|
|||||||
func (renderTarget *RenderTarget) ID() graphics.RenderTargetID {
|
func (renderTarget *RenderTarget) ID() graphics.RenderTargetID {
|
||||||
return graphics.RenderTargetID(renderTarget.id)
|
return graphics.RenderTargetID(renderTarget.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (renderTarget *RenderTarget) Width() int {
|
|
||||||
return renderTarget.width
|
|
||||||
}
|
|
||||||
|
|
||||||
func (renderTarget *RenderTarget) Height() int {
|
|
||||||
return renderTarget.height
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user