main.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // Copyright 2018 The Ebiten Authors
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package main
  15. import (
  16. "bytes"
  17. "image"
  18. _ "image/png"
  19. "log"
  20. "github.com/hajimehoshi/ebiten/v2"
  21. "github.com/hajimehoshi/ebiten/v2/ebitenutil"
  22. "github.com/hajimehoshi/ebiten/v2/examples/resources/images"
  23. )
  24. const (
  25. screenWidth = 640
  26. screenHeight = 480
  27. )
  28. var (
  29. ebitenImage *ebiten.Image
  30. )
  31. type Game struct {
  32. }
  33. func (g *Game) Update() error {
  34. return nil
  35. }
  36. func (g *Game) Draw(screen *ebiten.Image) {
  37. ebitenutil.DebugPrint(screen, "Nearest Filter (default) VS Linear Filter")
  38. op := &ebiten.DrawImageOptions{}
  39. op.GeoM.Scale(4, 4)
  40. op.GeoM.Translate(64, 64)
  41. // By default, nearest filter is used.
  42. screen.DrawImage(ebitenImage, op)
  43. op = &ebiten.DrawImageOptions{}
  44. op.GeoM.Scale(4, 4)
  45. op.GeoM.Translate(64, 64+240)
  46. // Specify linear filter.
  47. op.Filter = ebiten.FilterLinear
  48. screen.DrawImage(ebitenImage, op)
  49. }
  50. func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {
  51. return screenWidth, screenHeight
  52. }
  53. func main() {
  54. // Decode an image from the image file's byte slice.
  55. img, _, err := image.Decode(bytes.NewReader(images.Ebiten_png))
  56. if err != nil {
  57. log.Fatal(err)
  58. }
  59. ebitenImage = ebiten.NewImageFromImage(img)
  60. ebiten.SetWindowSize(screenWidth, screenHeight)
  61. ebiten.SetWindowTitle("Filter (Ebitengine Demo)")
  62. if err := ebiten.RunGame(&Game{}); err != nil {
  63. log.Fatal(err)
  64. }
  65. }