From 34947d066b994c2ef9121a83497da344982d28e2 Mon Sep 17 00:00:00 2001 From: chai Date: Thu, 17 May 2018 18:04:41 +0800 Subject: v0.1.0 --- src/lua/graphics/luaopen_graphics.cpp | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) (limited to 'src/lua/graphics/luaopen_graphics.cpp') diff --git a/src/lua/graphics/luaopen_graphics.cpp b/src/lua/graphics/luaopen_graphics.cpp index 490f560..8ddd455 100644 --- a/src/lua/graphics/luaopen_graphics.cpp +++ b/src/lua/graphics/luaopen_graphics.cpp @@ -1,24 +1,25 @@ +#include + #include "libs/luax/luax.h" + #include "render/image.h" #include "render/canvas.h" #include "render/jsl.h" #include "render/graphics.h" #include "render/window.h" #include "render/font.h" -#include "../luaopen_types.h" -#include "lua/embed/graphics.lua.h" -#include "libs/GLee/GLee.h" #include "fs/filesystem.h" -#include -using namespace jin::render; -using namespace jin::fs; +#include "../luaopen_types.h" +#include "../embed/graphics.lua.h" namespace jin { namespace lua { - + using namespace render; + using namespace fs; + /** * jin.graphics context, storge some module * shared variables. @@ -224,14 +225,24 @@ namespace lua return 0; } + static int l_unbindCanvas(lua_State* L) + { + Canvas::unbind(); + return 0; + } + static int l_useShader(lua_State* L) { + if (luax_gettop(L) == 0) + { + JSLProgram::unuse(); + return 0; + } if (luax_istype(L, 1, TYPE_JSL)) { /* is image */ JSLProgram* jsl = (JSLProgram*)luax_toudata(L, 1); jsl->use(); - } else { @@ -378,7 +389,7 @@ namespace lua return 1; } float* p = new float[2 * n]; - for (int i = 1; i <= 2 * n; i++) + for (int i = 1; i <= 2 * n; ++i) p[i - 1] = luax_rawgetnumber(L, 3, i); render::polygon(mode, p, n); delete[] p; @@ -494,6 +505,7 @@ namespace lua {"study", l_study}, // bind canvas {"bind", l_bindCanvas}, + {"unbind", l_unbindCanvas}, // use shader {"use", l_useShader}, {"unuse", l_unuseShader}, @@ -529,5 +541,5 @@ namespace lua return 1; } -} -} +}// lua +}// jin -- cgit v1.1-26-g67d0