Skip to content
run.go 1014 B
Newer Older
faiface's avatar
faiface committed

import (
	"github.com/faiface/mainthread"
faiface's avatar
faiface committed
	"github.com/go-gl/glfw/v3.2/glfw"
	"github.com/pkg/errors"
faiface's avatar
faiface committed
// Run is essentially the main function of PixelGL. It exists mainly due to the technical
// limitations of OpenGL and operating systems. In short, all graphics and window manipulating calls
// must be done from the main thread. Run makes this possible.
faiface's avatar
faiface committed
//
faiface's avatar
faiface committed
// Call this function from the main function of your application. This is necessary, so that Run
// runs on the main thread.
faiface's avatar
faiface committed
//
//   func run() {
faiface's avatar
faiface committed
//       // interact with Pixel and PixelGL from here (even concurrently)
faiface's avatar
faiface committed
//   }
//
//   func main() {
//       pixel.Run(run)
//   }
//
faiface's avatar
faiface committed
// You can spawn any number of goroutines from your run function and interact with PixelGL
// concurrently. The only condition is that the Run function is called from your main function.
func Run(run func()) {
	err := glfw.Init()
	if err != nil {
		panic(errors.Wrap(err, "failed to initialize GLFW"))
	}
faiface's avatar
faiface committed
	defer glfw.Terminate()