Hi Everyone,
I'm trying to render text using OpenGL and the Freetype library. Text rendering is working fine except for one thing. Every now and then, a character is spaced incorrectly:
Above you can see the 'j' in jumps is clashing with the 'u'. I've tried different fonts, but they also produce odd spacing errors:
In that case, the 'p' in jumps and 'g' in dog isn't spaced correctly either.
the way I create the horizontal offsets for characters in the final texture is by using the advance.x property on the resulting glyph and adding any kerning values for the character:
//first get kerning if we're passed the first character and this font has kerning
if ((i >= 1) && (Font->HasKerning == true))
{
FT_Get_Kerning(FontFace, PreviousGlyph, CurrentGlyph, FT_KERNING_DEFAULT, &KerningVector);
HorizontalOffset += KerningVector.x >> 6;
}
/* This is where the pixels are copied from the glyph into the texture */
/* HorizontalOffset is the 'X' value starting point for the new glyph */
//now that we're done copying over the pixel data, we update the Offset based on the glyphs advance
HorizontalOffset += FontFace->glyph->advance.x >> 6
On closer inspection, I noticed the advance.x value for the character 'j' for the font in the first image is much smaller than the other characters, 13 as opposed to the average of +-28. I believe that is the cause of the 'u' overwriting it. If I open both font's in the windows font viewer, they render correctly, they also render correctly in GIMP. It seems to be only my application thats rendering them incorrectly
My question is, how should I go about fixing this issue? Is there something I'm missing here?
Thanks.