Added Canvas:getPixel(x, y). (pull request #17)

This commit is contained in:
rude
2012-10-17 21:33:10 -04:00
parent 4e2c424cd1
commit ba4cf6204d
4 changed files with 37 additions and 0 deletions
+12
View File
@@ -458,6 +458,18 @@ love::image::ImageData *Canvas::getImageData(love::image::Image *image)
return img;
}
void Canvas::getPixel(unsigned char* pixel_rgba, int x, int y)
{
strategy->bindFBO( fbo );
glReadPixels(x, height - y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel_rgba);
if (current)
strategy->bindFBO( current->fbo );
else
strategy->bindFBO( 0 );
}
void Canvas::setFilter(const Image::Filter &f)
{
bindTexture(img);
+2
View File
@@ -65,6 +65,8 @@ public:
love::image::ImageData *getImageData(love::image::Image *image);
void getPixel(unsigned char* pixel_rgba, int x, int y);
void setFilter(const Image::Filter &f);
Image::Filter getFilter() const;
@@ -64,6 +64,27 @@ int w_Canvas_getImageData(lua_State *L)
return 1;
}
int w_Canvas_getPixel(lua_State * L)
{
Canvas * canvas = luax_checkcanvas(L, 1);
int x = luaL_checkint(L, 2);
int y = luaL_checkint(L, 3);
unsigned char c[4];
try
{
canvas->getPixel(c, x, y);
}
catch (love::Exception & e)
{
return luaL_error(L, "%s", e.what());
}
lua_pushnumber(L, c[0]);
lua_pushnumber(L, c[1]);
lua_pushnumber(L, c[2]);
lua_pushnumber(L, c[3]);
return 4;
}
int w_Canvas_setFilter(lua_State *L)
{
Canvas *canvas = luax_checkcanvas(L, 1);
@@ -202,6 +223,7 @@ static const luaL_Reg functions[] =
{
{ "renderTo", w_Canvas_renderTo },
{ "getImageData", w_Canvas_getImageData },
{ "getPixel", w_Canvas_getPixel },
{ "setFilter", w_Canvas_setFilter },
{ "getFilter", w_Canvas_getFilter },
{ "setWrap", w_Canvas_setWrap },
@@ -36,6 +36,7 @@ namespace opengl
Canvas *luax_checkcanvas(lua_State *L, int idx);
int w_Canvas_renderTo(lua_State *L);
int w_Canvas_getImageData(lua_State *L);
int w_Canvas_getPixel(lua_State * L);
int w_Canvas_setFilter(lua_State *L);
int w_Canvas_getFilter(lua_State *L);
int w_Canvas_setWrap(lua_State *L);