1. DLaicH
  2. love-canvas_getPixel

Commits

DLaicH  committed dd3ce39 Draft Merge

merged that back into default so that I can work with the branches independently

  • Participants
  • Parent commits e0f98d5, 1cd239d
  • Branches default
  • Tags 0.8.0-canvas_getPixel

Comments (0)

Files changed (4)

File src/modules/graphics/opengl/Canvas.cpp

View file
  • Ignore whitespace
 		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)
 	{
 		GLint gmin = (f.min == Image::FILTER_NEAREST) ? GL_NEAREST : GL_LINEAR;

File src/modules/graphics/opengl/Canvas.h

View file
  • Ignore whitespace
 
 		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;
 

File src/modules/graphics/opengl/wrap_Canvas.cpp

View file
  • Ignore whitespace
 		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);
 	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 },

File src/modules/graphics/opengl/wrap_Canvas.h

View file
  • Ignore whitespace
 	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);