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
|
io.stdout:setvbuf("no")
local shader = [[
#VERTEX_SHADER
Vertex vert(Vertex v)
{
return v;
}
#END_VERTEX_SHADER
#FRAGMENT_SHADER
Color frag(Color col, Texture tex, Vertex v)
{
return col;
}
#END_FRAGMENT_SHADER
]]
local shader2 = [[
#VERTEX_SHADER
Vertex vert(Vertex v)
{
return v;
}
#END_VERTEX_SHADER
#FRAGMENT_SHADER
Color frag(Color col, Texture tex, Vertex v)
{
Color c = texel(tex, v.uv);
return c;
}
#END_FRAGMENT_SHADER
]]
music = nil
local tex = nil
local shader_program = nil
local shader_program2 = nil
local timer = nil
local tb = {x = 1, y = 2}
local t = 0
local spr = nil
function jin.core.onLoad()
jin.graphics.setClearColor(100, 100, 100, 255)
shader_program = jin.graphics.newShader(shader)
shader_program2 = jin.graphics.newShader(shader2)
tex = jin.graphics.newTexture("1.png")
spr = jin.graphics.newSprite()
spr:setShader(shader_program2)
spr:setGraphic(tex)
tex = nil
spr:setScale(4, 4)
spr:setOrigin(jin.graphics.SpriteOrigin.MIDDLELEFT)
music = jin.audio.newSource("forest.ogg")
music:setVolume(0.5)
music:setLoop(true)
--music:play()
jin.graphics.clear()
jin.graphics.showWindow()
timer = jin.time.newTimer()
local h = timer:every(0.5, function(sp)
local x, y = spr:getPosition()
spr:setPosition(x + 1, y)
end, spr)
timer:after(3, function(p)
--timer:cancel(h)
end, h)
end
local stop = false
function jin.core.onEvent(e)
if e.type == "Quit" then
jin.core.stop()
end
end
function jin.core.onUpdate()
tb.x = t
t = t + jin.time.getDelta()
end
function jin.core.onDraw()
timer:update(jin.time.getDelta())
jin.graphics.useShader(shader_program)
jin.graphics.setColor(255, 0, 255, 255)
jin.graphics.rect(jin.graphics.RenderMode.FILL, 30, 50, 100, 200)
jin.graphics.setColor(255, 255, 255, 255)
jin.graphics.unuseShader()
spr:render()
--jin.graphics.useShader(shader_program2)
--jin.graphics.draw(tex, 0, 0,0.2, 0.2)
--jin.graphics.unuseShader()
if stop then
jin.graphics.print("Quit", 100, 300)
end
end
|