move GLFW init from Run to NewWindow

This commit is contained in:
faiface 2016-11-25 23:12:01 +01:00
parent c8dba6aaf1
commit 0fe2df4620
2 changed files with 3 additions and 9 deletions

10
run.go
View File

@ -3,7 +3,6 @@ package pixel
import (
"github.com/faiface/pixel/pixelgl"
"github.com/go-gl/glfw/v3.2/glfw"
"github.com/pkg/errors"
)
// Run is essentialy the "main" function of Pixel. It exists mainly due to the technical limitations of OpenGL and operating systems,
@ -24,14 +23,7 @@ import (
//
// You can spawn any number of goroutines from you run function and interact with Pixel concurrently.
// The only condition is that the Run function must be called from your main function.
func Run(run func()) error {
err := glfw.Init()
if err != nil {
return errors.Wrap(err, "failed to initialize GLFW")
}
func Run(run func()) {
defer glfw.Terminate()
pixelgl.Run(run)
return nil
}

View File

@ -73,6 +73,8 @@ func NewWindow(config WindowConfig) (*Window, error) {
w := &Window{config: config}
err := pixelgl.DoErr(func() error {
glfw.Init()
glfw.WindowHint(glfw.ContextVersionMajor, 3)
glfw.WindowHint(glfw.ContextVersionMinor, 3)
glfw.WindowHint(glfw.OpenGLProfile, glfw.OpenGLCoreProfile)