From J Wiki
Jump to navigation Jump to search

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 ( Wm yes check.png or generated at runtime using gl2.

Texture Fonts


Wm yes check.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:

  • when lighting is on, the glyphs are not properly lit on the front plane
  • in the current simple example, the widths and offsets of the glyphs are the same of all glyphs

Bitmap Fonts


Wm yes check.png

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

There are a few problems:

  • the two problems as in texture fonts
  • bitmap font is binary, so no shades of gray are possible to provide antialiasing

Pixel Fonts


Wm yes check.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:

  • color is taken directly from pixels, so it needs to be set in a certain manner, not yet in the example
  • the shift of position in the display list is not done so efficiently as in glBitmap; as a result, setting individual raster positions is not as good

Stroke Fonts


Wm yes check.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