mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 11:18:54 +01:00
ebitenutil: Give up using linear filter for lines
The edges of a source texture would be unexpectable with linear filterling
This commit is contained in:
parent
95906e9630
commit
6bbf6c53ce
@ -22,15 +22,14 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
emptyNearestImage *ebiten.Image
|
emptyImage *ebiten.Image
|
||||||
emptyLinearImage *ebiten.Image
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
emptyNearestImage, _ = ebiten.NewImage(16, 16, ebiten.FilterNearest)
|
// Filter must be 'nearest' filter.
|
||||||
_ = emptyNearestImage.Fill(color.White)
|
// Linear filtering would make edges blurred.
|
||||||
emptyLinearImage, _ = ebiten.NewImage(16, 16, ebiten.FilterLinear)
|
emptyImage, _ = ebiten.NewImage(16, 16, ebiten.FilterNearest)
|
||||||
_ = emptyLinearImage.Fill(color.White)
|
_ = emptyImage.Fill(color.White)
|
||||||
}
|
}
|
||||||
|
|
||||||
func colorScale(clr color.Color) (rf, gf, bf, af float64) {
|
func colorScale(clr color.Color) (rf, gf, bf, af float64) {
|
||||||
@ -50,7 +49,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 := emptyLinearImage.Size()
|
ew, eh := emptyImage.Size()
|
||||||
length := math.Hypot(x2-x1, y2-y1)
|
length := math.Hypot(x2-x1, y2-y1)
|
||||||
|
|
||||||
op := &ebiten.DrawImageOptions{}
|
op := &ebiten.DrawImageOptions{}
|
||||||
@ -58,18 +57,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(emptyLinearImage, op)
|
_ = dst.DrawImage(emptyImage, 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 := emptyNearestImage.Size()
|
ew, eh := emptyImage.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(emptyNearestImage, op)
|
_ = dst.DrawImage(emptyImage, op)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user