one texture for whole font vs one texture per char

Started by
5 comments, last by blackpawn 15 years, 4 months ago
For drawing fonts in opengl/directx, would using one texture for the whole font be faster than having many textures, each representing a different character of the same font? The reason I'm asking this is that my font drawing routine is a bit slow. I'm guessing switching between them textures are taking a bit of time. Would this be a valid guess?
Advertisement
Yes. You almost always want to use a single texture with all of the font glpyhs embedded. This lets you draw any amount of text in a single draw call, vs. one draw call per character. Depending on what kind of hardware and drivers you've got, the overhead per draw call can be pretty bad.
ya, you should really use a texture atlas for your font instead of individual textures because of the draw call overhead.

~Graham
Thanks, on my way to implementing some sort of bitmap font loader now :D Doesn't look complicated but reading the format seems to take some effort..

thanks
you could pack your glyphs together into a larger texture using this technique: www.blackpawn.com/texts/lightmaps
Interesting, lightmaps.. that seems to be different than the "lightmaps" most usually referred to (which has something to do with lighting?).

With these packed textures, will it ever cause float inaccuracies? As in, since texture coordinates are done using floating point, and when the texture being used is large enough, there will be a point when you won't have accurate textures? Just worried since this is ever more important with fonts.

I managed to find a bitmap text generator that does things for you, and I'm using it now (partly because the iphone also doesn't let you embed any custom fonts, unless you use freetype etc).
no floats have plenty of precision to address the pixel centers for the texture sizes. make sure to disable multisampling while rendering stuff like this so the gpu doesn't sample outside the glyph rects on the quad edges.

This topic is closed to new replies.

Advertisement