2017-02-22 13:44:38 -06:00
|
|
|
package pixelgl
|
2016-11-25 10:45:24 -06:00
|
|
|
|
|
|
|
import (
|
2017-01-20 10:45:19 -06:00
|
|
|
"github.com/faiface/mainthread"
|
2016-11-25 10:45:24 -06:00
|
|
|
"github.com/go-gl/glfw/v3.2/glfw"
|
2017-01-25 20:33:48 -06:00
|
|
|
"github.com/pkg/errors"
|
2016-11-25 10:45:24 -06:00
|
|
|
)
|
|
|
|
|
2017-03-15 16:55:43 -05:00
|
|
|
// Run is essentialy 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.
|
2016-11-25 10:45:24 -06:00
|
|
|
//
|
2017-03-15 16:55:43 -05:00
|
|
|
// Call this function from the main function of your application. This is necessary, so that Run
|
|
|
|
// runs on the main thread.
|
2016-11-25 10:45:24 -06:00
|
|
|
//
|
|
|
|
// func run() {
|
2017-03-15 16:55:43 -05:00
|
|
|
// // interact with Pixel and PixelGL from here (even concurrently)
|
2016-11-25 10:45:24 -06:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// func main() {
|
|
|
|
// pixel.Run(run)
|
|
|
|
// }
|
|
|
|
//
|
2017-03-15 16:55:43 -05:00
|
|
|
// 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.
|
2016-11-25 16:12:01 -06:00
|
|
|
func Run(run func()) {
|
2017-01-25 20:33:48 -06:00
|
|
|
err := glfw.Init()
|
|
|
|
if err != nil {
|
|
|
|
panic(errors.Wrap(err, "failed to initialize GLFW"))
|
|
|
|
}
|
2016-11-25 10:45:24 -06:00
|
|
|
defer glfw.Terminate()
|
2017-01-20 10:45:19 -06:00
|
|
|
mainthread.Run(run)
|
2016-11-25 10:45:24 -06:00
|
|
|
}
|