-
Notifications
You must be signed in to change notification settings - Fork 0
/
glfw.go
54 lines (46 loc) · 1.22 KB
/
glfw.go
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
47
48
49
50
51
52
53
54
package main
import "fmt"
import "os"
import glfw "github.com/go-gl/glfw3"
import "github.com/go-gl/gl"
func initGlfw() {
if !glfw.Init() {
panic("Can't init glfw")
os.Exit(1)
}
}
func errorCallback(err glfw.ErrorCode, desc string) {
fmt.Printf("%v: %v\n", err, desc)
}
func createWindow(width, height int) *glfw.Window {
glfw.SetErrorCallback(errorCallback)
glfw.WindowHint(glfw.OpenglForwardCompatible, glfw.True)
glfw.WindowHint(glfw.OpenglProfile, glfw.OpenglCoreProfile)
glfw.WindowHint(glfw.ContextVersionMajor, 3)
glfw.WindowHint(glfw.ContextVersionMinor, 2)
window, err := glfw.CreateWindow(width, height, "Gon", nil, nil)
if err != nil {
fmt.Println(err)
panic("Unable to create window")
}
window.MakeContextCurrent()
if gl.Init() != 0 {
fmt.Println("error initializing OpenGL")
}
window.SetSizeCallback(onResize)
window.SetKeyCallback(onKey)
glfw.SwapInterval(1)
gl.LineWidth(2)
return window
}
func terminateGlfw() {
glfw.Terminate()
}
func onResize(window *glfw.Window, w, h int) {
gl.Viewport(0, 0, w, h)
}
func onKey(window *glfw.Window, key glfw.Key, scancode int, action glfw.Action, mods glfw.ModifierKey) {
if key == glfw.KeyEscape && action == glfw.Press {
window.SetShouldClose(true)
}
}