diff options
| author | Alexander Pickering <alexandermpickering@gmail.com> | 2018-03-09 23:55:49 -0500 |
|---|---|---|
| committer | Alexander Pickering <alexandermpickering@gmail.com> | 2018-03-09 23:55:49 -0500 |
| commit | 2831e232b886c5e3b0791ea5192f9e5194e6abf3 (patch) | |
| tree | 4fb9309d18f388673b7a21b8f0e927727006f585 /src/client/lua_api/video | |
| parent | 35b7c646fd7f80b64c1ef49b6d81f9df9bc1b940 (diff) | |
| download | brokengine-2831e232b886c5e3b0791ea5192f9e5194e6abf3.tar.gz brokengine-2831e232b886c5e3b0791ea5192f9e5194e6abf3.tar.bz2 brokengine-2831e232b886c5e3b0791ea5192f9e5194e6abf3.zip | |
Added IGUIImages
Added the ability to display itextures on the gui
Diffstat (limited to 'src/client/lua_api/video')
| -rw-r--r-- | src/client/lua_api/video/iimage.cpp | 81 | ||||
| -rw-r--r-- | src/client/lua_api/video/iimage.hpp | 8 | ||||
| -rw-r--r-- | src/client/lua_api/video/itexture.cpp | 41 | ||||
| -rw-r--r-- | src/client/lua_api/video/itexture.hpp | 8 | ||||
| -rw-r--r-- | src/client/lua_api/video/smaterial.cpp | 51 | ||||
| -rw-r--r-- | src/client/lua_api/video/smaterial.hpp | 8 |
6 files changed, 197 insertions, 0 deletions
diff --git a/src/client/lua_api/video/iimage.cpp b/src/client/lua_api/video/iimage.cpp new file mode 100644 index 0000000..b832783 --- /dev/null +++ b/src/client/lua_api/video/iimage.cpp @@ -0,0 +1,81 @@ + +#include "iimage.hpp" +#include <irrlicht.h> + +#include "../../../shared/lua_api/common.h" + +using namespace irr; +using namespace video; + +extern IrrlichtDevice* device; +extern IVideoDriver* driver; + +//newiimage(ECOLOR_FORMAT,{width,height}) +int newiimage(lua_State* L){ + printf("Attempting to create new iimage\n"); + long w,h; + popvector2i(L,&w,&h); + int format = lua_tonumber(L,-1); + lua_pop(L,1); + printf("All data collected, creating...\n"); + IImage* img = driver->createImage((irr::video::ECOLOR_FORMAT)format,irr::core::dimension2d<u32>(w,h)); + lua_pushlightuserdata(L,img); + luaL_getmetatable(L,"iimage"); + lua_setmetatable(L,-2); + printf("Everything sets up, returning\n"); + return 1; +} + +//setPixel({x,y},{r,g,b,a},bool_shouldblend) +int setiimagepixel(lua_State* L){ + printf("Setpixel called\n"); + bool sb = lua_toboolean(L,-1);//{ud_iimage},{x,y},{r,g,b,a},bool_shouldblend + lua_pop(L,1);//{ud_iimage},{x,y},{r,g,b,a} + long r,g,b,a; + popvector4i(L,&r,&g,&b,&a);//{ud_iimage},{x,y} + long x,y; + popvector2i(L,&x,&y);//{ud_iimage} + IImage* img = (IImage*)lua_touserdata(L,-1);//{ud_iimage} + img->setPixel(x,y,SColor(a,r,g,b),sb); + lua_pop(L,1); + return 0; +} + +static const luaL_reg iimage_m[] = { + {"setPixel", setiimagepixel}, + {0,0}, +}; + +#define set_const(l,x) lua_pushstring(l,#x);lua_pushinteger(l,x);lua_settable(l,-3); + +void iimage_register(lua_State* L){ + printf("Registering iimage...\n"); + driver = device->getVideoDriver(); + lua_getglobal(L,"video");//{} + + set_const(L,ECF_A1R5G5B5); + set_const(L,ECF_R5G6B5); + set_const(L,ECF_A8R8G8B8); + set_const(L,ECF_R16F); + set_const(L,ECF_G16R16F); + set_const(L,ECF_A16B16G16R16F); + set_const(L,ECF_R32F); + set_const(L,ECF_G32R32F); + set_const(L,ECF_A32B32G32R32F); + set_const(L,ECF_UNKNOWN); + + lua_pushcfunction(L,newiimage);//{},newiimage() + lua_setfield(L,-2,"newiimage");//{} + lua_pop(L,1);// + + luaL_newmetatable(L,"iimage");//{m_iimage} + + lua_newtable(L);//{m_iimage},{} + luaL_register(L,NULL,iimage_m);//{m_iimage},{iimage} + + lua_setfield(L,-2,"__index");//{m_iimage} + + lua_pop(L,1);// + + printf("registered iimage!\n"); +} diff --git a/src/client/lua_api/video/iimage.hpp b/src/client/lua_api/video/iimage.hpp new file mode 100644 index 0000000..d5890e4 --- /dev/null +++ b/src/client/lua_api/video/iimage.hpp @@ -0,0 +1,8 @@ + +extern "C" { + #include <lua.h> + #include <lauxlib.h> + #include <lualib.h> +} + +void iimage_register(lua_State* L); diff --git a/src/client/lua_api/video/itexture.cpp b/src/client/lua_api/video/itexture.cpp new file mode 100644 index 0000000..a7f4652 --- /dev/null +++ b/src/client/lua_api/video/itexture.cpp @@ -0,0 +1,41 @@ + +extern "C" { + #include <lua.h> + #include <lauxlib.h> + #include <lualib.h> +} +#include <irrlicht.h> +#include "itexture.hpp" +#include "iimage.hpp" +#include "../../../shared/lua_api/common.h" + +using namespace irr; +using namespace video; + +extern IrrlichtDevice* device; +extern IVideoDriver* driver; +//newtexture(string name,IImage* image) +int newitexture(lua_State* L){ + IImage* im = (IImage*) lua_touserdata(L,-1); + lua_pop(L,1); + const char* name = lua_tostring(L,-1); + lua_pop(L,1); + + ITexture* tex = driver->addTexture(name,im); + if(!tex){ + lua_pushstring(L,"Failed to create texture!"); + lua_error(L); + } + + lua_pushlightuserdata(L,tex); + + return 1; +} + + + +void itexture_register(lua_State* L){ + lua_getglobal(L,"video"); + lua_pushcfunction(L,newitexture); + lua_setfield(L,-2,"newtexture"); +} diff --git a/src/client/lua_api/video/itexture.hpp b/src/client/lua_api/video/itexture.hpp new file mode 100644 index 0000000..35d7174 --- /dev/null +++ b/src/client/lua_api/video/itexture.hpp @@ -0,0 +1,8 @@ + +extern "C" { + #include <lua.h> + #include <lauxlib.h> + #include <lualib.h> +} + +void itexture_register(lua_State* L); diff --git a/src/client/lua_api/video/smaterial.cpp b/src/client/lua_api/video/smaterial.cpp new file mode 100644 index 0000000..e5b9eff --- /dev/null +++ b/src/client/lua_api/video/smaterial.cpp @@ -0,0 +1,51 @@ + +extern "C" { + #include <lua.h> + #include <lauxlib.h> + #include <lualib.h> +} +#include <irrlicht.h> +#include "smaterial.hpp" + +using namespace irr::video; + +/*This probably needs a _gc metamethod*/ +int newsmaterial(lua_State* L){ + SMaterial* mat = new SMaterial(); + lua_pushlightuserdata(L,mat); + + return 0; +} + +#define set_const(l,x) lua_pushstring(l,#x);lua_pushinteger(l,x);lua_settable(l,-3); + +void smaterial_register(lua_State* L){ + //Add globals dealing with material flags + + lua_getglobal(L,"video");//{} + + set_const(L,EMF_WIREFRAME); + set_const(L,EMF_POINTCLOUD); + set_const(L,EMF_GOURAUD_SHADING); + set_const(L,EMF_LIGHTING); + set_const(L,EMF_ZBUFFER); + set_const(L,EMF_ZWRITE_ENABLE); + set_const(L,EMF_BACK_FACE_CULLING); + set_const(L,EMF_FRONT_FACE_CULLING); + set_const(L,EMF_BILINEAR_FILTER); + set_const(L,EMF_TRILINEAR_FILTER); + set_const(L,EMF_ANISOTROPIC_FILTER); + set_const(L,EMF_FOG_ENABLE); + set_const(L,EMF_NORMALIZE_NORMALS); + set_const(L,EMF_TEXTURE_WRAP); + set_const(L,EMF_ANTI_ALIASING); + set_const(L,EMF_COLOR_MASK); + set_const(L,EMF_COLOR_MATERIAL); + set_const(L,EMF_USE_MIP_MAPS); + set_const(L,EMF_BLEND_OPERATION); + set_const(L,EMF_POLYGON_OFFSET); + + lua_pushcfunction(L,newsmaterial);//{},newsmaterial + lua_setfield(L,-2,"newsmaterial"); + +} diff --git a/src/client/lua_api/video/smaterial.hpp b/src/client/lua_api/video/smaterial.hpp new file mode 100644 index 0000000..7457d69 --- /dev/null +++ b/src/client/lua_api/video/smaterial.hpp @@ -0,0 +1,8 @@ + +extern "C" { + #include <lua.h> + #include <lauxlib.h> + #include <lualib.h> +} + +void smaterial_register(lua_State* L); |
