diff options
author | chai <chaifix@163.com> | 2018-10-05 15:40:31 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2018-10-05 15:40:31 +0800 |
commit | 789895b4b9f99668b8b772f271d07d1ce3115742 (patch) | |
tree | 3ae85381358445b2c29c9a0afb59375de9a7ce66 /src/lua/modules/graphics/graphics.cpp | |
parent | 846d6ab0ec1033481574e8324a43fc547ecf5882 (diff) |
*update
Diffstat (limited to 'src/lua/modules/graphics/graphics.cpp')
-rw-r--r-- | src/lua/modules/graphics/graphics.cpp | 89 |
1 files changed, 19 insertions, 70 deletions
diff --git a/src/lua/modules/graphics/graphics.cpp b/src/lua/modules/graphics/graphics.cpp index 679b820..5c67421 100644 --- a/src/lua/modules/graphics/graphics.cpp +++ b/src/lua/modules/graphics/graphics.cpp @@ -145,7 +145,7 @@ namespace lua static int l_newShader(lua_State* L) { const char* program = luax_checkstring(L, 1); - JSLProgram* jsl = JSLProgram::createJSLProgram(program); + Shader* jsl = Shader::createShader(program); if (jsl == nullptr) { error(L, "Failed to compile shader"); @@ -153,7 +153,7 @@ namespace lua return 1; } Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_SHADER, sizeof(Proxy)); - proxy->bind(new Ref<JSLProgram>(jsl, JIN_GRAPHICS_SHADER)); + proxy->bind(new Ref<Shader>(jsl, JIN_GRAPHICS_SHADER)); return 1; } @@ -252,7 +252,6 @@ namespace lua context.curRenderColor.a = luax_checknumber(L, 4); else context.curClearColor.a = 255; - glColor4f(context.curRenderColor.r / 255.f, context.curRenderColor.g / 255.f, context.curRenderColor.b / 255.f, @@ -293,13 +292,13 @@ namespace lua { if (luax_gettop(L) == 0) { - JSLProgram::unuse(); + Shader::unuse(); return 0; } if (luax_istype(L, 1, JIN_GRAPHICS_SHADER)) { Proxy* proxy = (Proxy*)luax_toudata(L, 1); - Ref<JSLProgram>& jsl = proxy->getRef<JSLProgram>(); + Ref<Shader>& jsl = proxy->getRef<Shader>(); jsl->use(); } else @@ -308,13 +307,13 @@ namespace lua } return 0; } - +/* static int l_unuseShader(lua_State* L) { - JSLProgram::unuse(); + Shader::unuse(); return 0; } - +*/ static int l_setBlend(lua_State* L) { @@ -451,10 +450,10 @@ namespace lua return 0; } - static int l_newFont(lua_State* L) + static int l_newFontData(lua_State* L) { - Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_FONT, sizeof(Proxy)); - Font* font = new Font(); + Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_FONTDATA, sizeof(Proxy)); + FontData* fd = nullptr; { const char* path = luax_checkstring(L, 1); Filesystem* fs = Filesystem::get(); @@ -464,64 +463,14 @@ namespace lua luax_pushnil(L); return 1; } - Buffer b = {}; + Buffer b; fs->read(path, &b); - font->loadMemory((const unsigned char*)b.data); + fd = FontData::createFontData((unsigned char*)b.data, b.size); } - proxy->bind(new Ref<Font>(font, JIN_GRAPHICS_FONT)); + proxy->bind(new Ref<FontData>(fd, JIN_GRAPHICS_FONTDATA)); return 1; } - static int l_setFont(lua_State* L) - { - int n = luax_gettop(L); - if (n == 0) - { - if (context.defaultFont == 0) - { - #include "lua/resources/font.ttf.h" - context.defaultFont = new Font(); - context.defaultFont->loadMemory(font_ttf); - } - context.curFont = context.defaultFont; - return 0; - } - Font* font = (Font*)luax_checktype(L, 1, JIN_GRAPHICS_FONT); - context.curFont = font; - return 0; - } - - static int l_write(lua_State* L) - { - if (context.curFont == 0) - return 0; - - const char* text = luax_checkstring(L, 1); - int x = luax_checknumber(L, 2); - int y = luax_checknumber(L, 3); - - int fh = luax_optnumber(L, 4, 15); - int spacing = luax_optnumber(L, 5, 1); - int lh = luax_optnumber(L, 6, 18); - - context.curFont->render(text, x, y, fh, spacing, lh); - - return 0; - } - - static int l_box(lua_State* L) - { - const char* text = luax_checkstring(L, 1); - int fontheight = luax_checknumber(L, 2); - int spacing = luax_checknumber(L, 3); - int lineheight = luax_checknumber(L, 4); - int w, h; - context.curFont->box(text, fontheight, spacing, lineheight, &w, &h); - luax_pushnumber(L, w); - luax_pushnumber(L, h); - return 2; - } - static const luaL_Reg f[] = { /* window */ { "init", l_init }, @@ -535,7 +484,7 @@ namespace lua { "newTexture", l_newTexture }, { "newShader", l_newShader }, { "newCanvas", l_newCanvas }, - { "newFont", l_newFont }, + { "newFontData", l_newFontData }, /* render */ { "setClearColor", l_setClearColor }, { "clear", l_clear }, @@ -543,16 +492,12 @@ namespace lua { "setColor", l_setColor }, { "getColor", l_getColor }, { "present", l_present }, - /* font */ - { "box", l_box }, - { "write", l_write }, - { "setFont", l_setFont }, /* canvas */ { "bindCanvas", l_bindCanvas }, { "unbindCanvas", l_unbindCanvas }, /* shader */ { "useShader", l_useShader }, - { "unuseShader", l_unuseShader }, + //{ "unuseShader", l_unuseShader }, /* shapes */ { "point", l_point }, { "line", l_line }, @@ -565,6 +510,8 @@ namespace lua extern int luaopen_Texture(lua_State* L); extern int luaopen_Font(lua_State* L); + extern int luaopen_FontData(lua_State* L); + extern int luaopen_Page(lua_State* L); extern int luaopen_Canvas(lua_State* L); extern int luaopen_JSL(lua_State* L); extern int luaopen_Bitmap(lua_State* L); @@ -575,7 +522,9 @@ namespace lua luaopen_Bitmap(L); luaopen_Texture(L); luaopen_Canvas(L); + luaopen_FontData(L); luaopen_Font(L); + luaopen_Page(L); luaopen_JSL(L); // load whole lib |