From c8f8de20f5ff03d94a969e23cfe77d52e10b3ab4 Mon Sep 17 00:00:00 2001 From: xengineering Date: Fri, 21 May 2021 13:45:20 +0200 Subject: Refactor GLFW-related Code --- main.go | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) (limited to 'main.go') 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() } -- cgit v1.2.3-70-g09d2