examples: Use FilterDefault (#453)

This commit is contained in:
Hajime Hoshi 2018-02-14 02:55:51 +09:00
parent 6ef4bbde2d
commit 5ed5cceb43
28 changed files with 49 additions and 46 deletions

View File

@ -66,7 +66,7 @@ func (g *Game) Update() error {
func (g *Game) Draw(screen *ebiten.Image) { func (g *Game) Draw(screen *ebiten.Image) {
if g.boardImage == nil { if g.boardImage == nil {
w, h := g.board.Size() w, h := g.board.Size()
g.boardImage, _ = ebiten.NewImage(w, h, ebiten.FilterNearest) g.boardImage, _ = ebiten.NewImage(w, h, ebiten.FilterDefault)
} }
screen.Fill(backgroundColor) screen.Fill(backgroundColor)
g.board.Draw(g.boardImage) g.board.Draw(g.boardImage)

View File

@ -336,7 +336,7 @@ var (
) )
func init() { func init() {
tileImage, _ = ebiten.NewImage(tileSize, tileSize, ebiten.FilterNearest) tileImage, _ = ebiten.NewImage(tileSize, tileSize, ebiten.FilterDefault)
tileImage.Fill(color.White) tileImage.Fill(color.White)
} }

View File

@ -64,7 +64,7 @@ func update(screen *ebiten.Image) error {
func main() { func main() {
var err error var err error
ebitenImage, _, err = ebitenutil.NewImageFromFile("_resources/images/ebiten.png", ebiten.FilterNearest) ebitenImage, _, err = ebitenutil.NewImageFromFile("_resources/images/ebiten.png", ebiten.FilterDefault)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }

View File

@ -51,16 +51,16 @@ var (
func init() { func init() {
var err error var err error
gophersImage, _, err = ebitenutil.NewImageFromFile("_resources/images/gophers.jpg", ebiten.FilterNearest) gophersImage, _, err = ebitenutil.NewImageFromFile("_resources/images/gophers.jpg", ebiten.FilterDefault)
if err != nil { if err != nil {
panic(err) panic(err)
} }
groundImage, _ = ebiten.NewImage(screenWidth*2, screenHeight*2/3+50, ebiten.FilterNearest) groundImage, _ = ebiten.NewImage(screenWidth*2, screenHeight*2/3+50, ebiten.FilterDefault)
perspectiveGroundImage, _ = ebiten.NewImage(screenWidth*2, screenHeight, ebiten.FilterNearest) perspectiveGroundImage, _ = ebiten.NewImage(screenWidth*2, screenHeight, ebiten.FilterDefault)
const repeat = 5 const repeat = 5
w, h := gophersImage.Size() w, h := gophersImage.Size()
repeatedGophersImage, _ = ebiten.NewImage(w*repeat, h*repeat, ebiten.FilterNearest) repeatedGophersImage, _ = ebiten.NewImage(w*repeat, h*repeat, ebiten.FilterDefault)
for j := 0; j < repeat; j++ { for j := 0; j < repeat; j++ {
for i := 0; i < repeat; i++ { for i := 0; i < repeat; i++ {
op := &ebiten.DrawImageOptions{} op := &ebiten.DrawImageOptions{}
@ -84,7 +84,7 @@ func init() {
fogRGBA.SetRGBA(i, j, clr) fogRGBA.SetRGBA(i, j, clr)
} }
} }
fogImage, _ = ebiten.NewImageFromImage(fogRGBA, ebiten.FilterNearest) fogImage, _ = ebiten.NewImageFromImage(fogRGBA, ebiten.FilterDefault)
} }
type player struct { type player struct {

View File

@ -67,7 +67,7 @@ func update(screen *ebiten.Image) error {
func main() { func main() {
var err error var err error
ebitenImage, _, err = ebitenutil.NewImageFromFile("_resources/images/ebiten.png", ebiten.FilterNearest) ebitenImage, _, err = ebitenutil.NewImageFromFile("_resources/images/ebiten.png", ebiten.FilterDefault)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }

View File

@ -72,13 +72,13 @@ func linesTextBoxPosition() (x, y int) {
func init() { func init() {
// Background // Background
var err error var err error
imageGameBG, _, err = ebitenutil.NewImageFromFile("_resources/images/gophers.jpg", ebiten.FilterLinear) imageGameBG, _, err = ebitenutil.NewImageFromFile("_resources/images/gophers.jpg", ebiten.FilterDefault)
if err != nil { if err != nil {
panic(err) panic(err)
} }
// Windows // Windows
imageWindows, _ = ebiten.NewImage(ScreenWidth, ScreenHeight, ebiten.FilterNearest) imageWindows, _ = ebiten.NewImage(ScreenWidth, ScreenHeight, ebiten.FilterDefault)
// Windows: Field // Windows: Field
x, y := fieldWindowPosition() x, y := fieldWindowPosition()
@ -103,7 +103,7 @@ func init() {
drawTextBox(imageWindows, "LINES", x, y, textBoxWidth()) drawTextBox(imageWindows, "LINES", x, y, textBoxWidth())
// Gameover // Gameover
imageGameover, _ = ebiten.NewImage(ScreenWidth, ScreenHeight, ebiten.FilterNearest) imageGameover, _ = ebiten.NewImage(ScreenWidth, ScreenHeight, ebiten.FilterDefault)
imageGameover.Fill(color.NRGBA{0x00, 0x00, 0x00, 0x80}) imageGameover.Fill(color.NRGBA{0x00, 0x00, 0x00, 0x80})
y = (ScreenHeight - blockHeight) / 2 y = (ScreenHeight - blockHeight) / 2
drawTextWithShadowCenter(imageGameover, "GAME OVER", 0, y, 1, color.White, ScreenWidth) drawTextWithShadowCenter(imageGameover, "GAME OVER", 0, y, 1, color.White, ScreenWidth)
@ -185,6 +185,7 @@ func (s *GameScene) drawBackground(r *ebiten.Image) {
op.GeoM.Scale(scale, scale) op.GeoM.Scale(scale, scale)
op.GeoM.Translate(ScreenWidth/2, ScreenHeight/2) op.GeoM.Translate(ScreenWidth/2, ScreenHeight/2)
op.ColorM = lightGray op.ColorM = lightGray
op.Filter = ebiten.FilterLinear
r.DrawImage(imageGameBG, op) r.DrawImage(imageGameBG, op)
} }

View File

@ -28,7 +28,7 @@ var imageBlocks *ebiten.Image
func init() { func init() {
var err error var err error
imageBlocks, _, err = ebitenutil.NewImageFromFile("_resources/images/blocks/blocks.png", ebiten.FilterNearest) imageBlocks, _, err = ebitenutil.NewImageFromFile("_resources/images/blocks/blocks.png", ebiten.FilterDefault)
if err != nil { if err != nil {
panic(err) panic(err)
} }

View File

@ -26,8 +26,8 @@ var (
) )
func init() { func init() {
transitionFrom, _ = ebiten.NewImage(ScreenWidth, ScreenHeight, ebiten.FilterNearest) transitionFrom, _ = ebiten.NewImage(ScreenWidth, ScreenHeight, ebiten.FilterDefault)
transitionTo, _ = ebiten.NewImage(ScreenWidth, ScreenHeight, ebiten.FilterNearest) transitionTo, _ = ebiten.NewImage(ScreenWidth, ScreenHeight, ebiten.FilterDefault)
} }
type Scene interface { type Scene interface {

View File

@ -29,7 +29,7 @@ var imageBackground *ebiten.Image
func init() { func init() {
var err error var err error
imageBackground, _, err = ebitenutil.NewImageFromFile("_resources/images/blocks/background.png", ebiten.FilterNearest) imageBackground, _, err = ebitenutil.NewImageFromFile("_resources/images/blocks/background.png", ebiten.FilterDefault)
if err != nil { if err != nil {
panic(err) panic(err)
} }

View File

@ -83,7 +83,7 @@ func update(screen *ebiten.Image) error {
func main() { func main() {
var err error var err error
ebitenImage, _, err = ebitenutil.NewImageFromFile("_resources/images/ebiten.png", ebiten.FilterNearest) ebitenImage, _, err = ebitenutil.NewImageFromFile("_resources/images/ebiten.png", ebiten.FilterDefault)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }

View File

@ -51,7 +51,7 @@ func init() {
log.Fatal(err) log.Fatal(err)
} }
eimg, err := ebiten.NewImageFromImage(img, ebiten.FilterLinear) eimg, err := ebiten.NewImageFromImage(img, ebiten.FilterDefault)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
@ -98,6 +98,8 @@ func update(screen *ebiten.Image) error {
// Move the image's center to the screen's center. // Move the image's center to the screen's center.
op.GeoM.Translate(float64(sw)/2, float64(sh)/2) op.GeoM.Translate(float64(sw)/2, float64(sh)/2)
op.Filter = ebiten.FilterLinear
screen.DrawImage(highDPIImage, op) screen.DrawImage(highDPIImage, op)
ebitenutil.DebugPrint(screen, fmt.Sprintf("Device Scale Ratio: %0.2f", scale)) ebitenutil.DebugPrint(screen, fmt.Sprintf("Device Scale Ratio: %0.2f", scale))

View File

@ -125,7 +125,7 @@ Inverted: %s [I]`, hue, saturation, value, msgInverted)
func main() { func main() {
var err error var err error
gophersImage, _, err = ebitenutil.NewImageFromFile("_resources/images/gophers.jpg", ebiten.FilterNearest) gophersImage, _, err = ebitenutil.NewImageFromFile("_resources/images/gophers.jpg", ebiten.FilterDefault)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }

View File

@ -56,7 +56,7 @@ func update(screen *ebiten.Image) error {
func main() { func main() {
var err error var err error
gophersImage, _, err = ebitenutil.NewImageFromFile("_resources/images/gophers.jpg", ebiten.FilterNearest) gophersImage, _, err = ebitenutil.NewImageFromFile("_resources/images/gophers.jpg", ebiten.FilterDefault)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }

View File

@ -36,7 +36,7 @@ var (
func init() { func init() {
var err error var err error
bgImage, _, err = ebitenutil.NewImageFromFile("_resources/images/tile.png", ebiten.FilterNearest) bgImage, _, err = ebitenutil.NewImageFromFile("_resources/images/tile.png", ebiten.FilterDefault)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }

View File

@ -83,7 +83,7 @@ var keyboardKeys = [][]string{
func drawKey(t *ebiten.Image, name string, x, y, width int) { func drawKey(t *ebiten.Image, name string, x, y, width int) {
const height = 16 const height = 16
width-- width--
img, _ := ebiten.NewImage(width, height, ebiten.FilterNearest) img, _ := ebiten.NewImage(width, height, ebiten.FilterDefault)
p := make([]byte, width*height*4) p := make([]byte, width*height*4)
for j := 0; j < height; j++ { for j := 0; j < height; j++ {
for i := 0; i < width; i++ { for i := 0; i < width; i++ {
@ -131,7 +131,7 @@ func drawKey(t *ebiten.Image, name string, x, y, width int) {
func outputKeyboardImage() (map[string]image.Rectangle, error) { func outputKeyboardImage() (map[string]image.Rectangle, error) {
keyMap := map[string]image.Rectangle{} keyMap := map[string]image.Rectangle{}
img, _ := ebiten.NewImage(320, 240, ebiten.FilterNearest) img, _ := ebiten.NewImage(320, 240, ebiten.FilterDefault)
x, y := 0, 0 x, y := 0, 0
for j, line := range keyboardKeys { for j, line := range keyboardKeys {
x = 0 x = 0

View File

@ -35,7 +35,7 @@ var keyboardImage *ebiten.Image
func init() { func init() {
var err error var err error
keyboardImage, _, err = ebitenutil.NewImageFromFile("_resources/images/keyboard/keyboard.png", ebiten.FilterNearest) keyboardImage, _, err = ebitenutil.NewImageFromFile("_resources/images/keyboard/keyboard.png", ebiten.FilterDefault)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }

View File

@ -36,7 +36,7 @@ var (
) )
func init() { func init() {
offscreen, _ = ebiten.NewImage(screenWidth, screenHeight, ebiten.FilterNearest) offscreen, _ = ebiten.NewImage(screenWidth, screenHeight, ebiten.FilterDefault)
offscreenPix = make([]byte, screenWidth*screenHeight*4) offscreenPix = make([]byte, screenWidth*screenHeight*4)
for i := range palette { for i := range palette {
palette[i] = byte(math.Sqrt(float64(i)/float64(len(palette))) * 0x80) palette[i] = byte(math.Sqrt(float64(i)/float64(len(palette))) * 0x80)

View File

@ -45,17 +45,17 @@ var (
func init() { func init() {
var err error var err error
bgImage, _, err = ebitenutil.NewImageFromFile("_resources/images/gophers.jpg", ebiten.FilterNearest) bgImage, _, err = ebitenutil.NewImageFromFile("_resources/images/gophers.jpg", ebiten.FilterDefault)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
fgImage, _, err = ebitenutil.NewImageFromFile("_resources/images/fiveyears.jpg", ebiten.FilterNearest) fgImage, _, err = ebitenutil.NewImageFromFile("_resources/images/fiveyears.jpg", ebiten.FilterDefault)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
maskedFgImage, _ = ebiten.NewImage(screenWidth, screenHeight, ebiten.FilterNearest) maskedFgImage, _ = ebiten.NewImage(screenWidth, screenHeight, ebiten.FilterDefault)
// Initialize the spot light image. // Initialize the spot light image.
const r = 64 const r = 64
@ -70,7 +70,7 @@ func init() {
a.SetAlpha(i, j, color.Alpha{b}) a.SetAlpha(i, j, color.Alpha{b})
} }
} }
spotLightImage, _ = ebiten.NewImageFromImage(a, ebiten.FilterNearest) spotLightImage, _ = ebiten.NewImageFromImage(a, ebiten.FilterDefault)
} }
func update(screen *ebiten.Image) error { func update(screen *ebiten.Image) error {

View File

@ -38,7 +38,7 @@ var (
func init() { func init() {
var err error var err error
gophersImage, _, err = ebitenutil.NewImageFromFile("_resources/images/gophers.jpg", ebiten.FilterNearest) gophersImage, _, err = ebitenutil.NewImageFromFile("_resources/images/gophers.jpg", ebiten.FilterDefault)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
@ -64,7 +64,7 @@ func update(screen *ebiten.Image) error {
func main() { func main() {
w, h := gophersImage.Size() w, h := gophersImage.Size()
gophersRenderTarget, _ = ebiten.NewImage(w/mosaicRatio, h/mosaicRatio, ebiten.FilterNearest) gophersRenderTarget, _ = ebiten.NewImage(w/mosaicRatio, h/mosaicRatio, ebiten.FilterDefault)
if err := ebiten.Run(update, screenWidth, screenHeight, 2, "Mosaic (Ebiten Demo)"); err != nil { if err := ebiten.Run(update, screenWidth, screenHeight, 2, "Mosaic (Ebiten Demo)"); err != nil {
log.Fatal(err) log.Fatal(err)
} }

View File

@ -54,9 +54,9 @@ func init() {
Pix: pixels, Pix: pixels,
Stride: 4, Stride: 4,
Rect: image.Rect(0, 0, 4, 4), Rect: image.Rect(0, 0, 4, 4),
}, ebiten.FilterNearest) }, ebiten.FilterDefault)
canvasImage, _ = ebiten.NewImage(screenWidth, screenHeight, ebiten.FilterNearest) canvasImage, _ = ebiten.NewImage(screenWidth, screenHeight, ebiten.FilterDefault)
canvasImage.Fill(color.White) canvasImage.Fill(color.White)
} }

View File

@ -66,7 +66,7 @@ func update(screen *ebiten.Image) error {
func main() { func main() {
var err error var err error
gophersImage, _, err = ebitenutil.NewImageFromFile("_resources/images/gophers.jpg", ebiten.FilterNearest) gophersImage, _, err = ebitenutil.NewImageFromFile("_resources/images/gophers.jpg", ebiten.FilterDefault)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }

View File

@ -164,7 +164,7 @@ var (
) )
func init() { func init() {
pianoImage, _ = ebiten.NewImage(screenWidth, screenHeight, ebiten.FilterNearest) pianoImage, _ = ebiten.NewImage(screenWidth, screenHeight, ebiten.FilterDefault)
const ( const (
keyWidth = 24 keyWidth = 24

View File

@ -41,19 +41,19 @@ var (
func init() { func init() {
// Preload images // Preload images
var err error var err error
rightSprite, _, err = ebitenutil.NewImageFromFile("_resources/images/platformer/right.png", ebiten.FilterNearest) rightSprite, _, err = ebitenutil.NewImageFromFile("_resources/images/platformer/right.png", ebiten.FilterDefault)
if err != nil { if err != nil {
panic(err) panic(err)
} }
leftSprite, _, err = ebitenutil.NewImageFromFile("_resources/images/platformer/left.png", ebiten.FilterNearest) leftSprite, _, err = ebitenutil.NewImageFromFile("_resources/images/platformer/left.png", ebiten.FilterDefault)
if err != nil { if err != nil {
panic(err) panic(err)
} }
idleSprite, _, err = ebitenutil.NewImageFromFile("_resources/images/platformer/mainchar.png", ebiten.FilterNearest) idleSprite, _, err = ebitenutil.NewImageFromFile("_resources/images/platformer/mainchar.png", ebiten.FilterDefault)
if err != nil { if err != nil {
panic(err) panic(err)
} }
backgroundImage, _, err = ebitenutil.NewImageFromFile("_resources/images/platformer/background.png", ebiten.FilterNearest) backgroundImage, _, err = ebitenutil.NewImageFromFile("_resources/images/platformer/background.png", ebiten.FilterDefault)
if err != nil { if err != nil {
panic(err) panic(err)
} }

View File

@ -60,7 +60,7 @@ func update(screen *ebiten.Image) error {
func main() { func main() {
var err error var err error
gophersImage, _, err = ebitenutil.NewImageFromFile("_resources/images/gophers.jpg", ebiten.FilterNearest) gophersImage, _, err = ebitenutil.NewImageFromFile("_resources/images/gophers.jpg", ebiten.FilterDefault)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }

View File

@ -90,12 +90,12 @@ var (
) )
func init() { func init() {
img, _, err := ebitenutil.NewImageFromFile("_resources/images/ebiten.png", ebiten.FilterNearest) img, _, err := ebitenutil.NewImageFromFile("_resources/images/ebiten.png", ebiten.FilterDefault)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
w, h := img.Size() w, h := img.Size()
ebitenImage, _ = ebiten.NewImage(w, h, ebiten.FilterNearest) ebitenImage, _ = ebiten.NewImage(w, h, ebiten.FilterDefault)
op := &ebiten.DrawImageOptions{} op := &ebiten.DrawImageOptions{}
op.ColorM.Scale(1, 1, 1, 0.5) op.ColorM.Scale(1, 1, 1, 0.5)
ebitenImage.DrawImage(img, op) ebitenImage.DrawImage(img, op)

View File

@ -42,7 +42,7 @@ var (
func init() { func init() {
var err error var err error
tilesImage, _, err = ebitenutil.NewImageFromFile("_resources/images/tiles.png", ebiten.FilterNearest) tilesImage, _, err = ebitenutil.NewImageFromFile("_resources/images/tiles.png", ebiten.FilterDefault)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }

View File

@ -45,7 +45,7 @@ var (
func init() { func init() {
var err error var err error
uiImage, _, err = ebitenutil.NewImageFromFile("_resources/images/ui.png", ebiten.FilterNearest) uiImage, _, err = ebitenutil.NewImageFromFile("_resources/images/ui.png", ebiten.FilterDefault)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
@ -347,7 +347,7 @@ func (t *TextBox) Draw(dst *ebiten.Image) {
} }
if t.contentBuf == nil { if t.contentBuf == nil {
w, h := t.viewSize() w, h := t.viewSize()
t.contentBuf, _ = ebiten.NewImage(w, h, ebiten.FilterNearest) t.contentBuf, _ = ebiten.NewImage(w, h, ebiten.FilterDefault)
} }
t.contentBuf.Clear() t.contentBuf.Clear()

View File

@ -153,7 +153,7 @@ func main() {
fmt.Printf("Device scale factor: %0.2f\n", ebiten.DeviceScaleFactor()) fmt.Printf("Device scale factor: %0.2f\n", ebiten.DeviceScaleFactor())
var err error var err error
gophersImage, _, err = ebitenutil.NewImageFromFile("_resources/images/gophers.jpg", ebiten.FilterNearest) gophersImage, _, err = ebitenutil.NewImageFromFile("_resources/images/gophers.jpg", ebiten.FilterDefault)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }