aboutsummaryrefslogtreecommitdiff
path: root/bin/main.lua
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2018-09-11 19:45:38 +0800
committerchai <chaifix@163.com>2018-09-11 19:45:38 +0800
commit0ea853c2aad2aa3670eb694328743bb806e603bf (patch)
treeef6b1f09331d992b870c78e842ce59ff755163b9 /bin/main.lua
parentb994fc716e2a71ded757ff18e5d7f21a6f64a85a (diff)
*update
Diffstat (limited to 'bin/main.lua')
-rw-r--r--bin/main.lua98
1 files changed, 39 insertions, 59 deletions
diff --git a/bin/main.lua b/bin/main.lua
index 96898cf..eeec09e 100644
--- a/bin/main.lua
+++ b/bin/main.lua
@@ -1,30 +1,25 @@
-local boundary = {
- x = 200,
- y = 100,
- w = 100,
- h = 80,
-}
-
-local bg = {
- x = 200,
- y = 100,
- w = 300,
- h = 200
-}
-local p = {
- x = boundary.x + 10,
- y = boundary.y + 10,
- speed = 100,
-}
-
+io.stdout:setvbuf("no")
+local shader
+local img
+local img2
+local canvas
+local sw, sh = jin.graphics.getSize()
function jin.core.onLoad()
-
+ local str = jin.filesystem.read("metaball.shader")
+ shader = jin.graphics.newShader(str)
+ local w, h = 256, 240
+ local bitmap = jin.graphics.newBitmap(w, h, {255, 255, 0, 255})
+ local b = bitmap:clone()
+ bitmap = nil
+ -- local bitmap2 = jin.graphics.newBitmap("img2.bmp")
+ img = jin.graphics.newTexture(b)
+ -- img2 = jin.graphics.newTexture(bitmap2)
+ canvas = jin.graphics.newCanvas(200, 200)
end
-
-local function clamp(x, a, b)
- return math.min(math.max(x, a), b)
-end
-
+-- extern vec3 iResolution;
+-- extern number iGlobalTime;
+-- extern vec4 iMouse;
+local mx, my = 0, 0
function jin.core.onEvent(e)
if e.type == "Quit" then
jin.core.stop()
@@ -32,41 +27,26 @@ function jin.core.onEvent(e)
if e.type == "KeyDown" then
if e.key == "Escape" then
jin.core.stop()
- end
- if e.key == "Left" then
- p.x = p.x - p.speed
- elseif e.key == "Right" then
- p.x = p.x + p.speed
- elseif e.key == "Up" then
- p.y = p.y - p.speed
- elseif e.key == "Down" then
- p.y = p.y + p.speed
end
- p.x = clamp(p.x, boundary.x, boundary.x + boundary.w)
- p.y = clamp(p.y, boundary.y, boundary.y + boundary.h)
- end
-end
-
-local function updateBg()
- local x0 = boundary.x
- local x1 = boundary.x + boundary.w
- local tx = (p.x - x0) / (x1 - x0)
- bg.x = tx * (x1 - x0 - bg.w) + x0
- local y0 = boundary.y
- local y1 = boundary.y + boundary.h
- local ty = (p.y - y0) / (y1 - y0)
- bg.y = ty * (y1 - y0 - bg.h) + y0
-end
-
-function jin.core.onUpdate(dt)
- updateBg()
+ end
+ if e.type == "MouseMotion" then
+ -- if e.button == "left" then
+ mx = e.x
+ my = e.y
+ -- end
+ end
end
+local dt = 0
function jin.core.onDraw()
- jin.graphics.setColor(100, 100, 100, 255)
- jin.graphics.rect("fill", bg.x, bg.y, bg.w, bg.h)
- jin.graphics.setColor(255,255,255,255)
- jin.graphics.rect("line", boundary.x, boundary.y, boundary.w, boundary.h)
- jin.graphics.setColor(255,0,0,255)
- jin.graphics.rect("fill", p.x, p.y, 3, 3)
-end
+ dt = dt + 0.1
+ jin.graphics.bindCanvas(canvas)
+ jin.graphics.useShader(shader)
+ shader:sendNumber("iGlobalTime", dt )
+ shader:sendVec3("iResolution", {sw, sh, 1})
+ shader:sendVec4("iMouse", {mx, my, mx, my})
+ jin.graphics.draw(img, 0, 0, 1, 1)
+ jin.graphics.unuseShader()
+ jin.graphics.unbindCanvas()
+ jin.graphics.draw(canvas, 0, 0, 2, 2)
+end \ No newline at end of file