Fix issue #136 - Filter for Imagefonts.

This commit is contained in:
vrld
2011-01-07 14:08:10 +01:00
parent aa7ec54121
commit e3067ff33d
7 changed files with 26 additions and 13 deletions
+3 -3
View File
@@ -31,7 +31,7 @@ namespace graphics
namespace opengl namespace opengl
{ {
Font::Font(love::font::FontData * data) Font::Font(love::font::FontData * data, const Image::Filter& filter)
: height(data->getHeight()), lineHeight(1.25), mSpacing(1) : height(data->getHeight()), lineHeight(1.25), mSpacing(1)
{ {
glyphs = new Glyph*[MAX_CHARS]; glyphs = new Glyph*[MAX_CHARS];
@@ -41,7 +41,7 @@ namespace opengl
for(unsigned int i = 0; i < MAX_CHARS; i++) for(unsigned int i = 0; i < MAX_CHARS; i++)
{ {
gd = data->getGlyphData(i); gd = data->getGlyphData(i);
glyphs[i] = new Glyph(gd); glyphs[i] = new Glyph(gd, filter);
glyphs[i]->load(); glyphs[i]->load();
widths[i] = gd->getWidth(); widths[i] = gd->getWidth();
spacing[i] = gd->getAdvance(); spacing[i] = gd->getAdvance();
@@ -93,7 +93,7 @@ namespace opengl
void Font::print(char character, float x, float y) const void Font::print(char character, float x, float y) const
{ {
if (!glyphs[character]) character = ' '; if (!glyphs[(int)character]) character = ' ';
glPushMatrix(); glPushMatrix();
glTranslatef(x, floor(y+getHeight() + 0.5f), 0.0f); glTranslatef(x, floor(y+getHeight() + 0.5f), 0.0f);
glCallList(list+character); glCallList(list+character);
+2 -1
View File
@@ -27,6 +27,7 @@
// LOVE // LOVE
#include <common/Object.h> #include <common/Object.h>
#include <font/FontData.h> #include <font/FontData.h>
#include <graphics/Image.h>
#include "Glyph.h" #include "Glyph.h"
namespace love namespace love
@@ -69,7 +70,7 @@ namespace opengl
* *
* @param data The font data to construct from. * @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(); virtual ~Font();
+8 -4
View File
@@ -30,8 +30,10 @@ namespace graphics
namespace opengl namespace opengl
{ {
Glyph::Glyph(love::font::GlyphData * data) Glyph::Glyph(love::font::GlyphData * data, const Image::Filter& filter_)
: data(data), width((float)data->getWidth()), height((float)data->getHeight()), texture(0) : data(data),
width((float)data->getWidth()), height((float)data->getHeight()),
texture(0), filter(filter_)
{ {
data->retain(); data->retain();
@@ -99,8 +101,10 @@ namespace opengl
glGenTextures(1,&texture); glGenTextures(1,&texture);
glBindTexture(GL_TEXTURE_2D, texture); glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); (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_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+4 -1
View File
@@ -28,6 +28,7 @@
#include <font/GlyphData.h> #include <font/GlyphData.h>
#include <graphics/Drawable.h> #include <graphics/Drawable.h>
#include <graphics/Volatile.h> #include <graphics/Volatile.h>
#include <graphics/Image.h>
// OpenGL // OpenGL
#include "GLee.h" #include "GLee.h"
@@ -52,10 +53,12 @@ namespace opengl
vertex vertices[4]; vertex vertices[4];
Image::Filter filter;
public: public:
Glyph(love::font::GlyphData * data); Glyph(love::font::GlyphData * data, const Image::Filter& filter_ = Image::Filter());
virtual ~Glyph(); virtual ~Glyph();
bool load(); bool load();
+3 -2
View File
@@ -461,9 +461,9 @@ namespace opengl
return new Quad(v, sw, sh); 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. // Load it and check for errors.
if(!font) if(!font)
@@ -917,6 +917,7 @@ namespace opengl
switch(mode) switch(mode)
{ {
case DRAW_LINE: case DRAW_LINE:
// offsets here because OpenGL is being a bitch about line drawings
glBegin(GL_LINE_LOOP); glBegin(GL_LINE_LOOP);
glVertex2f(x, y); glVertex2f(x, y);
glVertex2f(x, y+h-1); glVertex2f(x, y+h-1);
+1 -1
View File
@@ -261,7 +261,7 @@ namespace opengl
/** /**
* Creates a Font object. * 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); SpriteBatch * newSpriteBatch(Image * image, int size, int usage);
@@ -254,11 +254,15 @@ namespace opengl
int w_newImageFont(lua_State * L) int w_newImageFont(lua_State * L)
{ {
// filter for glyphs, defaults to linear/linear
Image::Filter img_filter;
// Convert to ImageData if necessary. // 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))) 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"); luax_convobj(L, 1, "image", "newImageData");
else if(luax_istype(L, 1, GRAPHICS_IMAGE_T)) { else if(luax_istype(L, 1, GRAPHICS_IMAGE_T)) {
Image * i = luax_checktype<Image>(L, 1, "Image", GRAPHICS_IMAGE_T); Image * i = luax_checktype<Image>(L, 1, "Image", GRAPHICS_IMAGE_T);
img_filter = i->getFilter();
love::image::ImageData * id = i->getData(); love::image::ImageData * id = i->getData();
luax_newtype(L, "ImageData", IMAGE_IMAGE_DATA_T, (void*)id, false); luax_newtype(L, "ImageData", IMAGE_IMAGE_DATA_T, (void*)id, false);
lua_replace(L, 1); lua_replace(L, 1);
@@ -277,7 +281,7 @@ namespace opengl
love::font::FontData * data = luax_checktype<love::font::FontData>(L, 1, "FontData", FONT_FONT_DATA_T); love::font::FontData * data = luax_checktype<love::font::FontData>(L, 1, "FontData", FONT_FONT_DATA_T);
// Create the font. // Create the font.
Font * font = instance->newFont(data); Font * font = instance->newFont(data, img_filter);
if(font == 0) if(font == 0)
return luaL_error(L, "Could not load font."); return luaL_error(L, "Could not load font.");