Exemple #1
0
func main() {
	flag.Parse()
	if *cpuprofile != "" {
		f, err := os.Create(*cpuprofile)
		if err != nil {
			log.Fatal(err)
		}
		pprof.StartCPUProfile(f)
		go func() {
			time.Sleep(10 * time.Second)
			pprof.StopCPUProfile()
		}()
	}

	app.Main(func(a app.App) {
		var logdbg *time.Ticker
		var glctx gl.Context
		for ev := range a.Events() {
			switch ev := a.Filter(ev).(type) {
			case lifecycle.Event:
				switch ev.Crosses(lifecycle.StageVisible) {
				case lifecycle.CrossOn:
					logdbg = time.NewTicker(time.Second)
					go func() {
						for range logdbg.C {
							log.Printf("fps=%-4v underruns=%-4v buflen=%-4v tickavg=%-12s drift=%s\n",
								fps, al.Underruns(), al.BufLen(), al.TickAverge(), al.DriftApprox())
						}
					}()
					glctx = ev.DrawContext.(gl.Context)
					onStart(glctx)
					al.Start()
				case lifecycle.CrossOff:
					glctx = nil
					logdbg.Stop()
					al.Stop()
					al.CloseDevice()
				}
			case touch.Event:
				env.Touch(ev)
			case size.Event:
				if glctx == nil {
					a.Send(ev)
				} else {
					onLayout(ev)
				}
			case paint.Event:
				if glctx != nil {
					onPaint(glctx)
					a.Publish()
					a.Send(paint.Event{})
				}
			}
		}
	})
}
Exemple #2
0
func main() {
	const buffers = 1
	if err := al.OpenDevice(buffers); err != nil {
		log.Fatal(err)
	}
	al.Start()

	sine := snd.Sine()
	// mod is a modulator; try replacing the nil argument to
	// the oscillator with this.
	// mod := snd.NewOscil(sine, 200, nil)
	osc := snd.NewOscil(sine, 440, nil) // oscillator
	al.AddSource(osc)

	for range time.Tick(time.Second) {
		log.Printf("underruns=%-4v buflen=%-4v tickavg=%-12s drift=%s\n",
			al.Underruns(), al.BufLen(), al.TickAverge(), al.DriftApprox())
	}
}