Font rendering

I’ve inherited some jogl font rendering code which can’t handle multinational character sets at all. Does anyone know of ways to handle more of the range of fonts available to a regular jvm? I’ve found a URL on the web that says how to do bitmap fonts but only on Windows, so I thought I’d check here (but the search revealed no instances of the word font in the whole forum.

Here’s the OpenGL lesson for font rendering:

http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=13

 Thanks,
 Harold Shinsato

I’m not sure if this is anything like what you’re after, but what I decided to do for a recent font issue was to just use java fonts - I write my text to an image, then draw that scaled onto an image with the next power-of-two size dimensions.

This image I use for an openGL texture.

Since you’d be using Java fonts, they’ll handle exactly all of the fonts available to a regular VM ;o)

My approach is like the one of kaffiene:

Render ‘all’ 256 chars to a 256x256 BufferedImage on a 16x16 grid, make that a texture, and create text with a bunch of quads with correct texcoords.

Mess a bit with FontMetrics to handle all kinds of Fonts.

Pro: very reusable for dynamic texts
Con: you can only have 1 pretty small Font per texture

256x256 is sooo 1998 :slight_smile: Seriously, don’t be afraid to use much, much bigger textures, and make sure they’re alpha-luminance format (8 bits greyscale and 8 bits alpha).

For any kind of international font rendering you’ll have to render out far more than 256 glyphs… more like 2000 to cover 99% of everywhere.

Cas :slight_smile:

and make sure they’re alpha-luminance format

Oooh. Yea, I forgot :stuck_out_tongue:

Well, here is a neat list with all those internal formats:
http://www.opengl.org/resources/tutorials/sig99/advanced99/notes/node51.html

RGBA4 is for example pretty neat for hand drawn comic style images :wink:

For any kind of international font rendering you’ll have to
render out far more than 256 glyphs… more like 2000 to
cover 99% of everywhere.

True. Fortunately plain english is good enough for most games (that is if you don’t have much text to begin with… everyone knows start, options, exit and the like).

You’d be surprised at some of the apparently odd symbols you need… £ signs and bullet points for example.

Cas :slight_smile:

The code I inherited is doing the quad painting with a preformatted font bitmap file, but the kerning is terrible. I’m sure it’s much faster to write them that way, but I’m wondering if the performance wouldn’t be too bad using the approach that kaffiene describes - which would also provide the advantage of handling things like hebrew or arabic where the text goes from right to left, and even mixed text where you have some text that goes one way, and some text that goes the other. Are there any code examples of writing the text to an image?

   Thanks!
   Harold

Browse the CVS to com.shavenpuppy.jglib.tools.FontConverter.java

Note how it works out the kerning. Slow, but the only way to do it.

Cas :slight_smile: