forked from redvers/pony-glfw3
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.pony
56 lines (42 loc) · 1.52 KB
/
main.pony
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
55
56
use "Glfw3"
actor Main is GLFWWindowListener
let window: NullablePointer[GLFWwindow]
let window_user_object: GLFWWindowUserObject
let env: Env
new create(env': Env) =>
env = env'
env.out.print("Hello Glfw3")
if (Glfw3.glfwInit() == GLFWTrue()) then
env.out.print("GLFW initialized version: " + Glfw3.glfwGetVersionString())
window = Glfw3.glfwCreateWindow(640, 480, "My Title")
window_user_object = GLFWWindowUserObject(window)
window_user_object.set_listener(this)
window_user_object.enable_key_callback()
Glfw3.glfwMakeContextCurrent(window)
// GL commands here...
loop()
else
env.out.print("Error: could not init GLFW")
env.out.print(Glfw3Helper.get_error_description())
window = NullablePointer[GLFWwindow].none()
window_user_object = GLFWWindowUserObject.none()
end
fun _final() =>
Glfw3.glfwDestroyWindow(window)
Glfw3.glfwTerminate()
be loop() =>
// Required during behavior execution because needs to happen on the thread we'll run GL commands from
Glfw3.glfwMakeContextCurrent(window)
Glfw3.glfwSwapInterval(1)
// GL commands here...
Glfw3.glfwSwapBuffers(window)
Glfw3.glfwPollEvents()
if (Glfw3.glfwWindowShouldClose(window) == GLFWFalse()) then
loop()
end
fun key_callback(key: I32, scancode: I32, action: I32, mods: I32) =>
match key
| GLFWKeyEscape()
| GLFWKeyQ() => Glfw3.glfwSetWindowShouldClose(window, GLFWTrue())
end
env.out.print("key: " + key.string())