-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWindow.t
More file actions
58 lines (46 loc) · 1.24 KB
/
Window.t
File metadata and controls
58 lines (46 loc) · 1.24 KB
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
57
58
local std = require "util/std"
require "lib/gl"
local struct Window(std.Object) {
_window: &glfw.window
}
terra Window.methods.init()
var self: Window
self._window = nil
return self
end
terra Window.methods.create(width: uint, height: uint, name: rawstring): Window
var self = Window.init()
self._window = glfw.CreateWindow(width, height, name, nil, nil)
if self:isAlive() then
self:makeCurrent()
glew.Init()
glfw.SwapInterval(0)
end
return self
end
terra Window.methods.create(): Window
return Window.create(800, 600, "Untitled window")
end
terra Window:__destruct()
glfw.DestroyWindow(self._window)
end
terra Window:isAlive()
return self._window ~= nil
end
terra Window:shouldClose()
if not self:isAlive() then return true end
return glfw.WindowShouldClose(self._window) ~= 0
end
terra Window.methods.pollEvents()
glfw.PollEvents()
end
terra Window:makeCurrent()
glfw.MakeContextCurrent(self._window)
end
terra Window:swapBuffers()
glfw.SwapBuffers(self._window)
end
terra Window:getKey(key: int)
return glfw.GetKey(self._window, key) == glfw.PRESS
end
return Window