-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy path04-mesh.lua
64 lines (53 loc) · 1.37 KB
/
04-mesh.lua
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
package.cpath = "bin/?.dll"
local iup = require "iuplua"
local bgfx = require "bgfx"
local util = require "util"
local math3d = require "math3d"
local ctx = {
canvas = iup.canvas {},
}
local dlg = iup.dialog {
ctx.canvas,
title = "04-mesh",
size = "HALFxHALF",
}
local time = 0
local function mainloop()
math3d.reset()
bgfx.touch(0)
time = time + 0.01
bgfx.set_uniform(ctx.u_time, math3d.vector {time,0,0,0})
local mtx = math3d.matrix { r = { 0, time, 0} }
bgfx.set_transform(mtx)
bgfx.set_state(ctx.state)
util.meshSubmit(ctx.mesh, 0, ctx.prog)
bgfx.frame()
end
function ctx.init()
bgfx.set_view_clear(0, "CD", 0x303030ff, 1, 0)
ctx.prog = util.programLoad("vs_mesh", "fs_mesh")
ctx.mesh = util.meshLoad "meshes/bunny.bin"
ctx.u_time = bgfx.create_uniform("u_time", "v4")
ctx.state = bgfx.make_state {
WRITE_MASK = "RGBAZ",
DEPTH_TEST = "LESS",
CULL = "CCW",
MSAA = true,
}
end
function ctx.resize(w,h)
ctx.width = w
ctx.height = h
bgfx.reset(w,h, "v")
local viewmat = math3d.lookat( {0,1,-2.5}, {0,1,0} )
local projmat = math3d.projmat { fov = 60, aspect = w/h , n = 0.1, f = 100 }
bgfx.set_view_transform(0, viewmat, projmat)
bgfx.set_view_rect(0, 0, 0, ctx.width, ctx.height)
end
util.init(ctx)
dlg:showxy(iup.CENTER,iup.CENTER)
dlg.usersize = nil
util.run(mainloop)
-- bgfx.destroy(ctx.u_time)
-- bgfx.destroy(ctx.prog)
-- util.meshUnload(ctx.mesh)