Is Font System Depedent

Started by
7 comments, last by Deyja 18 years, 9 months ago
I'm wondering if there is a way to do system independent font? How would you render font in OGL or DX without using D3DXFont or anything of that sort?
Advertisement
I don't do dev in windows, so I can't help you with specifics there - but do a web search for bitmap font tutorials. It's one option for platform independent fonts, though not a very optimal solution.

Another option is a library called Freetype, it's fairly difficult to set up and use, but there is another library called SDL_ttf that wraps around it and makes it really easy to use true type fonts. However, you might need to be using SDL for it to work (not sure though). SDL is fairly easy to use though.
We can use bitmap fonts and map it onto a polygon and then render it on the screen. This method will allow us to scale the font irrespective of which platform we develop on. The polygon would be rendered in parallel projection and all the perspective correction should be turned off.
FreeType difficult to set up and use ?!
I'm using FreeType, and all I can say is that I was seriously surprised at how trivial it is to render ttf fonts with excellent antialiasing quality.

You just ask FreeType for a character and it hands out an array of 8 bit values containing the gray levels of the character's pixels. Those can then be directly used for the alpha channel of a texture, resulting in ultra-fast anti-aliased font rendering:
FT_Error Error = ::FT_Load_Char(FTFace, Glyph, FT_LOAD_RENDER);if(Error)  throw std::runtime_error("Failed to render truetype character");// FTFace->glyph->advance.x       Number of pixels times 64 to advance on X axis// FTFace->glyph->advance.x       Number of pixels times 64 to advance on Y axis// FTFace->glyph->bitmap_left     X axis offset for rendering (hotspot)// FTFace->glyph->bitmap_top      Y axis offset for rendering (hotspot)// FTFace->glyph->bitmap.width    Width of the character bitmap in pixels// FTFace->glyph->bitmap.height   Height of the character bitmap in pixels// FTFace->glyph->bitmap.buffer   Array containing the character's gray values


To achieve graphics API independency, my game engine consists of a series of interfaces for accessing textures and vertex buffers. My font rendering code doesn't actually contain any API specific calls, but simply uses these interfaces. The font's characters are stored on large, shared cache textures (arranged using a simple bin packing algorithms) and the rendering is performed using pre-transformed vertices stuffed in a dynamic vertex buffer (an orthogonal projection matrix would do, too, I suppose).

-Markus-
Professional C++ and .NET developer trying to break into indie game development.
Follow my progress: http://blog.nuclex-games.com/ or Twitter - Topics: Ogre3D, Blender, game architecture tips & code snippets.
Quote:Original post by Cygon
FreeType difficult to set up and use ?!
I'm using FreeType, and all I can say is that I was seriously surprised at how trivial it is to render ttf fonts with excellent antialiasing quality.


I have heard people complain about FreeType before.

What I should have said was: take a look at FreeType, if you can't set it up or make sense of it, SDL_ttf is available which makes it easier to use.
Hi

I'm using FreeType 2 to generate a font texture from any .ttf file. If you want i can give you ma cFont() class, just PM me and I'll post it here.
- Iliak -
[ ArcEngine: An open source .Net gaming framework ]
[ Dungeon Eye: An open source remake of Eye of the Beholder II ]
Any way to generate a texture from .ttf on your own?
not easily, no, there is alot work which goes into decoding the format and producing the glyths, thus why people take advantage of other libs such as Freetype 2 (which I also use to produce anti-alised and properly aligned fonts, an example of which is here).
Theres a simple app that generates bitmaps from ttfs available at www.angelcode.com IIRC, it uses winGDI instead of freetype, so your system font smoothing settings will effect the output. It uses a simple algorithm to pack characters into as few textures as possible, and writes a definition file with all the information needed to render. The result is almost exactly what the truetype library supplied, except 'pre generated'.

This topic is closed to new replies.

Advertisement