Commits

Alex Szpakowski committed 42239c2 Merge

Merged in changes from main repository

Comments (0)

Files changed (13)

src/modules/graphics/opengl/Canvas.cpp

 	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);

src/modules/graphics/opengl/Canvas.h

 
 	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;
 

src/modules/graphics/opengl/Font.cpp

 				// copy glyphquad (4 vertices) from original glyph to our current quad list
 				glyphquads.push_back(glyph->quad);
 
-				// 1.25 is magic line height for true type fonts
-				float lineheight = (type == FONT_TRUETYPE) ? floor(getHeight() / 1.25f + 0.5f) : 0.0f;
+				float lineheight = getBaseline();
 
 				// set proper relative position
 				for (int i = 0; i < 4; i++)
 	if (!Image::hasMipmapSupport())
 		throw love::Exception("Mipmap filtering is not supported on this system!");
 
-	GLboolean mipmapscreated;
-	glGetTexParameteriv(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, (GLint *)&mipmapscreated);
+	GLint mipmapscreated;
+	glGetTexParameteriv(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, &mipmapscreated);
 
 	// generate mipmaps for this image if we haven't already
 	if (!mipmapscreated)
 	textures.clear();
 }
 
+int Font::getAscent() const
+{
+	return rasterizer->getAscent();
+}
+
+int Font::getDescent() const
+{
+	return rasterizer->getDescent();
+}
+
+float Font::getBaseline() const
+{
+	// 1.25 is magic line height for true type fonts
+	return (type == FONT_TRUETYPE) ? floor(getHeight() / 1.25f + 0.5f) : 0.0f;
+}
+
 } // opengl
 } // graphics
 } // love

src/modules/graphics/opengl/Font.h

 	bool loadVolatile();
 	void unloadVolatile();
 
+	// Extra font metrics
+	int getAscent() const;
+	int getDescent() const;
+	float getBaseline() const;
+
 private:
 
 	enum FontType

src/modules/graphics/opengl/Image.cpp

 
 	bind();
 
-	GLboolean mipmapscreated;
-	glGetTexParameteriv(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, (GLint *)&mipmapscreated);
+	GLint mipmapscreated;
+	glGetTexParameteriv(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, &mipmapscreated);
 
 	// generate mipmaps for this image if we haven't already
 	if (!mipmapscreated)

src/modules/graphics/opengl/wrap_Canvas.cpp

 	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);
 {
 	{ "renderTo", w_Canvas_renderTo },
 	{ "getImageData", w_Canvas_getImageData },
+	{ "getPixel", w_Canvas_getPixel },
 	{ "setFilter", w_Canvas_setFilter },
 	{ "getFilter", w_Canvas_getFilter },
 	{ "setWrap", w_Canvas_setWrap },

src/modules/graphics/opengl/wrap_Canvas.h

 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);

src/modules/graphics/opengl/wrap_Font.cpp

 int w_Font_setFilter(lua_State *L)
 {
 	Font *t = luax_checkfont(L, 1);
-
-	Image::Filter f;
+	Image::Filter f = t->getFilter();
 
 	const char *minstr = luaL_checkstring(L, 2);
 	const char *magstr = luaL_optstring(L, 3, minstr);
 	if (!Image::getConstant(magstr, f.mag))
 		return luaL_error(L, "Invalid filter mode: %s", magstr);
 
-	if (lua_isnoneornil(L, 4))
-		f.mipmap = Image::FILTER_NONE; // mipmapping is disabled unless third argument is given
-	else
-	{
-		const char *mipmapstr = luaL_checkstring(L, 4);
-		if (!Image::getConstant(mipmapstr, f.mipmap))
-			return luaL_error(L, "Invalid filter mode: %s", mipmapstr);
-	}
-
 	try
 	{
 		t->setFilter(f);
 	Image::getConstant(f.mag, magstr);
 	lua_pushstring(L, minstr);
 	lua_pushstring(L, magstr);
+	return 2;
+}
+
+int w_Font_setMipmapFilter(lua_State *L)
+{
+	Font *t = luax_checkfont(L, 1);
+	Image::Filter f = t->getFilter();
+
+	if (lua_isnoneornil(L, 2))
+		f.mipmap = Image::FILTER_NONE; // mipmapping is disabled if no argument is given
+	else
+	{
+		const char *mipmapstr = luaL_checkstring(L, 2);
+		if (!Image::getConstant(mipmapstr, f.mipmap))
+			return luaL_error(L, "Invalid filter mode: %s", mipmapstr);
+	}
+
+	try
+	{
+		t->setFilter(f);
+	}
+	catch(love::Exception &e)
+	{
+		return luaL_error(L, "%s", e.what());
+	}
+	
+	return 0;
+}
+
+int w_Font_getMipmapFilter(lua_State *L)
+{
+	Font *t = luax_checkfont(L, 1);
+	const Image::Filter f = t->getFilter();
 
 	const char *mipmapstr;
-	if (Image::getConstant(f.mipmap, mipmapstr))
-		lua_pushstring(L, mipmapstr);
-	else
-		lua_pushnil(L); // only return a mipmap filter if mipmapping is enabled
+	if (!Image::getConstant(f.mipmap, mipmapstr))
+		return 0; // only return a mipmap filter if mipmapping is enabled
 
-	return 3;
+	lua_pushstring(L, mipmapstr);
+
+	return 1;
 }
 
 int w_Font_setMipmapSharpness(lua_State *L)
 	return 1;
 }
 
+int w_Font_getAscent(lua_State *L)
+{
+	Font *t = luax_checkfont(L, 1);
+	lua_pushnumber(L, t->getAscent());
+	return 1;
+}
+
+int w_Font_getDescent(lua_State *L)
+{
+	Font *t = luax_checkfont(L, 1);
+	lua_pushnumber(L, t->getDescent());
+	return 1;
+}
+
+int w_Font_getBaseline(lua_State *L)
+{
+	Font *t = luax_checkfont(L, 1);
+	lua_pushnumber(L, t->getBaseline());
+	return 1;
+}
+
 static const luaL_Reg functions[] =
 {
 	{ "getHeight", w_Font_getHeight },
 	{ "getLineHeight", w_Font_getLineHeight },
 	{ "setFilter", w_Font_setFilter },
 	{ "getFilter", w_Font_getFilter },
+	{ "setMipmapFilter", w_Font_setMipmapFilter },
+	{ "getMipmapFilter", w_Font_getMipmapFilter },
 	{ "setMipmapSharpness", w_Font_setMipmapSharpness },
 	{ "getMipmapSharpness", w_Font_getMipmapSharpness },
+	{ "getAscent", w_Font_getAscent },
+	{ "getDescent", w_Font_getDescent },
+	{ "getBaseline", w_Font_getBaseline },
 	{ 0, 0 }
 };
 

src/modules/graphics/opengl/wrap_Font.h

 int w_Font_getLineHeight(lua_State *L);
 int w_Font_setFilter(lua_State *L);
 int w_Font_getFilter(lua_State *L);
+int w_Font_setMipmapFilter(lua_State *L);
+int w_Font_getMipmapFilter(lua_State *L);
 int w_Font_setMipmapSharpness(lua_State *L);
 int w_Font_getMipmapSharpness(lua_State *L);
+int w_Font_getAscent(lua_State *L);
+int w_Font_getDescent(lua_State *L);
+int w_Font_getBaseline(lua_State *L);
 extern "C" int luaopen_font(lua_State *L);
 
 } // opengl

src/modules/graphics/opengl/wrap_Graphics.cpp

 
 int w_setPointStyle(lua_State *L)
 {
-	Graphics::PointStyle style = Graphics::POINT_SMOOTH;
+	Graphics::PointStyle style;
 
-	if (lua_gettop(L) >= 2)
-	{
-		const char *str = luaL_checkstring(L, 1);
-		if (!Graphics::getConstant(str, style))
-			return luaL_error(L, "Invalid point style: %s", str);
-	}
+	const char *str = luaL_checkstring(L, 1);
+	if (!Graphics::getConstant(str, style))
+		return luaL_error(L, "Invalid point style: %s", str);
 
 	instance->setPointStyle(style);
 	return 0;
 {
 	float size = (float)luaL_checknumber(L, 1);
 
-	Graphics::PointStyle style;
-	const char *str = luaL_checkstring(L, 2);
-	if (!Graphics::getConstant(str, style))
-		return luaL_error(L, "Invalid point style: %s", str);
+	Graphics::PointStyle style = Graphics::POINT_SMOOTH;
+
+	if (lua_gettop(L) >= 2)
+	{
+		const char *str = luaL_checkstring(L, 2);
+		if (!Graphics::getConstant(str, style))
+			return luaL_error(L, "Invalid point style: %s", str);
+	}
 
 	instance->setPoint(size, style);
 	return 0;

src/modules/graphics/opengl/wrap_Image.cpp

 int w_Image_setFilter(lua_State *L)
 {
 	Image *t = luax_checkimage(L, 1);
-
-	Image::Filter f;
+	Image::Filter f = t->getFilter();
 
 	const char *minstr = luaL_checkstring(L, 2);
 	const char *magstr = luaL_optstring(L, 3, minstr);
 	if (!Image::getConstant(magstr, f.mag))
 		return luaL_error(L, "Invalid filter mode: %s", magstr);
 
-	if (lua_isnoneornil(L, 4))
-		f.mipmap = Image::FILTER_NONE; // mipmapping is disabled unless third argument is given
-	else
-	{
-		const char *mipmapstr = luaL_checkstring(L, 4);
-		if (!Image::getConstant(mipmapstr, f.mipmap))
-			return luaL_error(L, "Invalid filter mode: %s", mipmapstr);
-	}
-
 	try
 	{
 		t->setFilter(f);
 	Image::getConstant(f.mag, magstr);
 	lua_pushstring(L, minstr);
 	lua_pushstring(L, magstr);
+	return 2;
+}
+
+int w_Image_setMipmapFilter(lua_State *L)
+{
+	Image *t = luax_checkimage(L, 1);
+	Image::Filter f = t->getFilter();
+
+	if (lua_isnoneornil(L, 2))
+		f.mipmap = Image::FILTER_NONE; // mipmapping is disabled if no argument is given
+	else
+	{
+		const char *mipmapstr = luaL_checkstring(L, 2);
+		if (!Image::getConstant(mipmapstr, f.mipmap))
+			return luaL_error(L, "Invalid filter mode: %s", mipmapstr);
+	}
+
+	try
+	{
+		t->setFilter(f);
+	}
+	catch(love::Exception &e)
+	{
+		return luaL_error(L, "%s", e.what());
+	}
+	
+	return 0;
+}
+
+int w_Image_getMipmapFilter(lua_State *L)
+{
+	Image *t = luax_checkimage(L, 1);
+	const Image::Filter f = t->getFilter();
 
 	const char *mipmapstr;
-	if (Image::getConstant(f.mipmap, mipmapstr))
-		lua_pushstring(L, mipmapstr);
-	else
-		lua_pushnil(L); // only return a mipmap filter if mipmapping is enabled
+	if (!Image::getConstant(f.mipmap, mipmapstr))
+		return 0; // only return a mipmap filter if mipmapping is enabled
 
-	return 3;
+	lua_pushstring(L, mipmapstr);
+
+	return 1;
 }
 
 int w_Image_setWrap(lua_State *L)
 	{ "getFilter", w_Image_getFilter },
 	{ "setWrap", w_Image_setWrap },
 	{ "getWrap", w_Image_getWrap },
+	{ "setMipmapFilter", w_Image_setMipmapFilter },
+	{ "getMipmapFilter", w_Image_getMipmapFilter },
 	{ "setMipmapSharpness", w_Image_setMipmapSharpness },
 	{ "getMipmapSharpness", w_Image_getMipmapSharpness },
 	{ 0, 0 }

src/modules/graphics/opengl/wrap_Image.h

 int w_Image_getHeight(lua_State *L);
 int w_Image_setFilter(lua_State *L);
 int w_image_getFilter(lua_State *L);
+int w_Image_setMipmapFilter(lua_State *L);
+int w_Image_getMipmapFilter(lua_State *L);
 int w_Image_setWrap(lua_State *L);
 int w_Image_getWrap(lua_State *L);
 int w_Image_setMipmapSharpness(lua_State *L);

src/modules/graphics/opengl/wrap_ParticleSystem.cpp

 {
 	ParticleSystem *t = luax_checkparticlesystem(L, 1);
 	float arg1 = (float)luaL_checknumber(L, 2);
+	if (arg1 < 0.0f || arg1 > 1.0f)
+		return luaL_error(L, "Size variation has to be between 0 and 1, inclusive.");
+
 	t->setSizeVariation(arg1);
 	return 0;
 }