示例#1
0
func drawTile(wg *sync.WaitGroup, w screen.Window, pool *tilePool, origin image.Point, x, y int) {
	defer wg.Done()
	tp := image.Point{
		(x + origin.X) >> 8,
		(y + origin.Y) >> 8,
	}
	tex, err := pool.get(tp)
	if err != nil {
		log.Println(err)
		return
	}
	screen.Copy(w, image.Point{x, y}, tex, tileBounds, draw.Src, nil)
}
示例#2
0
文件: main.go 项目: morero/exp
func main() {
	driver.Main(func(s screen.Screen) {
		w, err := s.NewWindow(nil)
		if err != nil {
			log.Fatal(err)
		}
		defer w.Release()

		winSize := image.Point{256, 256}
		b, err := s.NewBuffer(winSize)
		if err != nil {
			log.Fatal(err)
		}
		defer b.Release()
		drawGradient(b.RGBA())

		t, err := s.NewTexture(winSize)
		if err != nil {
			log.Fatal(err)
		}
		defer t.Release()
		t.Upload(image.Point{}, b, b.Bounds())

		var sz size.Event
		for {
			e := w.NextEvent()

			// This print message is to help programmers learn what events this
			// example program generates. A real program shouldn't print such
			// messages; they're not important to end users.
			format := "got %#v\n"
			if _, ok := e.(fmt.Stringer); ok {
				format = "got %v\n"
			}
			fmt.Printf(format, e)

			switch e := e.(type) {
			case lifecycle.Event:
				if e.To == lifecycle.StageDead {
					return
				}

			case key.Event:
				if e.Code == key.CodeEscape {
					return
				}

			case paint.Event:
				w.Fill(sz.Bounds(), blue0, screen.Src)
				w.Fill(sz.Bounds().Inset(10), blue1, screen.Src)
				w.Upload(image.Point{}, b, b.Bounds())
				w.Fill(image.Rect(50, 50, 350, 120), red, screen.Over)
				screen.Copy(w, image.Point{150, 100}, t, t.Bounds(), screen.Over, nil)
				w.Draw(f64.Aff3{
					+cos30, -sin30, 100,
					+sin30, +cos30, 200,
				}, t, t.Bounds(), screen.Over, nil)
				w.Publish()

			case size.Event:
				sz = e

			case error:
				log.Print(e)
			}
		}
	})
}