Posted by
Sven Gothel on
Sep 03, 2013; 5:03pm
URL: https://forum.jogamp.org/Text-rendering-quality-tp4029946p4029973.html
On 09/01/2013 04:56 PM, Marian Schedenig [via jogamp] wrote:
> 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 = 0;//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.
Region.VBAA_RENDERING_BIT -> uses the FBO-AA method, which, tbh,
I would not recommend. VBO-AA results may vary on the AA settings.
Plus using MSAA on the final image may make things worse.
The above is especially true, if you render into an FBO already!
Use mode '0', i.e. direct curve rendering.
+++
You may also want to make your FBO use MSAA !
>
> Which brings me to my question: Is there a way to do decent curve text
> rendering on my custom framebuffer textures?
Of course.
Simple setup your FBO (use MSAA) and use the described direct rendering.
You may use our FBObject or GLOffscreenDrawable .. as you wish.
Further more: Your texture should be rendered w/ same aspect-ratio
and resolution as you have rendered the text.
Otherwise we are loosing the resolution independence :)
and 'gain' distortions.
BTW .. the whole idea of using Curved GPU based rendering
is to do it in the rendering loop -> resolution independence.
So caching the result in an FBO is sort of .. odd, but maybe
has it's merits due to your use-case.
> 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.
Please post a 'small' unit test / demo code under our BSD-3 license ..
Maybe add a bug report and we can take it from there ..
~Sven
>