diff options
| author | Alexander Pickering <alex@cogarr.net> | 2018-06-23 06:52:55 -0600 |
|---|---|---|
| committer | Alexander Pickering <alex@cogarr.net> | 2018-06-23 06:52:55 -0600 |
| commit | e6faff1394864a1fe0d517584d1c104997dff39f (patch) | |
| tree | d7956fc8aabef903f354578d69d4d7fdf64ec928 /src/client/lua_api/video | |
| parent | 1aaa348ac080c97c0aeb0a02146ae26b74add5a1 (diff) | |
| parent | 9fa5dcc9310a8c6ff8c77a47a86303f7b950dcf3 (diff) | |
| download | brokengine-e6faff1394864a1fe0d517584d1c104997dff39f.tar.gz brokengine-e6faff1394864a1fe0d517584d1c104997dff39f.tar.bz2 brokengine-e6faff1394864a1fe0d517584d1c104997dff39f.zip | |
Merge branch 'master' of ssh://cogarr.net:43/home/git/brokengine
Diffstat (limited to 'src/client/lua_api/video')
| -rw-r--r-- | src/client/lua_api/video/iimage.cpp | 59 | ||||
| -rw-r--r-- | src/client/lua_api/video/itexture.cpp | 37 |
2 files changed, 79 insertions, 17 deletions
diff --git a/src/client/lua_api/video/iimage.cpp b/src/client/lua_api/video/iimage.cpp index b832783..3090057 100644 --- a/src/client/lua_api/video/iimage.cpp +++ b/src/client/lua_api/video/iimage.cpp @@ -10,34 +10,71 @@ using namespace video; extern IrrlichtDevice* device; extern IVideoDriver* driver; -//newiimage(ECOLOR_FORMAT,{width,height}) +//newiimage(ECOLOR_FORMAT,{width,height}) -> {image} int newiimage(lua_State* L){ - printf("Attempting to create new iimage\n"); + //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"); + //printf("All data collected, creating...\n"); IImage* img = driver->createImage((irr::video::ECOLOR_FORMAT)format,irr::core::dimension2d<u32>(w,h)); + lua_newtable(L); lua_pushlightuserdata(L,img); + lua_setfield(L,-2,"image"); luaL_getmetatable(L,"iimage"); lua_setmetatable(L,-2); - printf("Everything sets up, returning\n"); + //printf("Everything sets up, returning\n"); return 1; } -//setPixel({x,y},{r,g,b,a},bool_shouldblend) +//newiimagefromfile("/path/to/file") -> {image} +int newiimagefromfile(lua_State* L){ + //printf("Creating new iimage from file"); + const char* strpath = lua_tostring(L,-1); + lua_pop(L,1); + int numloaders = driver->getImageLoaderCount(); + bool hasloaded = false; + IImage* img; + for(int j = 0; j < numloaders; j++){ + IImageLoader* loader = driver->getImageLoader(j); + io::IReadFile* f = device->getFileSystem()->createAndOpenFile(strpath); + if(!loader->isALoadableFileExtension(strpath)) + continue; + if(!loader->isALoadableFileFormat(f)) + continue; + hasloaded = true; + img = loader->loadImage(f); + } + if(!hasloaded){ + lua_pushstring(L,"Failed to load file"); + lua_error(L); + } + if(!img){ + lua_pushstring(L,"Failed to load image"); + lua_error(L); + } + lua_newtable(L); + lua_pushlightuserdata(L,img); + lua_setfield(L,-2,"image"); + luaL_getmetatable(L,"iimage"); + lua_setmetatable(L,-2); + //printf("IImage made, returning!"); + return 1; +} + +//setPixel({self},{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} + double r,g,b,a; + popvector4d(L,&r,&g,&b,&a);//{ud_iimage},{x,y} long x,y; popvector2i(L,&x,&y);//{ud_iimage} + lua_getfield(L,-1,"image"); IImage* img = (IImage*)lua_touserdata(L,-1);//{ud_iimage} img->setPixel(x,y,SColor(a,r,g,b),sb); - lua_pop(L,1); + lua_pop(L,2); return 0; } @@ -49,7 +86,6 @@ static const luaL_reg iimage_m[] = { #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");//{} @@ -66,6 +102,8 @@ void iimage_register(lua_State* L){ lua_pushcfunction(L,newiimage);//{},newiimage() lua_setfield(L,-2,"newiimage");//{} + lua_pushcfunction(L,newiimagefromfile);//{},newiimagefromfile() + lua_setfield(L,-2,"newiimagefromfile");//{} lua_pop(L,1);// luaL_newmetatable(L,"iimage");//{m_iimage} @@ -77,5 +115,4 @@ void iimage_register(lua_State* L){ lua_pop(L,1);// - printf("registered iimage!\n"); } diff --git a/src/client/lua_api/video/itexture.cpp b/src/client/lua_api/video/itexture.cpp index a7f4652..42de1bd 100644 --- a/src/client/lua_api/video/itexture.cpp +++ b/src/client/lua_api/video/itexture.cpp @@ -14,20 +14,42 @@ using namespace video; extern IrrlichtDevice* device; extern IVideoDriver* driver; -//newtexture(string name,IImage* image) +//newtexture(string name,{image}) -> {texture} int newitexture(lua_State* L){ + //printf("About to create new texture\n"); + lua_getfield(L,-1,"image");//"name",{image},image* IImage* im = (IImage*) lua_touserdata(L,-1); - lua_pop(L,1); + lua_pop(L,2);//"name" const char* name = lua_tostring(L,-1); - lua_pop(L,1); + lua_pop(L,1);// + //printf("About to create texture\n"); ITexture* tex = driver->addTexture(name,im); if(!tex){ lua_pushstring(L,"Failed to create texture!"); lua_error(L); } + lua_newtable(L); + lua_pushlightuserdata(L,tex); + lua_setfield(L,-2,"texture"); + + return 1; +} + +//newtexturefromfile(string file_name) -> {texture} +int newitexturefromfile(lua_State* L){ + const char* strpath = lua_tostring(L,-1); + lua_pop(L,1); + ITexture* tex = driver->getTexture(strpath); + if(!tex){ + lua_pushstring(L,"Failed to create texture!"); + lua_error(L); + } + + lua_newtable(L); lua_pushlightuserdata(L,tex); + lua_setfield(L,-2,"texture"); return 1; } @@ -35,7 +57,10 @@ int newitexture(lua_State* L){ void itexture_register(lua_State* L){ - lua_getglobal(L,"video"); - lua_pushcfunction(L,newitexture); - lua_setfield(L,-2,"newtexture"); + lua_getglobal(L,"video");//{} + lua_pushcfunction(L,newitexture);//{},newitexture + lua_setfield(L,-2,"newtexture");//{} + lua_pushcfunction(L,newitexturefromfile); + lua_setfield(L,-2,"newtexturefromfile"); + lua_pop(L,1); } |
