Posts Tagged ‘fonts’

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!  😀

h1

dynamic text affectors

September 14, 2008

Still working on fancy text rendering.  I have my basic rendering down, but also have a counter in place to iterate text effects.  Then, each string has an initial offset (added to the main counter) to keep strings from all being at the same point in their effects.  On top of that, there’s a per character counter within the draw loop as well, that allows you to offset the effect point for each character to create things like traveling waves in text.  I’m thinking of writing an affector object with a primary counter callback, a per-char counter callback, a string transform callback, and a per-char transform callback.

So, I’m basically just working on this for now.  The menus will be done as soon as I have the font system standardized, I guess you could call it.  I’ll be leaving it as is for now to work on the hub.  I’ll show both together depending on how important the fancy text becomes in the menus.
Peace.

h1

more freedom in font rendering / cool menus

September 13, 2008

I’m rewriting the font and text code to do the following:

  • No more display lists; render on-the-fly.
  • Instead store glyph metrics to use for draw functions.
  • Add some drawing effects, as enabled by this new on-the-fly freedom.

I’ll post some screenshots of this when I have (a) fancy draw modes for fonts and (b) the menu in place.

The menu itself is quite impressive looking.  It’s not finished yet, but did you ever play Metroid Prime Echoes (the second one)?  Well, it’s a lot like those hub menus.  I don’t care if it’s not original, what are they going to do, sue me?  That’s not intellectual property.  Those things are hella coolz0rz.  I can’t beleive I said that.  KTHXBYE!

h1

floculate continued, freetype blues

September 11, 2008

So, I’m still working on the codebase for this Floculate game.  Here’s what I’ve done so far:

  • Wrote a new video code base.  It has one API in a header file, and it compiles a different C file depending on the platform you’re compiling on.  This is done by having system.c include either system.linux.c or system.win32.c depending on platform defines.  system.win32.c is empty right now, because I’m still working on the GNU/Linux platform.  When I finish the platform specifics and rendering fundementals I’ll do the Win32 version.
  • Took the physics engine source dir and copied it over to the Floculate source dir, and then did a make reference to the rat_physics makefile of choice, followed by copying a temp file of librat_physics_double.a.  Double is the precision of the real type it’s compiled with.

Here’s what I’m working on now… freetype font rendering in OpenGL.  I want to make my own font engine so that it’s in C and only as big as it has to be.  Problem is, I have no idea where to start.  I know what I want to do, and how to do the second part.  Basically it goes like this:

  1. Use FreeType to render the desired glyphs to pixmap surfaces.
  2. Create a texture and metric datum for each glyph.
  3. Display them as textured quads given text input / special effects.

So I can create textures from pixmaps and display them as textured quads.  What I DON’T know how to do is render the font.  If anyone out there has some advice, please come forward.  And please, don’t be all ‘hurr hurr use a redy madee font engin.’  I don’t want to.  But if someone knows of a good example of using freetype to render to pixmaps, then making textures from that, great.  I’ll keep posting on this until we’re all resolved.

On a random tangent: listen to Under The Weeping Moon.  It’s an awesome song.