Reputation: 123
I'm using freetype for writing text in an IPhone device, the result are rare. As you can see in the image same characters(like 'b', 'n' or 'u') aren't rendered equally.
The texture is always the same. Any idea where is the problem or what's going on?
http://craneossgd.files.wordpress.com/2011/10/image_freetype1.png
Code:
FT_New_Face(getFTLibrary(), _filename, 0, &(_face))
FT_Select_Charmap( _face, FT_ENCODING_UNICODE );
FT_Set_Char_Size( _face, _pt<<6,_pt<<6, _dpi, _dpi);
for (i=0; i<255; i++)
{
if (!createGlyphTexture(i))
{
clean();
}
}
.....
createGlyphTexture(unsigned char ch){
....
FT_Load_Glyph(_face, FT_Get_Char_Index(_face,ch), FT_LOAD_DEFAULT)
FT_Get_Glyph(_face->glyph, &glyph)
....
// *** Transform glyph to bitmap
FT_Glyph_To_Bitmap(&glyph, FT_RENDER_MODE_NORMAL, 0, 1);
// *** Get bitmap and glyph data
bitmap_glyph = (FT_BitmapGlyph)glyph;
bitmap = bitmap_glyph->bitmap;
// ***
width = pow2(bitmap.width);
height = pow2(bitmap.rows);
// *** Alloc memory for texture
expanded_data = (GLubyte *)malloc( sizeof(GLubyte)*2*width*height );
for (j=0; j<height;j++)
{
for (i=0; i<width; i++)
{
if ( (i>=(CRuint)bitmap.width) || (j>=(CRuint)bitmap.rows) ){
expanded_data[2*(i+j*width)] = 0;
expanded_data[2*(i+j*width)+1] = 0;
} else {
expanded_data[2*(i+j*width)] = bitmap.buffer[i+bitmap.width*j];
expanded_data[2*(i+j*width)+1] = bitmap.buffer[i+bitmap.width*j];
}
}
}
// *** Load texture into memory
glBindTexture(GL_TEXTURE_2D, _textures[ch]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_LUMINANCE_ALPHA, width, height, 0, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, expanded_data);
....
}
Thanks!!
Upvotes: 0
Views: 2726
Reputation: 123
In freetype reference: http://www.freetype.org/freetype2/docs/reference/ft2-base_interface.html
FT_LOAD_TARGET_LIGHT. A lighter hinting algorithm for non-monochrome modes. Many generated glyphs are more fuzzy but better resemble its original shape. A bit like rendering on Mac OS X. As a special exception, this target implies FT_LOAD_FORCE_AUTOHINT.
FT_RENDER_MODE_LIGHT.This is equivalent to FT_RENDER_MODE_NORMAL. It is only defined as a separate value because render modes are also used indirectly to define hinting algorithm selectors. See FT_LOAD_TARGET_XXX for details.
It works using next configuration:
FT_Load_Glyph(_face, FT_Get_Char_Index(_face,ch), FT_LOAD_TARGET_LIGHT)
...
FT_Glyph_To_Bitmap(&glyph, FT_RENDER_MODE_NORMAL, 0, 1);
Upvotes: 1