forked from 3dreamengine/3DreamEngine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.lua
More file actions
84 lines (70 loc) · 2.55 KB
/
Copy pathmain.lua
File metadata and controls
84 lines (70 loc) · 2.55 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
83
84
local examples = love.filesystem.getDirectoryItems("examples")
for i = #examples, 1, -1 do
if not love.filesystem.getInfo("examples/" .. examples[i] .. "/main.lua", "file") then
table.remove(examples, i)
end
end
love.graphics.setBackgroundColor(0.35, 0.35, 0.35)
local font = love.graphics.newFont(24)
local font_small = love.graphics.newFont(16)
local descriptions = {
["Lamborghini"] = "PBR rendered Lamborghini with emission texture.",
["Tavern"] = "PBR rendered Tavern with 9 fully soft shadowed static light sources. Toggle different features to see real time differences.",
["monkey"] = "Good old Suzanne. Simpliest usage example.",
["blacksmith"] = "Single room demo. PBR with 3 lightsources. Toggle different features to see real time differences.",
["firstpersongame"] = "Not really a game, demo scene to see particle systems, outdoor lighting, daytime and rain.",
["particlesystem"] = "Small particle system example.",
["lowPolyGame"] = "Unfinished collision demo, flat phong shading.",
["knight"] = "MagicaVoxel demo.",
}
local mousereleased = false
local function button(text, x, y, w, h)
love.graphics.push("all")
local hover = false
local mx, my = love.mouse.getPosition()
if mx > x and mx < x + w and my > y and my < y + h then
love.graphics.setColor(0.75, 0.75, 0.75)
hover = true
else
love.graphics.setColor(0.6, 0.6, 0.6)
end
love.graphics.rectangle("fill", x, y, w, h, 5)
love.graphics.setColor(0.4, 0.4, 0.4)
love.graphics.setLineWidth(2)
love.graphics.rectangle("line", x, y, w, h, 5)
love.graphics.setFont(font)
local width = font:getWidth(text)
local scale = math.min(1.0, (w-20) / width)
local baseline = font:getBaseline() * scale
love.graphics.setColor(0.1, 0.1, 0.1)
love.graphics.print(text, x+10, y + h - baseline - 5, 0, scale)
love.graphics.pop()
return hover
end
function love.load()
if love.filesystem.getInfo("default") and love.filesystem.read("default") ~= "" then
require("examples/" .. love.filesystem.read("default") .. "/main")
end
end
function love.draw()
for d,s in ipairs(examples) do
local hover = button(s, 50, 50 + (d-1)*35, 200, 30)
if hover and descriptions[s] then
love.graphics.push("all")
love.graphics.setColor(0.0, 0.0, 0.0)
love.graphics.setFont(font_small)
love.graphics.printf(descriptions[s], 350, 100, 400, "left")
love.graphics.pop()
end
if mousereleased and hover then
love.draw = nil
love.keypressed = nil
require("examples/" .. s .. "/main")
return
end
end
mousereleased = false
end
function love.mousereleased(x, y, b)
mousereleased = true
end