diff options
Diffstat (limited to 'src/lua/modules/graphics/je_lua_graphics.cpp')
-rw-r--r-- | src/lua/modules/graphics/je_lua_graphics.cpp | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/src/lua/modules/graphics/je_lua_graphics.cpp b/src/lua/modules/graphics/je_lua_graphics.cpp index 83ef40b..d59a67d 100644 --- a/src/lua/modules/graphics/je_lua_graphics.cpp +++ b/src/lua/modules/graphics/je_lua_graphics.cpp @@ -24,10 +24,17 @@ namespace JinEngine Color curClearColor; Font* curFont = nullptr; Font* defaultFont = nullptr; + bool initialized = false; } context; LUA_IMPLEMENT int l_init(lua_State* L) { + if (context.initialized) + { + luax_pushboolean(L, true); + return 1; + } + Window* wnd = Window::get(); Window::Setting setting; setting.width = luax_getfieldinteger(L, 1, "width"); @@ -36,21 +43,21 @@ namespace JinEngine setting.vsync = luax_getfieldbool(L, 1, "vsync"); setting.fullscreen = luax_getfieldbool(L, 1, "fullscreen"); setting.resizable = luax_getfieldbool(L, 1, "resizable"); - if (!wnd->init(&setting)) + context.initialized = wnd->init(&setting); + if (!context.initialized) { - luax_pushboolean(L, false); + luax_pushboolean(L, context.initialized); return 1; } - { - /* load default font */ - Bitmap* bitmap = Bitmap::createBitmap(default_font_bitmap, sizeof(default_font_bitmap)); - TextureFont* tf = TextureFont::createTextureFont(bitmap, Text(Encode::UTF8, default_charset), default_font_split, bitmap->getHeight()); - context.defaultFont = tf; - delete bitmap; - } - context.curFont = context.defaultFont; - - luax_pushboolean(L, true); + + /* load default font */ + Bitmap* bitmap = Bitmap::createBitmap(default_font_bitmap, sizeof(default_font_bitmap)); + TextureFont* tf = TextureFont::createTextureFont(bitmap, Text(Encode::UTF8, default_charset), default_font_split, bitmap->getHeight()); + delete bitmap; + context.defaultFont = tf; + context.curFont = tf; + + luax_pushboolean(L, context.initialized); return 1; } |