Well, when I tried to display text with different vertical extents like lower case ‘g’, it obviously didn’t work, because it simply assumed all characters were the same height. So, I’ve got new stuff involving metrics for you. I don’t really have any need for all of them, but here’s an image I ripped off from who knows where, that shows you all the metrics involved in placement. Search around, I’m sure you’ll find the source.
FreeType Placement Metrics
The image. The additional metrics I’ve used are height and y-bearing. It’s pretty simple. In my original code I had a scale of (1,-1,1) to turn it rightside up. Then I positioned it at -y-font->pt, which was essentially adding the font height to y, in negative scale. But since in many fonts, not all glyphs are the same height, you must consiter each glyph. So I added another metric: float hoss[num_glyphs], height offsets. This was calculated by subtracting the height from the y-bearing, giving me a negative value. Then I changed -y-font->pt to -y-(font->pt-font->hoss[*ch]), which gave me the height offset calculated for that glyph.
And the actual code to calculate this was VERY simple. Given that you’ve just loaded your glyph, (as my article did,) you access face->glyph. So our old code was:
tf->wids[ch]=(float)(face->glyph->advance.x>>6);
tf->qvws[ch]=bitmap.width;
tf->qvhs[ch]=bitmap.rows;
tf->qtws[ch]=(float)bitmap.width/(float)width;
tf->qths[ch]=(float)bitmap.rows/(float)height;
Yeah. And then you’ve got the new code, which has the extra metric:
tf->wids[ch]=(float)(face->glyph->advance.x>>6);
tf->hoss[ch]=(float)((face->glyph->metrics.horiBearingY-face->glyph->metrics.height)>>6);
tf->qvws[ch]=bitmap.width;
tf->qvhs[ch]=bitmap.rows;
tf->qtws[ch]=(float)bitmap.width/(float)width;
tf->qths[ch]=(float)bitmap.rows/(float)height;
Now we have the old transform code:
glTranslatef(x,-y-font->pt,0);
Versus the new transform code, with correct height placement:
glTranslatef(x,-y-(font->pt-font->hoss[*ch]),0);
Hope this helps you. I’ll probably update the article to include this stuff eventually.