aboutsummaryrefslogtreecommitdiff
path: root/src/lua/embed/scripts/graphics.lua.h
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2018-11-10 20:13:55 +0800
committerchai <chaifix@163.com>2018-11-10 20:13:55 +0800
commite92caa97329016d012b46b9d37e1b2c3b613a8f2 (patch)
tree5bef0b7547e12f61dede5e09843e1718b808f9c4 /src/lua/embed/scripts/graphics.lua.h
parent63153bc8e742c522cfd3f5ab10609966e33310e6 (diff)
*修改代码结构
Diffstat (limited to 'src/lua/embed/scripts/graphics.lua.h')
-rw-r--r--src/lua/embed/scripts/graphics.lua.h61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/lua/embed/scripts/graphics.lua.h b/src/lua/embed/scripts/graphics.lua.h
new file mode 100644
index 0000000..751d029
--- /dev/null
+++ b/src/lua/embed/scripts/graphics.lua.h
@@ -0,0 +1,61 @@
+/* graphics.lua */
+static const char* graphics_lua = R"(
+jin.graphics = jin.graphics or {}
+
+local jg = jin.graphics
+
+jg.RenderMode = {
+ FILL = 1,
+ LINE = 2,
+}
+
+local default_shader = nil
+local default_shader_source = [[
+#VERTEX_SHADER
+
+Vertex vert(Vertex v)
+{
+ return v;
+}
+
+#END_VERTEX_SHADER
+
+#FRAGMENT_SHADER
+
+Color frag(Color col, Texture tex, Vertex v)
+{
+ return col * texel(tex, v.uv);
+}
+
+#END_FRAGMENT_SHADER
+]]
+
+local _init = jg.init
+local initialized = false
+
+jg.init = function(setting)
+ if initialized then
+ return initialized
+ end
+ initialized = _init(setting)
+ if initialized then
+ default_shader = jg.newShader(default_shader_source)
+ jg.useShader(default_shader)
+ end
+ return initialized
+end
+
+jg.unuseShader = function()
+ jg.useShader(default_shader)
+end
+
+-- Reset all attributes to default value.
+jg.reset = function()
+ jg.setColor(255, 255, 255, 255)
+ jg.setClearColor(0, 0, 0, 255)
+ jg.clear()
+ jg.unsetFont()
+ jg.unuseShader()
+end
+
+)"; \ No newline at end of file