summaryrefslogtreecommitdiff
path: root/demo/vector/main.lua
blob: 28090c6a3ee58f93187f3e6c4e38b65e8a6fc7a8 (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
49
50
51
52
53
54
55
56
57
58
59
require 'common'

local glfw = honey.glfw
local nvg = honey.nvg


local vg
local papyrus

function honey.init()
	vg = nvg.CreateContext()
	papyrus = nvg.CreateFont(vg, "Papyrus", "PAPYRUS.ttf")
	if (papyrus == -1) then error("failed to find font") end
end


local time = 0
local frames = 0
function honey.update(dt)
	if glfw.GetKey(glfw.win, glfw.KEY_ESCAPE) == glfw.PRESS then
		glfw.SetWindowShouldClose(glfw.win, true)
	end
	
	time = time + dt
	frames = frames + 1
	if time > 5 then
		print('fps:', frames/5)
		frames = 0
		time = time - 5
	end
end


function honey.draw()
	nvg.BeginFrame(vg, 640, 480, 1.0)

	nvg.StrokeColor(vg, nvg.RGBf(1, 1, 1))
	nvg.FontFace(vg, "Papyrus")
	nvg.Text(vg, 50, 50, "Hello, world! c:")


	nvg.StrokeWidth(vg, 20)
	nvg.StrokeColor(vg, nvg.RGBf(1, 0, 0))

	local w = 640
	local h = 480

	nvg.BeginPath(vg)
	nvg.MoveTo(vg, w*0.2, h*.5)
	nvg.LineTo(vg, w*0.4, h * (0.5 + 0.5*math.sin(math.pi * time)));
	nvg.LineTo(vg, w*0.6, h * (0.5 - 0.5*math.sin(math.pi * time)));
	nvg.LineTo(vg, w*0.8, h*.5)
	nvg.Stroke(vg)

	nvg.EndFrame(vg)
end


honey.run()