move GLFW init from Run to NewWindow
This commit is contained in:
parent
c8dba6aaf1
commit
0fe2df4620
10
run.go
10
run.go
|
@ -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
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
||||||
|
|
Loading…
Reference in New Issue