Login  Register

Text rendering quality

Posted by Marian Schedenig on Sep 01, 2013; 2:56pm
URL: https://forum.jogamp.org/Text-rendering-quality-tp4029946.html

I'm struggling with getting decent text rendering in my JOGL game. I originally wrote my GL code as Android native GL2ES code before porting it to JOGL for the desktop version. The Android code uses Android's own graphics library to render text strings to a texture and then display them via GL, but with JOGL I'm trying to rely on its own TextRenderer functionality instead of reinventing the wheel. Most of the remaining code is still pretty much the same it was on Android, so I'm using standard GL calls most of the time and JOGL specific classes only in a few instance, e.g. when setting up the GLWindow.

Most of my text rendering occurs in my GUI classes, where each frame is rendered onto a framebuffer texture (created without any JOGL specific code) and then from there onto the main screen. I'm using my own primitive vertex and fragment shaders and the curve based TextRenderer seems to work well enough with those.

This is my initialisation code:

public TextRenderer getTextRenderer()
{
        if(textRenderer == null)
        {
                ShaderState ss = new ShaderState();
                RenderState rs = RenderState.createRenderState(ss, SVertex.factory());
                int renderModes = GLRegion.VBAA_RENDERING_BIT;
                textRenderer = TextRenderer.create(rs, renderModes);
                textRenderer.init(gl);
        }
       
        return textRenderer;
}

And here's how I render a text string, after setting up my shader's matrix correctly (which is why I always pass 0/0 as the coordinates):

getTextRenderer().drawString3D(gl, glFont.getFont(), text.getText(), new float[]{0, 0}, (int) glFont.getSize(), new int[]{0});

Problem is, the quality is rather lousy, as you can see in this image:



The FPS display on the upper right is drawn directly on the screen and thus takes advantage of my GLWindow's sample buffer settings (caps.setNumSamples(4)). It doesn't necessarily look great, but at least much better than the GUI text labels, which are drawn on the framebuffer textures and apparently don't using any antialiasing at all.

Which brings me to my question: Is there a way to do decent curve text rendering on my custom framebuffer textures? Alternatively, what would be my best bet for quality text rendering? The AWT TextRenderer is a bit of a PITA as it interferes with my shaders and when I disable them, I lose my matrix functionality and would have to manually calculate the target coordinates. Or should I just take the same route I did with Android and write my own AWT-to-texture rendering code?

All suggestions welcome.