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 ( import (
"github.com/faiface/pixel/pixelgl" "github.com/faiface/pixel/pixelgl"
"github.com/go-gl/glfw/v3.2/glfw" "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, // 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. // 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. // The only condition is that the Run function must be called from your main function.
func Run(run func()) error { func Run(run func()) {
err := glfw.Init()
if err != nil {
return errors.Wrap(err, "failed to initialize GLFW")
}
defer glfw.Terminate() defer glfw.Terminate()
pixelgl.Run(run) pixelgl.Run(run)
return nil
} }

View File

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