From 95906e96302a0a4723d22d053cc799b306d509dc Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 3 Dec 2017 23:11:39 +0900 Subject: [PATCH] ebitenutil: Bug fix: line should use linear filter --- ebitenutil/shapes.go | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/ebitenutil/shapes.go b/ebitenutil/shapes.go index 92b85cfd9..ba68af4bb 100644 --- a/ebitenutil/shapes.go +++ b/ebitenutil/shapes.go @@ -21,11 +21,16 @@ import ( "github.com/hajimehoshi/ebiten" ) -var emptyImage *ebiten.Image +var ( + emptyNearestImage *ebiten.Image + emptyLinearImage *ebiten.Image +) func init() { - emptyImage, _ = ebiten.NewImage(16, 16, ebiten.FilterNearest) - _ = emptyImage.Fill(color.White) + emptyNearestImage, _ = ebiten.NewImage(16, 16, ebiten.FilterNearest) + _ = emptyNearestImage.Fill(color.White) + emptyLinearImage, _ = ebiten.NewImage(16, 16, ebiten.FilterLinear) + _ = emptyLinearImage.Fill(color.White) } func colorScale(clr color.Color) (rf, gf, bf, af float64) { @@ -45,7 +50,7 @@ func colorScale(clr color.Color) (rf, gf, bf, af float64) { // // DrawLine is intended to be used mainly for debugging or prototyping purpose. func DrawLine(dst *ebiten.Image, x1, y1, x2, y2 float64, clr color.Color) { - ew, eh := emptyImage.Size() + ew, eh := emptyLinearImage.Size() length := math.Hypot(x2-x1, y2-y1) op := &ebiten.DrawImageOptions{} @@ -53,18 +58,18 @@ func DrawLine(dst *ebiten.Image, x1, y1, x2, y2 float64, clr color.Color) { op.GeoM.Rotate(math.Atan2(y2-y1, x2-x1)) op.GeoM.Translate(x1, y1) op.ColorM.Scale(colorScale(clr)) - _ = dst.DrawImage(emptyImage, op) + _ = dst.DrawImage(emptyLinearImage, op) } // DrawRect draws a rectangle on the given destination dst. // // DrawRect is intended to be used mainly for debugging or prototyping purpose. func DrawRect(dst *ebiten.Image, x, y, width, height float64, clr color.Color) { - ew, eh := emptyImage.Size() + ew, eh := emptyNearestImage.Size() op := &ebiten.DrawImageOptions{} op.GeoM.Scale(width/float64(ew), height/float64(eh)) op.GeoM.Translate(x, y) op.ColorM.Scale(colorScale(clr)) - _ = dst.DrawImage(emptyImage, op) + _ = dst.DrawImage(emptyNearestImage, op) }