Good looking 3d text

Started by gsanderson, January 18, 2009, 22:28:50

Previous topic - Next topic

gsanderson

I have been playing with lwjgl (nice job guys!) and needed text rendering, so I started playing with texture based text rendering - and figured I'd share my findings for getting the best looking scalable text I could with a single glyph texture

1) When generating the glyphs texture, render in white using anti-aliasing (e.g. for java2d: RenderingHints.TEXT_ANTIALIAS_ON) on a black background (not fully transparent black since doing so may cause you to lose anti-aliasing altogether)
2) Make sure there is a single texel border around each glyph in the texture (one texel is fine between adjacent glyphs) - otherwise you'll have filtering problems
3) Use power of two size textures - I'm not sure this makes a huge difference, but seems like a good idea
4) Render the glyphs at a reasonable size say 32pt
5) Use GL_LINEAR_MIPMAP_LINEAR & GL_LINEAR for min/max texture filters
6) Use automatic mip-map generation on your texture
7) Use GL_MODULATE and the current color to color the text (since the texture is white)

If you want your text without a filled black background, then after generating your glyphs, convert the texture from pixels looking like

a=555, r=x, g=x, b=x

to

a=x, r=x, g=x, b=x (i.e. pre-multiplied)

and blend using glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)

this looks MUCH better than using a=x, r=255, g=255, b=255 and glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

8 ) Drawing over a semi-transparent filled polygons looks nice, but don't forget to use polygon offset or some other means to make sure you actually overdraw the background!

Hope this helps somebody... it took a bit of playing to figure out, and seems to produce better results than whatever I found out on the web.

Evil-Devil

Can you provide any sample/screenshots?

NateS

You might check out Hiero, which can save an image packed with glyphs and a "BMFont" format text file describing offsets, etc.
http://slick.cokeandcode.com/demos/hiero.jnlp

I've been rewriting Hiero to support unicode and on-the-fly glyph rendering. A somewhat dated version of my rewrite can be seen here:
http://n4te.com/hiero/hiero.jnlp

See here for more info:
http://slick.javaunlimited.net/viewtopic.php?t=1469

gsanderson

sorry that it isn't very interesting looking, I'm just playing around, but you get the idea. (p.s. there should be an image attached - if not http://lwjgl.org/forum/index.php?action=dlattach;topic=2803.0;attach=146)