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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
local Node = require('Node')
local FPSCamera = require('FPSCamera')
local SpatialShader = require('SpatialShader')
local Primitives = require('Primitives')
-- local ScreenQuad = require('ScreenQuad')
local MeshInstance = require('MeshInstance')
FPSCamera.movement_speed = 5
honey.input.key.bind(honey.input.key.escape, honey.exit)
local buffer = false
honey.input.key.bind(honey.input.key.f,
function(action)
if action == 1 then
buffer = not buffer
end
end)
local tex = honey.texture.load('lowres.png',
{minFilter='nearest', magFilter='nearest'})
local cairo = honey.cairo()
cairo:setColor(1, 1, 1)
cairo:moveTo(1024,0)
cairo:lineTo(0,1024)
cairo:stroke()
cairo:setLineWidth(20);
cairo:arc(512, 512, 256);
cairo:stroke()
cairo:updateTexture()
local sceneRoot = Node.new()
local shader = SpatialShader.new(cairo:getTexture())
local lightDirection = honey.glm.vec3{1,1,1}
lightDirection:normalize()
shader:setVec3('directional_lights[0].direction', lightDirection)
shader:setVec3('directional_lights[0].color', honey.glm.vec3{0,1,0})
local meshes = honey.loadMesh('Suzanne.obj')
local suzanne = MeshInstance.new(sceneRoot,
honey.glm.vec3{0,0,3},
honey.glm.vec3{0,math.pi,0},
honey.glm.vec3{0.5,1,0.5},
meshes[1],
shader)
print(suzanne.mesh)
--local plane = MeshInstance.new(suzanne,
-- honey.glm.vec3{1,0,0},
-- honey.glm.vec3{0,0,0},
-- honey.glm.vec3{1,1,1},
-- Primitives.plane(4,4),
-- shader)
MeshInstance.new(sceneRoot,
honey.glm.vec3{0,0,3},
honey.glm.vec3{0,0,0},
honey.glm.vec3{1,1,1},
Primitives.plane(4,4),
shader)
MeshInstance.new(sceneRoot,
honey.glm.vec3{4,0,3},
honey.glm.vec3{0,math.pi,0},
honey.glm.vec3{1,1,1},
Primitives.plane(4,4),
shader)
suzanne.update = function(self, dt)
self:rotate('y', dt)
end
local total_frames = 0
local total_time = 0
honey.window.set_size(640, 480)
function honey.update(dt)
total_time = total_time + dt
FPSCamera:update(dt)
sceneRoot:updateCascade(dt)
if total_time > 1 then
print('FPS: '..tostring(total_frames/total_time))
print(cairo)
total_time = 0
total_frames = 0
end
end
function draw_suzanne()
sceneRoot:drawCascade(FPSCamera)
end
function honey.draw()
total_frames = total_frames + 1
if buffer then
honey.set_framebuffer(ScreenQuad.fb)
honey.set_viewport_size(480,640)
honey.clear_color(honey.glm.vec4(), true, true, false)
honey.enable_depth_test(true)
draw_suzanne()
honey.set_framebuffer(0)
honey.set_viewport_size(640, 480)
honey.enable_depth_test(false)
honey.clear_color(honey.glm.vec4{0,0,1,1}, true, false, false)
ScreenQuad:draw()
else
honey.clear_color(honey.glm.vec4{1,1,0,1}, true, true, false)
honey.set_viewport_size(640, 480)
honey.enable_depth_test(true)
draw_suzanne()
end
end
|