fonts & speed

My solution to the problem I had a few weeks ago about bitmap fonts being too slow and texture fonts being too ugly is to display the bitmapped font at startup in an evenly-spaced, ASCII-order grid, then read the frame buffer back as LUMINENCE data, and then create a texture font from this as LUMINENCE_ALPHA data (setting alpha to FF for non-zero pixels and 00 for zero ones), and finally create a set of display lists (one per char).

Defining the texture with GL_NEAREST gives bad results (the lines of each character are not the same width) even though since I’m trying to recreate the font in the exact same size it seems this should be OK. I use GL_LINEAR and it’s fuzzier than I would like but the characters have a regular width.

The problem now is color. In order to get the correct color I use glGetFloatv (GL_CURRENT_COLOR) and then call glColorMask with the RGB components on or off per the read values (on or off is OK because the text will be either a primary (RGB) or secondary (CYM) color, no other shade). The use of glColorMask when not all 3 colors are on adds almost 40 ms to my frame time (22 vs. 61). That is, forcing all on for white text is fast, forcing all off for black text is fast, but getting colored text by mixing on and off is slow. Is there a better (quicker) way to set the color, or is this a limitation of using texture mapped fonts?

You could send vertex colors for the color you want and modulate the texture with the color. Make sure you send an alpha value of 1.0, though.

I have tried setting the color with glColor3f(), but the text always shows up white, as per the original texture. I was under the impression that because textures may have a very complicated color mix (as in a photograph, each pixel may have a different blend of RGB), the color values used for each pixel must come from the original source pixel. The glColorMask call I am using is just a crude way of disabling certain colors that works in my case because each pixel in my font texture is either on or off.

You have to set your glTexEnv to GL_MODULATE in order to get vertex colors to mix with texture colors. I don’t recall the exact function call offhand, but it’s something like that. Do a search on GL_MODULATE here or on MSDN.

Thanks, I thought I had tried that but it turned out I had a glTexEnvf call with GL_REPLACE in the printstring routine and I only changed the one where I create the texture at startup. I found this other one and changed it and it worked (I wish all my problems were this easy). Thanks.