Font rendering

I have managed to read the outline information about fonts using Java’s Font class, but I have a few doubts:

  • I am using evaluators to draw the font curves, and obviously it’s 3D just like any other object in the scene.

It works, but I would like to render them in 2D. Is there a way to use evaluators for 2D rendering? I tried to set the projection matrix with gluOrtho2D before exhibitting the text but it didn’t work, not sure if this is possible by the way.

  • What would be the best way of turning that curve information in 2D?

  • When the vertices are generated by the glEvalMesh, is there a way of reading those values back?

For 2D font rendering you may want to consider rendering bitmapped fonts instead. This will get you proper subpixel antialiasing among other things. The approximate path you would want to take is to render a String into a BufferedImage, convert that BufferedImage into an OpenGL texture (e.g., using the TextureIO classes), and then render the OpenGL texture using a quad.

But how do I render it to a BufferedImage?

Using normal Java2D routines. Create a BufferedImage, create a Font, maybe use a TextLayout to determine the size of the String to be rendered, etc.

Thanks.

Will the recommended text label rendering procedure change once 2D/3D mixing is available in Mustang?

My needs center around rendering an axis labeled with numeric values, but other typical uses would be to render objects and then put a descriptive label next to each, or to show two views and label one “View 1” and the other “View 2”. I currently use the GLUT bitmap fonts, but there are limited styles and sizes. People with high-res screens have to squint, but the text looks a lot better than it does with the GLUT stroke font.

Ideally, the program would choose the font size to fit the screen area available at a given resolution. The user could then choose different fonts or change the text size in the same way that is possible with Ctrl++ and Ctrl± in Firefox. I would like to be able center or right-justify the text, and get the metrics of the rendered string.

Would this type of feature be possible using the current procedure? If so, has anyone written a class to automate it?

You can already use Java2D to draw text directly on top of a GLJPanel. The Java2D/JOGL bridge in Mustang will accelerate the 3D rendering into the GLJPanel.

If you want to draw your text using OpenGL and textured quads, then nothing will change with the presence of the bridge. You’ll still need to render into a BufferedImage and upload the data into a texture. It would be very helpful if someone wrote a helper class to enable the use of Java2D fonts in similar fashion to the platform-specific WGL and GLX font routines.

I have added some sample code to render Java AWT fonts using JOGL http://www.java-gaming.org/forums/index.php?topic=14320.msg113698#msg113698

A)

thiagosc2 asked this question:

–When the vertices are generated by the glEvalMesh, is there a way of reading those values back?

I am curious about this as well. Since openGL has a built in evaluator (which the NURBS functionality is built on), I am hoping to use it to get postions/path information for complex curves.

B)

Also, I found a DynamicFont class on this forum which worked great at writing text into a BufferedImage. I updated it slightly so that you can now pass in a Font (eg, new Font(“helvetica”, Font.ITALIC, 12) ) rather than needing to load the TTF file from disk.

However, I’m not currently storing each character in a display list, which might be faster. But I haven’t had any problems with speed so far.

If anyone is interested I can post the revised code, or someone more ambitious could make a more robust helper class out of the original code (search for DynamicFont on these forums).

-spiraljetty