-
Notifications
You must be signed in to change notification settings - Fork 639
/
Copy pathex08.lua
86 lines (63 loc) · 1.33 KB
/
ex08.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
-- This example show how user defined shader works
local ej = require "ejoy2d"
local fw = require "ejoy2d.framework"
local pack = require "ejoy2d.simplepackage"
pack.load {
pattern = fw.WorkDir..[[examples/asset/?]],
"sample",
}
-- define a shader
local s = ej.define_shader {
name = "EXAMPLE",
fs = [[
varying vec2 v_texcoord;
uniform vec4 color;
uniform sampler2D texture0;
void main() {
vec4 tmp = texture2D(texture0, v_texcoord);
gl_FragColor = color + tmp;
}
]],
uniform = {
{
name = "color",
type = "float4",
}
},
texture = {
"texture0",
}
}
s.color(1,0,0,1) -- set shader color
local obj = ej.sprite("sample","cannon")
obj:ps(100,100)
obj.program = "EXAMPLE"
obj.turret.program = "EXAMPLE"
obj.turret.material:color(0,0,1,1)
local obj2 = ej.sprite("sample","cannon")
obj2:ps(200,100)
obj2.turret.program = "EXAMPLE"
obj2.turret.material:color(0,1,0,1) -- uniform can be set in material
local obj3 = ej.sprite("sample","cannon")
obj3:ps(300,100)
obj3.program = "EXAMPLE"
local game = {}
function game.update()
end
function game.drawframe()
ej.clear(0xff808080) -- clear (0.5,0.5,0.5,1) gray
obj:draw()
obj2:draw()
obj3:draw()
end
function game.touch(what, x, y)
end
function game.message(...)
end
function game.handle_error(...)
end
function game.on_resume()
end
function game.on_pause()
end
ej.start(game)