summaryrefslogtreecommitdiff
path: root/honey.bak/init.lua
blob: 6cf880181e7f1c0d27a6e21cd4308af9cc51b2ca (plain)
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
local glfw = honey.glfw
local gl = honey.gl
local window = require 'honey.window'

local module = {}
setmetatable(module, {__index=_G})
setfenv(1, module)


function init(width, height, title)
	local width = width or 640
	local height = height or 480
	local title = title or "honey3d"

	glfw.Init()
	glfw.WindowHint(glfw.OPENGL_PROFILE, glfw.OPENGL_CORE_PROFILE)
	glfw.WindowHint(glfw.CONTEXT_VERSION_MAJOR, 4)
	glfw.WindowHint(glfw.CONTEXT_VERSION_MINOR, 1)
	local window = honey.Window(width, height, title)
	glfw.MakeContextCurrent(window.win)
	gl.InitGlad()
	gl.Enable(gl.DEPTH_TEST)

	honey.ode.InitODE()

	return window
end


function loop(window, update)
	local prevTime = 0
	while not window:shouldClose() do
		local time = glfw.GetTime()
		local dt = time - prevTime
		prevTime = time
		update(dt)
		window:swapBuffers()
		glfw.PollEvents()
	end
end


function terminate()
	glfw.Terminate()
end


return module