Java based OpenGL in J lacks font suport. Here we will explore portable methods of displaying text in OpenGL.

Font will be taken from pre-generated raster image located in file ( (./) download: arial.bmp ) or generated at runtime using gl2.

Texture Fonts

tex.png

This example defines a bitmap image with font snapshot in 16x16 pixel cells.

It uses texture and vector quad geometry to draw tiles, which are blended to the underlying world. The display lists are positioned into the 3D world, not in the raster viewport.

To put the text in fixed screen positions, the transformation is applied to place it just beyond the front plane of the view frustum.

There are a few problems:




Bitmap Fonts

bitmap.png

To emulate the behavior of wglUseFontBitmaps, the glyphs are drawn with glBitmap display lists into glRasterPos coordinates.

There are a few problems:




Pixel Fonts

pixmap.png

To emulate the behavior of glBitmap, the glyphs are drawn with glDrawPixels display lists also into glRasterPos coordinates.

As opposed to glBitmap, pixels use full color, not just binary bits.

There are a few problems:


Stroke Fonts

stroke.png

Stroke fonts are represented of series of polyline stretches. They are stored in display lists with the final command shifting by width along x axis.

The stroke display lists are played similar to texture fonts.




See Also

OpenGL/Fonts (last edited 2008-12-08 10:45:52 by )