]> git.lizzy.rs Git - dragonblocks3d-lua.git/blob - modules/RenderEngine/src/window.lua
Yaw & Pitch bound to mouse input
[dragonblocks3d-lua.git] / modules / RenderEngine / src / window.lua
1 function RenderEngine:framebuffer_size_callback(_, width, height)
2         gl.viewport(0, 0, width, height)
3         self.window_width, self.window_height = width, height
4         self:update_projection_matrix()
5 end
6
7 function RenderEngine:cursor_pos_callback(_, x, y)
8         local last_x, last_y = self.cursor_x or x, self.cursor_y or y
9         self.cursor_delta_x, self.cursor_delta_y = x - last_x, y - last_y
10         self.cursor_x, self.cursor_y = x, y
11 end
12
13 function RenderEngine:init_glfw()
14         glfw.window_hint("context version major", 3)
15         glfw.window_hint("context version minor", 3)
16         glfw.window_hint("opengl profile", "core")
17 end
18
19 function RenderEngine:create_window()
20         self.window = glfw.create_window(500, 500, "Unnamed Window")
21         glfw.make_context_current(self.window)
22         glfw.set_input_mode(self.window, "cursor", "disabled")
23         glfw.set_framebuffer_size_callback(self.window, function (...) self:framebuffer_size_callback(...) end) 
24         glfw.set_cursor_pos_callback(self.window, function (...) self:cursor_pos_callback(...) end)     
25 end
26
27 function RenderEngine:set_window_title(title)
28         glfw.set_window_title(self.window, title)
29 end
30
31 function RenderEngine:set_window_pos(x, y)
32         glfw.set_window_pos(self.window, x, y)
33 end
34
35 function RenderEngine:set_window_size(width, height)
36         glfw.set_window_size(self.window, width, height)
37 end