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?
<a href="http://craneossgd.files.wordpress.com/2011/10/image_freetype1.png" rel="nofollow">http://craneossgd.files.wordpress.com/2011/10/image_freetype1.png</a>
Code:
Thanks!!
The texture is always the same. Any idea where is the problem or what's going on?
<a href="http://craneossgd.files.wordpress.com/2011/10/image_freetype1.png" rel="nofollow">http://craneossgd.files.wordpress.com/2011/10/image_freetype1.png</a>
Code:
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!!