summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'main.go')
-rw-r--r--main.go32
1 files changed, 15 insertions, 17 deletions
diff --git a/main.go b/main.go
index 35a4704..e2d6e43 100644
--- a/main.go
+++ b/main.go
@@ -6,18 +6,19 @@ import (
"runtime"
"log"
"flag"
-
- "github.com/go-gl/glfw/v3.3/glfw"
)
-var (
- stlFilePath string
-)
+func init() {
+ // lock this program to one OS thread (details: https://golang.org/pkg/runtime/#LockOSThread)
+ log.Println("Locking OS thread")
+ runtime.LockOSThread()
+}
func main() {
// read command line arguments
- parseFlags()
+ var stlFilePath string
+ parseFlags(&stlFilePath)
// parse STL file
_, err := ReadBinaryStlFile(stlFilePath)
@@ -25,13 +26,9 @@ func main() {
log.Fatal(err)
}
- // lock this program to one OS thread (details: https://golang.org/pkg/runtime/#LockOSThread)
- log.Println("Locking OS thread")
- runtime.LockOSThread()
-
- // init GLFW and assert termination at end of main
- window := initGlfw()
- defer glfw.Terminate()
+ // initialize application (includes GLFW/window)
+ var app App = newApp()
+ defer app.terminate() // GLFW needs to be terminated!
// init OpenGL
program := initOpenGL()
@@ -39,12 +36,13 @@ func main() {
vao := makeVao(triangle)
// main loop
- for !window.ShouldClose() {
- draw(vao, window, program)
+ for !app.window.ShouldClose() {
+ app.handle()
+ draw(vao, program)
}
}
-func parseFlags() {
- flag.StringVar(&stlFilePath, "file", "myfile.stl", "path to the binary STL file")
+func parseFlags(stlFilePath *string) {
+ flag.StringVar(stlFilePath, "file", "myfile.stl", "path to the binary STL file")
flag.Parse()
}