Your text rendering method

Started by
6 comments, last by technobot 19 years, 4 months ago
What text rendering method do you use in your games? Is it home grown or taken from elsewhere? Have you been able to re-use it in another project without modification? Does it support any advanced text formatting methods like RTF/HTML? What API it it designed for? or does it support more than one?
Advertisement
Well, I can say what we do :)

We have a bitmap for each font-type which contains all the chars. At load time the the bitmaps are read into memory. The tricky part is to load the chars into a displaylist (OpenGL) or vertex Buffer (DirectX/XBox), which depends on how the font bitmap is constructed.

Actually Nehe has a tutorial on how to do this, its lession-21 (which has a font .bmp file)

I'we implemented the main logic in a CText base class, and subclasses for each platform which handles the rendering.

good luck
www.pokersniffer.org
Mine is homegrown. I have two variations, one for 2d, one for 3d.

The base is pretty similar (building letters as images/sections of a texture). The text function simply displays a line of text.

I keep things like wrapping/formatting out of the text rendering, that's part of the GUI.

The 2d is built to work with GDI/DDraw (pointer to surface access), basically works with rectangular regions.

The old 3d version is built to work with Direct3d8, the new relies upon my abstract renderer interface, which has DX8 and DX9 plugins, and a very rudimentary OpenGL one (which i actually don't use).

I can reuse it in other projects without modification. This is, for basic text rendering. For special font effects like wavering i can still call single letter drawing functions. If it needs more than that i usually build specialized functions specific to a game/app.

Both use an abstract interface forcing them to provide TextLength/TextHeight functions (my GUI works with the font interface only, and needs those for aligning text).

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

Grayscale texture that has all the chars + single quad per char in a set of display lists + blending/alpha-testing using the greyscale as alpha and luminance + external color setting (glSetColorxxx). Probably not the most efficient, but it works. We only have the texture font class atm, but we'll probably move the texture handling to a subclass at a later stage, and add other subclasses for different texture types (bitmap, 3D, color texture, and whatever else we'll need).

P.S.: We're targetting OpenGL only.
Michael K.
This is extremely interesting to me as I am currently looking for the best way to write a text engine in OpenGL. I want a methodology that supports standard font files for versatility, but also is cross-platform. This eliminates all Wgl stuff. Sdl also has no text functions. What would be the best solution for me?

My engine is C# Tao so I have an entirely different set of libraries at my disposal than most others posting here.
I use a bitmap with a regular grid of characters - and then seperate data for the kerning of the letters.
Rendered using quads and texture offsets (no texture swapping is good).
All provided by the Bitmap Font Builder :
http://www.lmnopc.com/bitmapfontbuilder/

I like text that is variable spaced, and nicely kerned, and that supports all the font options that my OS supports (in this case, Windows). Thus, I have a system which supports drawing text to offscreen surfaces, and another system which supports tieing surfaces to textures. I wrote it a few years ago, and just re-use it in each new setting.

Basically, it revolves around CreateDIBSection() and CreateCompatibleDC(), and the uses TexSubImage() on GL, and Lock() and memcpy() on Direct3D. If I'm to port to Linux, I'd have to re-implement the text-to-offscreen interface on top of something like FreeType, but that wouldn't be too hard (and a port is pretty far away, anyway).
enum Bool { True, False, FileNotFound };
Quote:Original post by Lithic
This is extremely interesting to me as I am currently looking for the best way to write a text engine in OpenGL. I want a methodology that supports standard font files for versatility, but also is cross-platform. This eliminates all Wgl stuff. Sdl also has no text functions. What would be the best solution for me?

My engine is C# Tao so I have an entirely different set of libraries at my disposal than most others posting here.

Since you want to support standard fonts, I think you may want to try a 3rd-party library. There a few mentioned in the Survey of OpenGL Font Technology, IIRC.
Michael K.

This topic is closed to new replies.

Advertisement