diff options
author | xengineering <mail2xengineering@protonmail.com> | 2021-05-21 13:45:20 +0200 |
---|---|---|
committer | xengineering <mail2xengineering@protonmail.com> | 2021-05-21 13:45:20 +0200 |
commit | c8f8de20f5ff03d94a969e23cfe77d52e10b3ab4 (patch) | |
tree | 71014001dac06af40de6ff7936b05e4d1536b637 /main.go | |
parent | 0c87cf3f007797714755b309ad31602cedb8af1e (diff) | |
download | stlscope-c8f8de20f5ff03d94a969e23cfe77d52e10b3ab4.tar stlscope-c8f8de20f5ff03d94a969e23cfe77d52e10b3ab4.tar.zst stlscope-c8f8de20f5ff03d94a969e23cfe77d52e10b3ab4.zip |
Refactor GLFW-related Code
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 32 |
1 files changed, 15 insertions, 17 deletions
@@ -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() } |