From ee9c6a6b6e4cf8aa74af0e109b2e64c8b8d0648d Mon Sep 17 00:00:00 2001
From: faiface <faiface@ksp.sk>
Date: Fri, 25 Nov 2016 17:45:24 +0100
Subject: [PATCH] replace Init and Quit with Run

---
 init.go | 35 -----------------------------------
 run.go  | 37 +++++++++++++++++++++++++++++++++++++
 2 files changed, 37 insertions(+), 35 deletions(-)
 delete mode 100644 init.go
 create mode 100644 run.go

diff --git a/init.go b/init.go
deleted file mode 100644
index ff33fb4..0000000
--- a/init.go
+++ /dev/null
@@ -1,35 +0,0 @@
-package pixel
-
-import (
-	"github.com/faiface/pixel/pixelgl"
-	"github.com/go-gl/glfw/v3.2/glfw"
-	"github.com/pkg/errors"
-)
-
-// Init initializes Pixel library. Call this function before using any of Pixel's functionality.
-//
-// If the initialization fails, an error is returned.
-func Init() error {
-	err := pixelgl.DoErr(func() error {
-		return glfw.Init()
-	})
-	if err != nil {
-		return errors.Wrap(err, "initializing GLFW failed")
-	}
-	return nil
-}
-
-// MustInit initializes Pixel library and panics when the initialization fails.
-func MustInit() {
-	err := Init()
-	if err != nil {
-		panic(err)
-	}
-}
-
-// Quit terminates Pixel library. Call this function when you're done with Pixel.
-func Quit() {
-	pixelgl.Do(func() {
-		glfw.Terminate()
-	})
-}
diff --git a/run.go b/run.go
new file mode 100644
index 0000000..50ae2a5
--- /dev/null
+++ b/run.go
@@ -0,0 +1,37 @@
+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,
+// in short, all graphics and window manipulating calls must be done from the main thread. Run makes this possible.
+//
+// Call this function from the main function of your application. This is necessary, so that Run runs on the main thread.
+//
+//   func run() {
+//       window := pixel.NewWindow(...)
+//       for {
+//           // your game's main loop
+//       }
+//   }
+//
+//   func main() {
+//       pixel.Run(run)
+//   }
+//
+// 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")
+	}
+	defer glfw.Terminate()
+
+	pixelgl.Run(run)
+
+	return nil
+}
-- 
GitLab