Fonts in LOVE (VERY big problem)

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Fonts in LOVE (VERY big problem)

Post by Jasoco »

Why don't you use a TTF font? It would make the words kern better. Image fonts are not good for TTF style fonts because they can't kern. Image fonts are best for bitmapped words like you see in actual games. If you use TTF it would write the letters better. Like that "i" in "Multiplayer". Can't you see how ugly that is? It is bugging the hell out of my OCD. If I were playing this game, I'd be turned off by the menu becausemy brain can't help but notice these slight misalignments. I notice that misplaced "i" more than I notice the top button being off center. Sometimes being over-observant is a curse.
User avatar
RPG
Party member
Posts: 157
Joined: Wed Mar 02, 2011 5:02 am
Location: Russia
Contact:

Re: Fonts in LOVE (VERY big problem)

Post by RPG »

Jasoco wrote:Why don't you use a TTF font? It would make the words kern better. Image fonts are not good for TTF style fonts because they can't kern. Image fonts are best for bitmapped words like you see in actual games. If you use TTF it would write the letters better. Like that "i" in "Multiplayer". Can't you see how ugly that is? It is bugging the hell out of my OCD. If I were playing this game, I'd be turned off by the menu becausemy brain can't help but notice these slight misalignments. I notice that misplaced "i" more than I notice the top button being off center. Sometimes being over-observant is a curse.
Ugly kerning there only because of poor current implementation of bitmap fonts in LOVE. Bitmap fonts I suggest do not have such a problem. Proof: http://www.angelcode.com/dev/bmfonts/

As I said earlier, due to the fact that our game lets you use any resolution, ttf fonts will take a lot of memory. Also ttf fonts slow as hell (I wrote about it) because LOVE makes new texture for each glyph. Bitmap fonts use only one texture.
User avatar
Lafolie
Inner party member
Posts: 809
Joined: Tue Apr 05, 2011 2:59 pm
Location: SR388
Contact:

Re: Fonts in LOVE (VERY big problem)

Post by Lafolie »

That example is pretty bad. I'm a type geek so maybe my opinion is biased but it looks terrible. Could be so much better.
Do you recognise when the world won't stop for you? Or when the days don't care what you've got to do? When the weight's too tough to lift up, what do you? Don't let them choose for you, that's on you.
User avatar
bmelts
Party member
Posts: 380
Joined: Fri Jan 30, 2009 3:16 am
Location: Wiscönsin
Contact:

Re: Fonts in LOVE (VERY big problem)

Post by bmelts »

RPG wrote:As I said earlier, due to the fact that our game lets you use any resolution, ttf fonts will take a lot of memory. Also ttf fonts slow as hell (I wrote about it) because LOVE makes new texture for each glyph. Bitmap fonts use only one texture.
Two things:

1) TTF fonts will be much faster and more efficient in 0.8.0 - they use one texture again.
2) Bitmap fonts tend to look hideous when scaled* - as you can see. It would look far nicer to simply create an appropriately-sized font from a TTF when the resolution is set, unless you plan on including a LOT of bitmap fonts of various sizes - which would increase the game's size and might well actually use more memory anyway thanks to how LÖVE is forced to store Images.

* with the exception of deliberately pixelly fonts with the filter set to "nearest" - that looks fine.
User avatar
ishkabible
Party member
Posts: 241
Joined: Sat Oct 23, 2010 7:34 pm
Location: Kansas USA

Re: Fonts in LOVE (VERY big problem)

Post by ishkabible »

i don't really see anything wrong with the current implementation of Love and it's TTF fonts. if there are some issues with the rendering of TTF fonts they can likely be fixed by storing the current size in a display list then when you need to re-sizing the font you create a new display list from scratch.

i used something like the following to store fonts in the past.

Code: Select all

class Font {
friend class Graphics;
private:
	GLuint list;
	GLuint *textures;
	short h;
	Font(const Font& F) : list(F.list),textures(F.textures),h(F.h) {}
	Font& operator=(const Font& F) {
		list = F.list;
		textures = F.textures;
		return *this;
	}
public:
	Font(GLuint l, GLuint *t, short H) : h(H), list(l), textures(t) {}
	~Font() {
		glDeleteLists(list,128);
		glDeleteTextures(128,textures);
		delete [] textures;
	}
};
to print it

Code: Select all

void print(std::string text,short x, short y) {
		size_t size = text.size();
		if(font==NULL)return;
		short h = font->h;
		std::string line;
		std::deque<std::string> lines;
		for(unsigned int i=0;i<size;++i) {
			if(text[i]=='\n') {
				lines.push_back(line);
				line.clear();
				i+1<size&&++i;
			}
			line += text[i];
		}

		float modelview_matrix[16];
		glGetFloatv(GL_MODELVIEW_MATRIX, modelview_matrix);
		lines.push_back(line);
		size = lines.size();
		glListBase(font->list);
		for(unsigned int i=0;i<size;++i) {
			glPushMatrix();
			glLoadIdentity();
			glTranslatef(x,y+h*i,0);
			glMultMatrixf(modelview_matrix);
			glCallLists(lines[i].size(), GL_UNSIGNED_BYTE, lines[i].c_str());
			glPopMatrix();
		}
	}
to create it

Code: Select all

FontPtr newFont(std::string filepath, short size) {
		GLuint* textures = new GLuint[128];
		FT_Library lib;
		FT_Init_FreeType( &lib );
		FT_Face face;
		FT_New_Face(lib,filepath.c_str(),0,&face);
		FT_Set_Char_Size( face, size << 6, size << 6, 96, 96);
		GLuint list=glGenLists(128);
		glGenTextures( 128, textures );
		for(unsigned char i=0;i<128;i++) {
			make_dlist(face,i,list,textures);
		}
		FT_Done_Face(face);
		FT_Done_FreeType(lib);
        return FontPtr(new Font(list, textures, size));
    }
O and 2 helper functions i used here, 1 of which is very importent

Code: Select all

inline float calculate_variation(float inner, float outer, float var) {
	float low = inner - (outer/2.0f)*var;
	float high = inner + (outer/2.0f)*var;
	float r = (rand() / (float(RAND_MAX)+1));
	return low*(1-r)+high*r;
}

inline int next_p2 (int a ) {
	int rval=1;
	while(rval<a)rval<<=1;
	return rval;
}

inline void make_dlist( FT_Face face, unsigned char ch, GLuint list_base, GLuint* tex_base ) {
	FT_Load_Glyph( face, FT_Get_Char_Index( face, ch ), FT_LOAD_DEFAULT );
	FT_Glyph glyph;
	FT_Get_Glyph( face->glyph, &glyph );
	FT_Glyph_To_Bitmap( &glyph, ft_render_mode_normal, 0, 1 );
	FT_BitmapGlyph bitmap_glyph = (FT_BitmapGlyph)glyph;
	FT_Bitmap& bitmap=bitmap_glyph->bitmap;
	int width = next_p2( bitmap.width );
	int height = next_p2( bitmap.rows );
	GLubyte* expanded_data = new GLubyte[ 2 * width * height];
	for(int j=0; j <height;j++) {
		for(int i=0; i < width; i++){
			expanded_data[2*(i+j*width)]= expanded_data[2*(i+j*width)+1] =
				(i>=bitmap.width || j>=bitmap.rows) ?
				0 : bitmap.buffer[i + bitmap.width*j];
		}
	}
	glBindTexture( GL_TEXTURE_2D, tex_base[ch]);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
	glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0,
		GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, expanded_data );
	delete [] expanded_data;
	glNewList(list_base+ch,GL_COMPILE);
	glBindTexture(GL_TEXTURE_2D,tex_base[ch]);
	glPushMatrix();
	glTranslatef(bitmap_glyph->left,0,0);
	glTranslatef(0,-bitmap_glyph->top,0);
	float x=(float)bitmap.width / (float)width;
	float y=(float)bitmap.rows / (float)height;
	glBegin(GL_QUADS);
	glTexCoord2d(0,0); glVertex2f(0,0);
	glTexCoord2d(0,y); glVertex2f(0,bitmap.rows);
	glTexCoord2d(x,y); glVertex2f(bitmap.width,bitmap.rows);
	glTexCoord2d(x,0); glVertex2f(bitmap.width,0);
	glEnd();
	glPopMatrix();
	glTranslatef(face->glyph->advance.x >> 6 ,0,0);
	glEndList();
}
edit: fun little snipit of code i saw in there "i+1<size&&++i;", short circuit logic to create terse if statements!!
User avatar
RPG
Party member
Posts: 157
Joined: Wed Mar 02, 2011 5:02 am
Location: Russia
Contact:

Re: Fonts in LOVE (VERY big problem)

Post by RPG »

All professional game engines support this type of bitmap fonts. I hope LOVE will not be worse.

I'd also like to manage game fonts. All known games use the type of font, which I showed.

If I understood correctly, LOVE will never support bitmap fonts?
User avatar
RPG
Party member
Posts: 157
Joined: Wed Mar 02, 2011 5:02 am
Location: Russia
Contact:

Re: Fonts in LOVE (VERY big problem)

Post by RPG »

This is my old bitmap font implementation:
Image
Looks very fine I think. This font has size only 3 kb's. Pay attention to the fps.
User avatar
RPG
Party member
Posts: 157
Joined: Wed Mar 02, 2011 5:02 am
Location: Russia
Contact:

Re: Fonts in LOVE (VERY big problem)

Post by RPG »

I also want to explain my position. If you want to use very large font (16 pixels or more), it is better to create bitmap font size 50 pixels and reduce it to the desired value.

If you need a very small font, you should use a monochrome bitmap fonts, because it looks very clear. In LOVE, small fonts look very blurry and you can not disable anti-aliasing from lua script. This font uses very small amount of memory.
User avatar
Lafolie
Inner party member
Posts: 809
Joined: Tue Apr 05, 2011 2:59 pm
Location: SR388
Contact:

Re: Fonts in LOVE (VERY big problem)

Post by Lafolie »

Triple post D:

I would have thought that using vector-based fonts for large sizes is the better choice since bitmap images increase in (memory) size the bigger they get, whereas a vector-based format is one-size-fits-all, so to speak. Plus, vectors are as such, thus can be scaled without any artefacts/distortion, whereas scaling a bitmap has several implications (as you have demonstrated). If you want your GUI to be truly scalable, then TTF typefaces are the best solution.

This is a pretty obvious conclusion to reach since vector-based font formats are widely used (such as by the OS you're using, probably). As for the anti-aliasing of smaller type... well I'm not sure if there is a way to stop that. I haven't played about with fonts on Löve yet.
Do you recognise when the world won't stop for you? Or when the days don't care what you've got to do? When the weight's too tough to lift up, what do you? Don't let them choose for you, that's on you.
User avatar
RPG
Party member
Posts: 157
Joined: Wed Mar 02, 2011 5:02 am
Location: Russia
Contact:

Re: Fonts in LOVE (VERY big problem)

Post by RPG »

Sometimes you need to full control over your fonts, for example, outline, decorative text, anti-aliasing.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 231 guests