diff options
Diffstat (limited to 'src/lua/modules/graphics/graphics.cpp')
-rw-r--r-- | src/lua/modules/graphics/graphics.cpp | 33 |
1 files changed, 15 insertions, 18 deletions
diff --git a/src/lua/modules/graphics/graphics.cpp b/src/lua/modules/graphics/graphics.cpp index 4ff0dfc..5ba8c13 100644 --- a/src/lua/modules/graphics/graphics.cpp +++ b/src/lua/modules/graphics/graphics.cpp @@ -125,25 +125,13 @@ namespace JinEngine error(L, "No such image file %s", f); goto fail; } - Buffer b = {}; + Buffer b; if (!fs->read(f, b)) { error(L, "Failed to read image %s", f); goto fail; } bitmap = Bitmap::createBitmap(&b, b.size()); - //const Color* col = bitmap->getPixels(); - //ofstream o = ofstream("img.txt", ios_base::app); - //for (int i = 0; i < bitmap->getWidth() * bitmap->getHeight(); ++i) - //{ - // Color c = col[i]; - // o << (int)c.r << ','; - // o << (int)c.g << ','; - // o << (int)c.b << ','; - // o << (int)c.a << ','; - // if ((i + 1) % 10 == 0) - // o << endl; - //} if (bitmap == nullptr) { error(L, "Failed to decode image file %s", f); @@ -161,12 +149,21 @@ namespace JinEngine /* 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(); + Texture* texture = nullptr; + if (luax_istype(L, 1, JIN_GRAPHICS_BITMAP)) + { + Proxy* p = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_BITMAP); + Ref<Bitmap>& refBitmap = p->getRef<Bitmap>(); + Bitmap* bitmap = refBitmap.getObject(); + texture = Texture::createTexture(bitmap); + } + else if (luax_isstring(L, 1)) + { + const char* path = luax_checkstring(L, 1); + texture = Texture::createTexture(path); + } Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_TEXTURE, sizeof(Proxy)); - Texture* tex = Texture::createTexture(bitmap); - proxy->bind(new Ref<Texture>(tex, JIN_GRAPHICS_TEXTURE)); + proxy->bind(new Ref<Texture>(texture, JIN_GRAPHICS_TEXTURE)); return 1; } |