Posts Tagged ‘freetype fonts’

h1

super article update time and WOG

October 5, 2008

thundercats yay snerf snerf snerf snerf o-lion-o!

no, no, no, NO, NO!  no.  NO.  no…

😐

thundercats FAIL.

but they’re funny, so you can’t really hate them.  bawwww conk.

But the reason I’m posting is that I just updated the FreeType article with better code boxes plus proper vertical placement, a big thing I missed the first time like a total idiot!  The FreeType font article is already updated, will fix the code boxes on the others next.

WOG, that is to say, WORLD OF FUCKING AWESOME GOO, or for the uninitiated, World of Goo.  And it is COMING OUT on OCTOBER 13.  Yayuh.  If you pre-ordered, guess what, they send you a download link on the 6th.  Which means awesome times come sooner.

Advertisements
h1

FreeType + OpenGL revisited

October 4, 2008

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

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.


				
h1

gads, another page!

September 19, 2008

This one is about how to do freetype fonts in OpenGL!  Enjoy the read!  😀