aboutsummaryrefslogtreecommitdiff
path: root/src/lua/modules/graphics/luaopen_graphics.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lua/modules/graphics/luaopen_graphics.cpp')
-rw-r--r--src/lua/modules/graphics/luaopen_graphics.cpp79
1 files changed, 51 insertions, 28 deletions
diff --git a/src/lua/modules/graphics/luaopen_graphics.cpp b/src/lua/modules/graphics/luaopen_graphics.cpp
index f0a7f5b..9c1d404 100644
--- a/src/lua/modules/graphics/luaopen_graphics.cpp
+++ b/src/lua/modules/graphics/luaopen_graphics.cpp
@@ -1,4 +1,5 @@
#include "lua/modules/luax.h"
+#include "lua/modules/types.h"
#include "libjin/jin.h"
#include "lua/common/common.h"
#include "lua/modules/embed/graphics.lua.h"
@@ -16,6 +17,7 @@ namespace lua
static struct
{
color curRenderColor;
+ color curClearColor;
Font* curFont = nullptr;
Font* defaultFont = nullptr;
} context;
@@ -123,6 +125,26 @@ namespace lua
return 0;
}
+ static int l_setClearColor(lua_State* L)
+ {
+ if (luax_gettop(L) == 0)
+ {
+ glClearColor(1, 1, 1, 1);
+ return 0;
+ }
+
+ context.curClearColor.rgba.r = luax_checknumber(L, 1);
+ context.curClearColor.rgba.g = luax_checknumber(L, 2);
+ context.curClearColor.rgba.b = luax_checknumber(L, 3);
+ context.curClearColor.rgba.a = luax_checknumber(L, 4);
+
+ glClearColor(context.curClearColor.rgba.r / 255.f,
+ context.curClearColor.rgba.g / 255.f,
+ context.curClearColor.rgba.b / 255.f,
+ context.curClearColor.rgba.a / 255.f);
+ return 0;
+ }
+
static int l_present(lua_State* L)
{
Window::get()->swapBuffers();
@@ -440,34 +462,35 @@ namespace lua
}
static const luaL_Reg f[] = {
- { "init", l_init },
- { "size", l_getSize },
- { "getWidth", l_getWidth },
- { "getHeight", l_getHeight },
- { "newImage", l_newImage },
- { "newShader", l_newShader },
- { "newCanvas", l_newCanvas },
- { "newFont", l_newFont },
- { "box", l_box },
- { "write", l_write },
- { "clear", l_clear },
- { "draw", l_draw },
- { "color", l_setColor },
- { "palette", l_getColor },
- { "present", l_present },
- { "study", l_study },
- { "bind", l_bindCanvas },
- { "unbind", l_unbindCanvas },
- { "use", l_useShader },
- { "unuse", l_unuseShader },
- { "point", l_drawpoint },
- { "line", l_drawLine },
- { "rect", l_drawRect },
- { "circle", l_drawCircle },
- { "triangle", l_drawTriangle },
- { "polygon", l_drawPolygon },
- { "destroy", l_destroy },
- { 0, 0 }
+ { "init", l_init },
+ { "getSize", l_getSize },
+ { "getWidth", l_getWidth },
+ { "getHeight", l_getHeight },
+ { "newImage", l_newImage },
+ { "newShader", l_newShader },
+ { "newCanvas", l_newCanvas },
+ { "newFont", l_newFont },
+ { "box", l_box },
+ { "write", l_write },
+ { "setClearColor", l_setClearColor },
+ { "clear", l_clear },
+ { "draw", l_draw },
+ { "setColor", l_setColor },
+ { "palette", l_getColor },
+ { "present", l_present },
+ { "setFont", l_study },
+ { "bindCanvas", l_bindCanvas },
+ { "unbindCanvas", l_unbindCanvas },
+ { "useShader", l_useShader },
+ { "unuseShader", l_unuseShader },
+ { "point", l_drawpoint },
+ { "line", l_drawLine },
+ { "rect", l_drawRect },
+ { "circle", l_drawCircle },
+ { "triangle", l_drawTriangle },
+ { "polygon", l_drawPolygon },
+ { "destroy", l_destroy },
+ { 0, 0 }
};
extern int luaopen_Image(lua_State* L);