aboutsummaryrefslogtreecommitdiff
path: root/src/lua/modules/graphics/graphics.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lua/modules/graphics/graphics.cpp')
-rw-r--r--src/lua/modules/graphics/graphics.cpp66
1 files changed, 40 insertions, 26 deletions
diff --git a/src/lua/modules/graphics/graphics.cpp b/src/lua/modules/graphics/graphics.cpp
index 62bfb26..909e70c 100644
--- a/src/lua/modules/graphics/graphics.cpp
+++ b/src/lua/modules/graphics/graphics.cpp
@@ -15,8 +15,8 @@ namespace lua
static struct
{
- color curRenderColor;
- color curClearColor;
+ Color curRenderColor;
+ Color curClearColor;
Font* curFont = nullptr;
Font* defaultFont = nullptr;
} context;
@@ -77,9 +77,9 @@ namespace lua
return 1;
}
- static int l_newTexture(lua_State* L)
+ static int l_newBitmap(lua_State* L)
{
- Filesystem* fs = Filesystem::get();
+ Filesystem* fs = Filesystem::get();
const char* f = luax_checkstring(L, 1);
if (!fs->exists(f))
{
@@ -88,9 +88,20 @@ namespace lua
}
Buffer b;
fs->read(f, &b);
+ Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_BITMAP, sizeof(Proxy));
+ Bitmap* bitmap = Bitmap::createBitmap(b.data, b.size);
+ proxy->bind(new Ref<Bitmap>(bitmap, JIN_GRAPHICS_BITMAP));
+ return 1;
+ }
+ /* jin.graphics.newTexture(bitmap) */
+ static int l_newTexture(lua_State* L)
+ {
+ Proxy* p = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_BITMAP);
+ Ref<Bitmap>& refBitmap = p->getRef<Bitmap>();
+ Bitmap* bitmap = refBitmap.getObject();
Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_TEXTURE, sizeof(Proxy));
- Texture* img = Texture::createTexture(b.data, b.size);
+ Texture* img = Texture::createTexture(bitmap);
proxy->bind(new Ref<Texture>(img, JIN_GRAPHICS_TEXTURE));
return 1;
}
@@ -140,15 +151,15 @@ namespace lua
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);
+ context.curClearColor.r = luax_checknumber(L, 1);
+ context.curClearColor.g = luax_checknumber(L, 2);
+ context.curClearColor.b = luax_checknumber(L, 3);
+ context.curClearColor.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);
+ glClearColor(context.curClearColor.r / 255.f,
+ context.curClearColor.g / 255.f,
+ context.curClearColor.b / 255.f,
+ context.curClearColor.a / 255.f);
return 0;
}
@@ -192,27 +203,27 @@ namespace lua
return 0;
}
- context.curRenderColor.rgba.r = luax_checknumber(L, 1);
- context.curRenderColor.rgba.g = luax_checknumber(L, 2);
- context.curRenderColor.rgba.b = luax_checknumber(L, 3);
+ context.curRenderColor.r = luax_checknumber(L, 1);
+ context.curRenderColor.g = luax_checknumber(L, 2);
+ context.curRenderColor.b = luax_checknumber(L, 3);
if (luax_gettop(L) == 4)
- context.curRenderColor.rgba.a = luax_checknumber(L, 4);
+ context.curRenderColor.a = luax_checknumber(L, 4);
else
- context.curClearColor.rgba.a = 255;
+ context.curClearColor.a = 255;
- glColor4f(context.curRenderColor.rgba.r / 255.f,
- context.curRenderColor.rgba.g / 255.f,
- context.curRenderColor.rgba.b / 255.f,
- context.curRenderColor.rgba.a / 255.f);
+ glColor4f(context.curRenderColor.r / 255.f,
+ context.curRenderColor.g / 255.f,
+ context.curRenderColor.b / 255.f,
+ context.curRenderColor.a / 255.f);
return 0;
}
static int l_palette(lua_State * L)
{
- luax_pushnumber(L, context.curRenderColor.rgba.r);
- luax_pushnumber(L, context.curRenderColor.rgba.g);
- luax_pushnumber(L, context.curRenderColor.rgba.b);
- luax_pushnumber(L, context.curRenderColor.rgba.a);
+ luax_pushnumber(L, context.curRenderColor.r);
+ luax_pushnumber(L, context.curRenderColor.g);
+ luax_pushnumber(L, context.curRenderColor.b);
+ luax_pushnumber(L, context.curRenderColor.a);
return 4;
}
@@ -478,6 +489,7 @@ namespace lua
{ "getHeight", l_getHeight },
{ "destroy", l_destroy },
/* creators */
+ { "newBitmap", l_newBitmap },
{ "newTexture", l_newTexture },
{ "newShader", l_newShader },
{ "newCanvas", l_newCanvas },
@@ -513,10 +525,12 @@ namespace lua
extern int luaopen_Font(lua_State* L);
extern int luaopen_Canvas(lua_State* L);
extern int luaopen_JSL(lua_State* L);
+ extern int luaopen_Bitmap(lua_State* L);
int luaopen_graphics(lua_State* L)
{
// register types
+ luaopen_Bitmap(L);
luaopen_Texture(L);
luaopen_Canvas(L);
luaopen_Font(L);