summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2018-10-09 22:48:27 +0800
committerchai <chaifix@163.com>2018-10-09 22:48:27 +0800
commit9ee09f6ff94ec92727501e848627296f5116aa4b (patch)
tree8ed18b3975c9369e9d49f2f6aa0a6c14ba3967b2
parent99d246aa9f42e7c04cc6bab57a5ae195bfc904df (diff)
*update
-rw-r--r--JGUI/JButton.lua0
-rw-r--r--JGUI/main.lua31
-rw-r--r--bitmap_font/font.pngbin0 -> 2780 bytes
-rw-r--r--bitmap_font/main.lua46
4 files changed, 75 insertions, 2 deletions
diff --git a/JGUI/JButton.lua b/JGUI/JButton.lua
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/JGUI/JButton.lua
diff --git a/JGUI/main.lua b/JGUI/main.lua
index 1cb7b9c..c932a55 100644
--- a/JGUI/main.lua
+++ b/JGUI/main.lua
@@ -1,4 +1,20 @@
io.stdout:setvbuf("no")
+local texture_shader_source = [[
+#VERTEX_SHADER
+Vertex vert(Vertex v)
+{
+ return v;
+}
+#END_VERTEX_SHADER
+
+#FRAGMENT_SHADER
+Color frag(Color c, Texture tex, Vertex v)
+{
+ return c * texel(tex, v.uv);
+}
+#END_FRAGMENT_SHADER
+]]
+local texture_shader = nil
local JGUI = require("JGUI")
local panel = JGUI.newPanel("Panel")
@@ -22,7 +38,7 @@ button.onRelease = function()
bt = bt1
end
function jin.core.onLoad()
-
+ texture_shader = jin.graphics.newShader(texture_shader_source)
end
function jin.core.onEvent(e)
@@ -34,12 +50,23 @@ function jin.core.onEvent(e)
end
panel:onEvent(e)
end
-
+local t = 0
+local f = 0
function jin.core.onUpdate(dt)
panel:onUpdate(dt)
+ f = f + 1
+ t = t + dt
+ if t >= 1 then
+ print(f)
+ t = t - 1
+ f = 0
+ end
end
function jin.core.onDraw()
+ jin.graphics.setColor(255 * math.sin(t), 255 * math.cos(t), 255 * math.tan(t), 255)
+ jin.graphics.useShader(texture_shader)
-- jin.graphics.unbindCanvas()
jin.graphics.draw(bt, 0, button.y)
+ jin.graphics.unuseShader()
end
diff --git a/bitmap_font/font.png b/bitmap_font/font.png
new file mode 100644
index 0000000..151b992
--- /dev/null
+++ b/bitmap_font/font.png
Binary files differ
diff --git a/bitmap_font/main.lua b/bitmap_font/main.lua
new file mode 100644
index 0000000..a9231f0
--- /dev/null
+++ b/bitmap_font/main.lua
@@ -0,0 +1,46 @@
+io.stdout:setvbuf("no")
+local texture_shader_source = [[
+#VERTEX_SHADER
+Vertex vert(Vertex v)
+{
+ return v;
+}
+#END_VERTEX_SHADER
+
+#FRAGMENT_SHADER
+Color frag(Color c, Texture tex, Vertex v)
+{
+ return c * texel(tex, v.uv);
+}
+#END_FRAGMENT_SHADER
+]]
+local texture_shader = nil
+local font = nil
+function jin.core.onLoad()
+ texture_shader = jin.graphics.newShader(texture_shader_source)
+ local fontData = jin.graphics.newBitmap("font.png")
+ font = jin.graphics.newTexture(fontData)
+ fontData = nil
+end
+
+function jin.core.onEvent(e)
+ if e.type == "Quit" then
+ jin.core.stop()
+ end
+ if e.type == "KeyDown" and e.key == "Escape" then
+ jin.core.stop()
+ end
+end
+function jin.core.onUpdate(dt)
+
+end
+local t = 0
+function jin.core.onDraw()
+ jin.graphics.setClearColor(255, 255, 255, 255)
+ t = t + 0.01
+ jin.graphics.setColor(255*math.sin(t), 255*math.cos(t), 255*math.sin(t)*math.cos(t), 255)
+ jin.graphics.useShader(texture_shader)
+ jin.graphics.drawq(font, {16, 16, 32, 16}, 10, 10, 5, 5)
+ --jin.graphics.draw(font, 0, 0, 3, 3)
+ jin.graphics.unuseShader()
+end