Jump to content
  • Advertisement
Sign in to follow this  
Simplicity

Is Font System Depedent

This topic is 4715 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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-

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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'.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!