diff --git a/src/modules/graphics/opengl/Font.cpp b/src/modules/graphics/opengl/Font.cpp index 7d576f9a3..97ba816bb 100644 --- a/src/modules/graphics/opengl/Font.cpp +++ b/src/modules/graphics/opengl/Font.cpp @@ -31,8 +31,8 @@ namespace graphics namespace opengl { - Font::Font(love::font::FontData * data) - : height(data->getHeight()), lineHeight(1.25), mSpacing(1) + Font::Font(love::font::FontData * data, const Image::Filter& filter) + : height(data->getHeight()), lineHeight(1), mSpacing(1) { glyphs = new Glyph*[MAX_CHARS]; type = FONT_UNKNOWN; @@ -41,7 +41,7 @@ namespace opengl for(unsigned int i = 0; i < MAX_CHARS; i++) { gd = data->getGlyphData(i); - glyphs[i] = new Glyph(gd); + glyphs[i] = new Glyph(gd, filter); glyphs[i]->load(); widths[i] = gd->getWidth(); spacing[i] = gd->getAdvance(); @@ -62,7 +62,7 @@ namespace opengl float Font::getHeight() const { - return height / lineHeight; + return height; } void Font::print(std::string text, float x, float y, float angle, float sx, float sy) const @@ -76,13 +76,14 @@ namespace opengl for (unsigned int i = 0; i < text.size(); i++) { unsigned char g = (unsigned char)text[i]; if (g == '\n') { // wrap newline, but do not print it - glTranslatef(-dx, floor(getHeight() + 0.5f), 0); + glTranslatef(-dx, floor(getHeight() * getLineHeight() + 0.5f), 0); dx = 0.0f; continue; } if (!glyphs[g]) g = 32; // space glPushMatrix(); - if (type == FONT_TRUETYPE) glTranslatef(0, floor(getHeight() + 0.5f), 0); + // 1.25 is magic line height for true type fonts + if (type == FONT_TRUETYPE) glTranslatef(0, floor(getHeight() / 1.25f + 0.5f), 0); glyphs[g]->draw(0, 0, 0, 1, 1, 0, 0); glPopMatrix(); glTranslatef(spacing[g], 0, 0); @@ -93,7 +94,7 @@ namespace opengl void Font::print(char character, float x, float y) const { - if (!glyphs[character]) character = ' '; + if (!glyphs[(int)character]) character = ' '; glPushMatrix(); glTranslatef(x, floor(y+getHeight() + 0.5f), 0.0f); glCallList(list+character); diff --git a/src/modules/graphics/opengl/Font.h b/src/modules/graphics/opengl/Font.h index a277a62e9..84bd9a7d9 100644 --- a/src/modules/graphics/opengl/Font.h +++ b/src/modules/graphics/opengl/Font.h @@ -27,6 +27,7 @@ // LOVE #include #include +#include #include "Glyph.h" namespace love @@ -69,7 +70,7 @@ namespace opengl * * @param data The font data to construct from. **/ - Font(love::font::FontData * data); + Font(love::font::FontData * data, const Image::Filter& filter = Image::Filter()); virtual ~Font(); diff --git a/src/modules/graphics/opengl/Glyph.cpp b/src/modules/graphics/opengl/Glyph.cpp index d1b0a4c07..bbee12489 100644 --- a/src/modules/graphics/opengl/Glyph.cpp +++ b/src/modules/graphics/opengl/Glyph.cpp @@ -30,8 +30,10 @@ namespace graphics namespace opengl { - Glyph::Glyph(love::font::GlyphData * data) - : data(data), width((float)data->getWidth()), height((float)data->getHeight()), texture(0) + Glyph::Glyph(love::font::GlyphData * data, const Image::Filter& filter_) + : data(data), + width((float)data->getWidth()), height((float)data->getHeight()), + texture(0), filter(filter_) { data->retain(); @@ -99,8 +101,10 @@ namespace opengl glGenTextures(1,&texture); glBindTexture(GL_TEXTURE_2D, texture); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, + (filter.mag == Image::FILTER_LINEAR) ? GL_LINEAR : GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, + (filter.min == Image::FILTER_LINEAR) ? GL_LINEAR : GL_NEAREST); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); diff --git a/src/modules/graphics/opengl/Glyph.h b/src/modules/graphics/opengl/Glyph.h index d6c2578c0..331a46167 100644 --- a/src/modules/graphics/opengl/Glyph.h +++ b/src/modules/graphics/opengl/Glyph.h @@ -28,6 +28,7 @@ #include #include #include +#include // OpenGL #include "GLee.h" @@ -52,10 +53,12 @@ namespace opengl vertex vertices[4]; + Image::Filter filter; + public: - Glyph(love::font::GlyphData * data); + Glyph(love::font::GlyphData * data, const Image::Filter& filter_ = Image::Filter()); virtual ~Glyph(); bool load(); diff --git a/src/modules/graphics/opengl/Graphics.cpp b/src/modules/graphics/opengl/Graphics.cpp index df59c1057..3e1f32ac6 100644 --- a/src/modules/graphics/opengl/Graphics.cpp +++ b/src/modules/graphics/opengl/Graphics.cpp @@ -461,9 +461,9 @@ namespace opengl return new Quad(v, sw, sh); } - Font * Graphics::newFont(love::font::FontData * data) + Font * Graphics::newFont(love::font::FontData * data, const Image::Filter& filter) { - Font * font = new Font(data); + Font * font = new Font(data, filter); // Load it and check for errors. if(!font) @@ -917,6 +917,7 @@ namespace opengl switch(mode) { case DRAW_LINE: + // offsets here because OpenGL is being a bitch about line drawings glBegin(GL_LINE_LOOP); glVertex2f(x, y); glVertex2f(x, y+h-1); diff --git a/src/modules/graphics/opengl/Graphics.h b/src/modules/graphics/opengl/Graphics.h index 00bc7df61..eb3c58fe8 100644 --- a/src/modules/graphics/opengl/Graphics.h +++ b/src/modules/graphics/opengl/Graphics.h @@ -261,7 +261,7 @@ namespace opengl /** * Creates a Font object. **/ - Font * newFont(love::font::FontData * data); + Font * newFont(love::font::FontData * data, const Image::Filter& filter = Image::Filter()); SpriteBatch * newSpriteBatch(Image * image, int size, int usage); diff --git a/src/modules/graphics/opengl/wrap_Graphics.cpp b/src/modules/graphics/opengl/wrap_Graphics.cpp index 63cd882b1..674182d27 100644 --- a/src/modules/graphics/opengl/wrap_Graphics.cpp +++ b/src/modules/graphics/opengl/wrap_Graphics.cpp @@ -254,11 +254,15 @@ namespace opengl int w_newImageFont(lua_State * L) { + // filter for glyphs, defaults to linear/linear + Image::Filter img_filter; + // Convert to ImageData if necessary. if(lua_isstring(L, 1) || luax_istype(L, 1, FILESYSTEM_FILE_T) || (luax_istype(L, 1, DATA_T) && !luax_istype(L, 1, IMAGE_IMAGE_DATA_T) && !luax_istype(L, 1, FONT_FONT_DATA_T))) luax_convobj(L, 1, "image", "newImageData"); else if(luax_istype(L, 1, GRAPHICS_IMAGE_T)) { Image * i = luax_checktype(L, 1, "Image", GRAPHICS_IMAGE_T); + img_filter = i->getFilter(); love::image::ImageData * id = i->getData(); luax_newtype(L, "ImageData", IMAGE_IMAGE_DATA_T, (void*)id, false); lua_replace(L, 1); @@ -277,7 +281,7 @@ namespace opengl love::font::FontData * data = luax_checktype(L, 1, "FontData", FONT_FONT_DATA_T); // Create the font. - Font * font = instance->newFont(data); + Font * font = instance->newFont(data, img_filter); if(font == 0) return luaL_error(L, "Could not load font.");