/
glfw.go
54 lines (44 loc) · 839 Bytes
/
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 glfw
// #cgo pkg-config: glfw3
// #include <GLFW/glfw3.h>
import "C"
import (
"errors"
"runtime"
)
const (
Press = C.GLFW_PRESS
Release = C.GLFW_RELEASE
Repeat = C.GLFW_REPEAT
)
func init() {
runtime.LockOSThread()
}
// This function must be called from the main thread (i.e. from either init() or main()).
func Init() error {
if C.glfwInit() == C.GL_FALSE {
return errors.New("Failed to initialize GLFW.")
}
return nil
}
func Terminate() {
C.glfwTerminate()
}
func GetCurrentContext() *Window {
windows.Lock()
defer windows.Unlock()
return windows.m[C.glfwGetCurrentContext()]
}
func MakeContextCurrent(w *Window) {
if w == nil {
C.glfwMakeContextCurrent(nil)
} else {
C.glfwMakeContextCurrent(w.w)
}
}
func WaitEvents() {
C.glfwWaitEvents()
}
func PostEmptyEvent() {
C.glfwPostEmptyEvent()
}