mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-11 19:48:54 +01:00
parent
596efc86fe
commit
599571c7a7
@ -455,7 +455,7 @@ type GameWithCRTEffect struct {
|
|||||||
crtShader *ebiten.Shader
|
crtShader *ebiten.Shader
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GameWithCRTEffect) DrawFinalScreen(screen ebiten.FinalScreen, offscreen *ebiten.Image) {
|
func (g *GameWithCRTEffect) DrawFinalScreen(screen ebiten.FinalScreen, offscreen *ebiten.Image, geoM ebiten.GeoM) {
|
||||||
if g.crtShader == nil {
|
if g.crtShader == nil {
|
||||||
s, err := ebiten.NewShader(crtGo)
|
s, err := ebiten.NewShader(crtGo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -465,11 +465,10 @@ func (g *GameWithCRTEffect) DrawFinalScreen(screen ebiten.FinalScreen, offscreen
|
|||||||
}
|
}
|
||||||
|
|
||||||
ow, oh := offscreen.Size()
|
ow, oh := offscreen.Size()
|
||||||
sw, sh := screen.Size()
|
|
||||||
|
|
||||||
op := &ebiten.DrawRectShaderOptions{}
|
op := &ebiten.DrawRectShaderOptions{}
|
||||||
op.Images[0] = offscreen
|
op.Images[0] = offscreen
|
||||||
op.GeoM.Scale(float64(sw)/float64(ow), float64(sh)/float64(oh))
|
op.GeoM = geoM
|
||||||
screen.DrawRectShader(ow, oh, g.crtShader, op)
|
screen.DrawRectShader(ow, oh, g.crtShader, op)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
17
gameforui.go
17
gameforui.go
@ -148,29 +148,30 @@ func (g *gameForUI) DrawOffscreen() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (g *gameForUI) DrawScreen() {
|
func (g *gameForUI) DrawScreen() {
|
||||||
|
scale, offsetX, offsetY := g.ScreenScaleAndOffsets()
|
||||||
|
var geoM GeoM
|
||||||
|
geoM.Scale(scale, scale)
|
||||||
|
geoM.Translate(offsetX, offsetY)
|
||||||
|
|
||||||
if d, ok := g.game.(FinalScreenDrawer); ok {
|
if d, ok := g.game.(FinalScreenDrawer); ok {
|
||||||
d.DrawFinalScreen(g.screen, g.offscreen)
|
d.DrawFinalScreen(g.screen, g.offscreen, geoM)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
scale, offsetX, offsetY := g.ScreenScaleAndOffsets()
|
|
||||||
switch {
|
switch {
|
||||||
case !isScreenFilterEnabled(), math.Floor(scale) == scale:
|
case !isScreenFilterEnabled(), math.Floor(scale) == scale:
|
||||||
op := &DrawImageOptions{}
|
op := &DrawImageOptions{}
|
||||||
op.GeoM.Scale(scale, scale)
|
op.GeoM = geoM
|
||||||
op.GeoM.Translate(offsetX, offsetY)
|
|
||||||
g.screen.DrawImage(g.offscreen, op)
|
g.screen.DrawImage(g.offscreen, op)
|
||||||
case scale < 1:
|
case scale < 1:
|
||||||
op := &DrawImageOptions{}
|
op := &DrawImageOptions{}
|
||||||
op.GeoM.Scale(scale, scale)
|
op.GeoM = geoM
|
||||||
op.GeoM.Translate(offsetX, offsetY)
|
|
||||||
op.Filter = FilterLinear
|
op.Filter = FilterLinear
|
||||||
g.screen.DrawImage(g.offscreen, op)
|
g.screen.DrawImage(g.offscreen, op)
|
||||||
default:
|
default:
|
||||||
op := &DrawRectShaderOptions{}
|
op := &DrawRectShaderOptions{}
|
||||||
op.Images[0] = g.offscreen
|
op.Images[0] = g.offscreen
|
||||||
op.GeoM.Scale(scale, scale)
|
op.GeoM = geoM
|
||||||
op.GeoM.Translate(offsetX, offsetY)
|
|
||||||
w, h := g.offscreen.Size()
|
w, h := g.offscreen.Size()
|
||||||
g.screen.DrawRectShader(w, h, g.screenShader, op)
|
g.screen.DrawRectShader(w, h, g.screenShader, op)
|
||||||
}
|
}
|
||||||
|
6
run.go
6
run.go
@ -107,7 +107,11 @@ type FinalScreenDrawer interface {
|
|||||||
// DrawFinalScreen draws the final screen.
|
// DrawFinalScreen draws the final screen.
|
||||||
// If a game implementing FinalScreenDrawer is passed to RunGame, DrawFinalScreen is called after Draw.
|
// If a game implementing FinalScreenDrawer is passed to RunGame, DrawFinalScreen is called after Draw.
|
||||||
// screen is the final screen. offscreen is the offscreen modified at Draw.
|
// screen is the final screen. offscreen is the offscreen modified at Draw.
|
||||||
DrawFinalScreen(screen FinalScreen, offscreen *Image)
|
//
|
||||||
|
// geoM is the default geometry matrix to render the offscreen onto the final screen.
|
||||||
|
// geoM scales the offscreen to fit the final screen without changing the aspect ratio, and
|
||||||
|
// translates the offscreen to put it on the center of the final screen.
|
||||||
|
DrawFinalScreen(screen FinalScreen, offscreen *Image, geoM GeoM)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DefaultTPS represents a default ticks per second, that represents how many times game updating happens in a second.
|
// DefaultTPS represents a default ticks per second, that represents how many times game updating happens in a second.
|
||||||
|
Loading…
Reference in New Issue
Block a user