func main(f func(App)) { runtime.LockOSThread() C.createWindow() // TODO: send lifecycle events when e.g. the X11 window is iconified or moved off-screen. sendLifecycle(lifecycle.StageFocused) donec := make(chan struct{}) go func() { f(app{}) close(donec) }() // TODO: can we get the actual vsync signal? ticker := time.NewTicker(time.Second / 60) defer ticker.Stop() tc := ticker.C for { select { case <-donec: return case <-gl.WorkAvailable: gl.DoWork() case <-endPaint: C.swapBuffers() tc = ticker.C case <-tc: tc = nil eventsIn <- paint.Event{} } C.processEvents() } }
func newWindow(opts *screen.NewWindowOptions) (screen.Window, error) { var hwnd C.HWND hr := C.createWindow(&hwnd) if hr != C.S_OK { return nil, winerror("error creating window", hr) } return &window{ hwnd: hwnd, pump: pump.Make(), }, nil }
func main(f func(App)) { runtime.LockOSThread() var worker gl.Worker glctx, worker = gl.NewContext() workAvailable := worker.WorkAvailable() C.createWindow() // TODO: send lifecycle events when e.g. the X11 window is iconified or moved off-screen. theApp.sendLifecycle(lifecycle.StageFocused) // TODO: translate X11 expose events to shiny paint events, instead of // sending this synthetic paint event as a hack. theApp.eventsIn <- paint.Event{} donec := make(chan struct{}) go func() { f(theApp) close(donec) }() // TODO: can we get the actual vsync signal? ticker := time.NewTicker(time.Second / 60) defer ticker.Stop() var tc <-chan time.Time for { select { case <-donec: return case <-workAvailable: worker.DoWork() case <-theApp.publish: C.swapBuffers() tc = ticker.C case <-tc: tc = nil theApp.publishResult <- PublishResult{} } C.processEvents() } }
func (this *Window) _createWindow() { C.createWindow(unsafe.Pointer(this)) }