local glfw = honey.glfw
local gl = honey.gl

local mesh = require 'honey.asset.mesh'


function honey.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)
	honey.window = glfw.CreateWindow(width, height, title, glfw.monitor_NULL, glfw.window_NULL)
	glfw.MakeContextCurrent(honey.window)
	gl.InitGlad()
	gl.Enable(gl.DEPTH_TEST)

	honey.ode.InitODE()
	mesh.init()
end


function honey.loop(update)
	local prevTime = 0
	while glfw.WindowShouldClose(honey.window) == glfw.FALSE do
		local time = glfw.GetTime()
		local dt = time - prevTime
		prevTime = time
		update(dt)
		glfw.SwapBuffers(honey.window)
		glfw.PollEvents()
	end
end


function honey.terminate()
	glfw.Terminate()
end