aboutsummaryrefslogtreecommitdiff
path: root/src/lua/graphics/luaopen_graphics.cpp
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2018-05-17 18:04:41 +0800
committerchai <chaifix@163.com>2018-05-17 18:04:41 +0800
commit34947d066b994c2ef9121a83497da344982d28e2 (patch)
tree41a65f6973a9082dafcc081a8a46de99b556370b /src/lua/graphics/luaopen_graphics.cpp
parentd45064be602c3becb046d86913ea8013774b0079 (diff)
v0.1.0
Diffstat (limited to 'src/lua/graphics/luaopen_graphics.cpp')
-rw-r--r--src/lua/graphics/luaopen_graphics.cpp34
1 files changed, 23 insertions, 11 deletions
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 <SDL2/SDL.h>
+
#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 <SDL2/SDL.h>
-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