-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathmain.lua
More file actions
82 lines (70 loc) · 2.3 KB
/
main.lua
File metadata and controls
82 lines (70 loc) · 2.3 KB
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
local menori = require 'menori'
local scene_iterator = 1
local example_list = {
{ title = "Minimal", path = "examples.minimal.scene" },
{ title = "Basic Lighting", path = "examples.basic_lighting.scene" },
{ title = "SSAO", path = "examples.SSAO.scene" },
{ title = "RaycastBVH", path = "examples.raycast_bvh.scene" },
{ title = "CollisionDemo", path = "examples.сollision_demo.scene" },
}
for _, v in ipairs(example_list) do
local Scene = require(v.path)
menori.app:add_scene(v.title, Scene())
end
menori.app:set_scene('Minimal')
local w, h = love.graphics.getDimensions()
local canvas = love.graphics.newCanvas(w, h)
local canvas_sprite = menori.SpriteLoader.from_image(canvas)
canvas_sprite.px = 0.5
canvas_sprite.py = 0.5
function love.draw()
love.graphics.setCanvas({canvas, depth = true})
menori.app:render()
local font = love.graphics.getFont()
love.graphics.setColor(1, 0.5, 0, 1)
love.graphics.print(love.timer.getFPS(), 10, 10)
love.graphics.setColor(1, 1, 1, 1)
local prev_str = "Prev scene (press Q)"
local next_str = "Next scene (press E)"
love.graphics.print("Example: " .. example_list[scene_iterator].title, 10, 25)
love.graphics.print(prev_str, 10, h-30)
love.graphics.print(next_str, w - font:getWidth(next_str) - 10, h-30)
love.graphics.setCanvas()
local cw, ch = love.graphics.getDimensions()
canvas_sprite:draw_in_viewport(0, 0, 'min', cw, ch, 0.5, 0.5)
end
function love.update(dt)
menori.app:update(dt)
if love.keyboard.isDown('escape') then
love.event.quit()
end
-- love.mouse.setRelativeMode(love.mouse.isDown(2))
end
local function set_scene()
menori.app:set_scene(example_list[scene_iterator].title)
end
function love.wheelmoved(...)
menori.app:handle_event('wheelmoved', ...)
end
function love.keyreleased(key, ...)
if key == 'q' then
scene_iterator = scene_iterator - 1
if scene_iterator < 1 then scene_iterator = #example_list end
set_scene()
end
if key == 'e' then
scene_iterator = scene_iterator + 1
if scene_iterator > #example_list then scene_iterator = 1 end
set_scene()
end
menori.app:handle_event('keyreleased', key, ...)
end
function love.keypressed(...)
menori.app:handle_event('keypressed', ...)
end
function love.mousemoved(...)
menori.app:handle_event('mousemoved', ...)
end
function love.mousepressed(...)
menori.app:handle_event('mousepressed', ...)
end