Ladies and Gentlemen, I am pleased to announce the introduction of a Java 2D based TextRenderer class into the JOGL source tree, in the new package com.sun.opengl.util.j2d. This class provides high performance bitmapped text rendering, with complete Unicode support, into OpenGL drawables with an extremely small and simple API. Advanced string-by-string caching algorithms behind the scenes result in a minimum number of OpenGL pipeline state changes; for a given TextRenderer, all strings’ cached rendering results are placed on a single OpenGL texture. A rectangle packing algorithm manages the placement of the strings on the backing store completely automatically; all details of the caching are hidden from the end user and are not exposed in the public API.
The renderer is extremely easy to use, and looks almost exactly like Java 2D’s Graphics.drawString() API. Here’s a Hello, World code snippet:
TextRenderer renderer = new TextRenderer(new Font("SansSerif", Font.BOLD, 36));
renderer.beginRendering(drawable.getWidth(), drawable.getHeight());
renderer.draw("Hello, World!", 30, 30);
renderer.endRendering();
There is a simple test of the new code in the jogl-demos workspace in demos.j2d.TestTextRenderer. More demos are coming.
Please take a look and give the new renderer a try and post with any feedback, comments or suggestions. The APIs in this area, including the related TextureRenderer and Overlay classes, are still very much open for consideration, so if you have suggestions about changes or improvements please post them. Also please let us know if you run into any problems, in particular any performance problems, with the new code; it’s been debugged to a certain degree but it’s certainly possible some issues remain, and we’re continuing to look into some situations where performance is not as good as expected.