mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-26 11:48:55 +01:00
ebitenutil: Bug fix: line should use linear filter
This commit is contained in:
parent
d832f1e3cb
commit
95906e9630
@ -21,11 +21,16 @@ import (
|
|||||||
"github.com/hajimehoshi/ebiten"
|
"github.com/hajimehoshi/ebiten"
|
||||||
)
|
)
|
||||||
|
|
||||||
var emptyImage *ebiten.Image
|
var (
|
||||||
|
emptyNearestImage *ebiten.Image
|
||||||
|
emptyLinearImage *ebiten.Image
|
||||||
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
emptyImage, _ = ebiten.NewImage(16, 16, ebiten.FilterNearest)
|
emptyNearestImage, _ = ebiten.NewImage(16, 16, ebiten.FilterNearest)
|
||||||
_ = emptyImage.Fill(color.White)
|
_ = 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) {
|
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.
|
// 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) {
|
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)
|
length := math.Hypot(x2-x1, y2-y1)
|
||||||
|
|
||||||
op := &ebiten.DrawImageOptions{}
|
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.Rotate(math.Atan2(y2-y1, x2-x1))
|
||||||
op.GeoM.Translate(x1, y1)
|
op.GeoM.Translate(x1, y1)
|
||||||
op.ColorM.Scale(colorScale(clr))
|
op.ColorM.Scale(colorScale(clr))
|
||||||
_ = dst.DrawImage(emptyImage, op)
|
_ = dst.DrawImage(emptyLinearImage, op)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DrawRect draws a rectangle on the given destination dst.
|
// DrawRect draws a rectangle on the given destination dst.
|
||||||
//
|
//
|
||||||
// DrawRect is intended to be used mainly for debugging or prototyping purpose.
|
// 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) {
|
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 := &ebiten.DrawImageOptions{}
|
||||||
op.GeoM.Scale(width/float64(ew), height/float64(eh))
|
op.GeoM.Scale(width/float64(ew), height/float64(eh))
|
||||||
op.GeoM.Translate(x, y)
|
op.GeoM.Translate(x, y)
|
||||||
op.ColorM.Scale(colorScale(clr))
|
op.ColorM.Scale(colorScale(clr))
|
||||||
_ = dst.DrawImage(emptyImage, op)
|
_ = dst.DrawImage(emptyNearestImage, op)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user