Font engine

I was wondering what would be a good way to make a Font engine with the LWJGL to write text. The one I wrote currently works like this:

1.) Create a new StaticText class object passing in the X Y positions and the string that will be displayed.

2.) In the StaticText constructor, create a blank texture, bind a FrameBufferObject for rendering, and render all the letters into that new texture

3.) Since the StaticText class is extended to Component which holds the x,y,textureId variables, the renderer can loop through the Component array and draw everything.

Basically, every text object is rendered in the beginning within its own textureID so it doesnt have to render each letter again after every frame. Is this a slow way of doing a font engine? Any feedback?

Thats a pic of my font engine. The red outline is the size of the texture. When you pass in different lines “/n” it calculates how big the width and height of the texture has to be to fit in all lines.

Seems perfectly fine. Text changes pretty slowly (someone has to read it xD), so prerendering it might be the best solution depending on how it will be used. You might end up with LOTS of textures though. It might be better to simpy store a Display List instead of a texture.

My approach was to use a rectangle packer to draw all of the characters I might need into a BufferedImage using Java2D, and their anti-aliased font support. I’d push the BufferedImage’s byte data into a single OpenGL texture. Then I’d create geometries for each text string I’d need with a quad per character and the appropriate texture coordinates to look up in the image.

All strings of the same font could use the same texture atlas.

Basically if you ensure that all of your glyphs are in the same texture, and you draw your texture regions efficiently (i.e. using vertex arrays or VBOs) then you should be fine. That way you don’t depend on frame buffers, or Java2D/AWT, or what have you.

You might want to look into TWL’s BitmapFont tool, which is really useful for packing glyphs into a texture (with kerning information and all).
http://twl.l33tlabs.org/themer/fonttool.jnlp

why rasterizing truetype fonts and not simply draw vectorial bezier curve ? (it’s a naive question, it may be a good raison)

Drawing the bezier curve will only give you the outline to the font, to fill it with a solid color you’d have to probably use some sort of triangulator. Besides that method will use a lot more polygons, drawing raster fonts is much faster once they have been generated.

The Jogl guys create an very interessting font rendering system, which uses shaders for rendering of the splines.
I haven’t tryed it yet but are planning to use it when i need fonts in the future
http://ramisantina.com/blog/?p=73

Is it bad to have too many textures? Does it clog RAM? But either way, im going to gradually delete the textures afterwards