summaryrefslogtreecommitdiff
path: root/main.go
blob: b4d52cfeeffc322dfd47afa8dc4f03004572bedb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// vim: shiftwidth=4 tabstop=4 noexpandtab

package main

import (
	"runtime"
	"log"
	"flag"
)

func main() {

	// read command line arguments
	var stlFilePath string
	parseFlags(&stlFilePath)

	// parse STL file
	stl, err := ReadBinaryStlFile(stlFilePath)
	if err != nil {
		log.Fatal(err)
	}
	vertices = stl.toVertices()

	// lock this program to one OS thread (details: https://golang.org/pkg/runtime/#LockOSThread)
	log.Println("Locking OS thread")
	runtime.LockOSThread()

	// initialize application (includes GLFW/window)
	var app App = newApp(&stl)
	defer app.terminate()  // GLFW needs to be terminated!

	// initialize graphics
	var graphics Graphics = newGraphics()
	app.graphics = &graphics  // connect graphics to the app

	// main loop
	for !app.window.ShouldClose() {
		graphics.draw()
		app.handle()
	}
}

func parseFlags(stlFilePath *string) {
	flag.StringVar(stlFilePath, "file", "myfile.stl", "path to the binary STL file")
	flag.Parse()
}