JOGL - High performance text rendering

classic Classic list List threaded Threaded
16 messages Options
km
Reply | Threaded
Open this post in threaded view
|

JOGL - High performance text rendering

km
Hello,

I'm using JOGL for a application which renders a map, on this map we can (depending on some options) draw large amounts of text items. Our application is cross-platform in nature that it should run on Windows, Linux and MacOS X.

To increase performance, we dropped AWT/Swing for Qt-Jambi, and on Windows we dropped the JOGL TextRenderer for wglUseFontBitmaps (platform specific function).

Unfortunately text rendering is still terribly slow (1-2 fps) on Linux and MacOS X if large amounts of texts are shown at the same time (+/- 1000 text labels). If only a small number of text labels are shown (+/- 10-50) there are no performance issues at all.

We are currently using JOGL 1.1.1a.

Are there alternatives for the TextRenderer which allow us to draw text with better performance on MacOS X and Linux?
Or, are there suggestions to fine-tune the use of the TextRenderer?

Thanks,
Kenny
Reply | Threaded
Open this post in threaded view
|

RE: JOGL - High performance text rendering

Rami Santina
Administrator

I recommend that you first move to jogl 2. A tool to help you do that is created by Micheal (for import and Class names…etc).

As for the text rendering we are currently working on HW accelerated text renderer which should be available soon (not too soon but soon J ).

Meanwhile, I guess you should look into LOD schemes to hide unneeded text from view point. You should not draw everything to each frame…if items are not shown or far away its best that you hide them. Or decrease qulity…etc

This by it self should give you a boost in performance.

 

Hope it helps!

Reply | Threaded
Open this post in threaded view
|

Re: JOGL - High performance text rendering

gouessej
Administrator
In reply to this post by km
Hi!

To fix your issue, switch to JOGL 2, force the use of vertex arrays with TextRenderer and I'm going to provide a patch that reduces the memory use and improves the speed. My fix is already available for JOGL 1.1.1a, feel free to use it. TextRenderer is already hardware accelerated, I know the source code. Only the first implementations of TextRenderer (very old implementations, some years ago) were using Java2D and were not hardware accelerated

Using wglUseFontBitmaps in windows is not faster than using the few methods concerning text rendering in the GLUT that are still in JOGL as far as I know (but it supports only a few fonts).

I'm not sure Qt-Jambi is noticeably faster than plain AWT especially when it is used correctly.
Julien Gouesse | Personal blog | Website
km
Reply | Threaded
Open this post in threaded view
|

Re: JOGL - High performance text rendering

km
Thanks,

I'm certainly going to try JOGL2 and see if it improves on the situation.

Also, the switch we made to Qt-Jambi, when recalling correctly was idd not for performance reasons, rather for the fact that we had issues with multi-monitor support and multiple opengl-contexts in separate windows, on both monitors. We didn't manage to get that working with AWT/Swing and traced that back to somewhere deep in the JVM code that did not allow this acceleration for a 2nd monitor somehow. It could be that there were workaround for it, but in the end we investigated alternatives (SWT en Qt-Jambi) and didn't saw these problems there, so in the end we switched to another platform for the GUI itself.

Kind regards,
Kenny
km
Reply | Threaded
Open this post in threaded view
|

Re: JOGL - High performance text rendering

km
One point though: where to find the JOGL2 download? I find many different links on the JogAmp site providing downloads for JOGL2, which is the correct one I should use?
Reply | Threaded
Open this post in threaded view
|

Re: JOGL - High performance text rendering

gouessej
Administrator
In reply to this post by km
JOGL 2 improves the situation in the way of supporting multiple displays too with NEWT. Personally, I might plan to use it with SWT... Use Sven's repository on github.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: JOGL - High performance text rendering

Rbajter
In reply to this post by km
Hi there, I just stumbled across your post - a bit late perhaps.
Anyway, I'm trying to do the exact same thing as you are/were: Display many thousands of obects with text labels over a map (the google maps kind). My goal was to render 10000 textured quads plus labels with a framerate of about 20  on my hardware. I got 5000 with a framerate of about 15. Close enough. The biggest problem was how to render strings efficiently with TextRenderer.

This is what my text rendering loop looks like (simplified):

String text = "Hello?";
textRenderer.setColor(Color.WHITE);
textRenderer.begin3DRendering();
for (Point2D point : points) {
    gl.glPushMatrix();
    gl.glTranslated(point.getX(),point.getY(), 0.0);
    textRenderer.draw(text, 0, 0);
    textRenderer.flush();
    gl.glPopMatrix();
}
textRenderer.end3DRendering();

Note that the begin and end are outside the loop and there is a flush call after the draw call instead of having the begin and end surround the draw call inside the loop. This simple restructuring took me from 500 to 5000 objects on screen with similar framerates. Of course, if I drop text rendering altogether I can render 50000 objects instead, but that's not really helpful.

Even though it might be too late I thought I should share this insight.

Cheers!
Reply | Threaded
Open this post in threaded view
|

Re: JOGL - High performance text rendering

Wade Walker
Administrator
Thanks for this tip -- I'm sure it will be helpful to people searching on this topic later, even if it's too late for the original poster
Reply | Threaded
Open this post in threaded view
|

Re: JOGL - High performance text rendering

GiGurra
This post was updated on .
Yes, and I happen to have just searched for it. I just recently moved my application from jogl 1 to jogl 2.
My application basically runs a set of awt windows, each with some control buttons and a jogl glcanvas in the center,
so I'm using com.jogamp.opengl.util.awt.TextRenderer to render text (vertexarrays enabled like suggested).
Everything is running smooth so far except the performance of the textrenderer, which is, by far, the biggest slowdown of my application (I use only the 3d rendering calls of the textrenderer btw).

In order to speed it up Ive tried to make as few "begin3drendering" calls as possible, but with the nature of my application,
that will not be possible to the extent that I reach sufficient performance.

To remedy this problem in jogl1 I rewrote parts of the textrenderer, which pretty much solved my problem.
However, when I try to do the same thing for jogl 2.. I've run into a problem. I can't find the source :). I've downlaoded the
latest master build which has some source zips. Should I also check the stable builds? Has the textrenderer been removed from the master builds or am I (which is most likely) just looking in the wrong place :).

UPDATE/EDIT: Nevm I was, as expected, looking in the wrong place :S
Reply | Threaded
Open this post in threaded view
|

Re: JOGL - High performance text rendering

Wade Walker
Administrator
Sounds like you already found TextRenderer in com.jogamp.opengl.util.awt

If you've got some modifications to improve it, please look at the directions at http://jogamp.org/wiki/index.php/How_to_Contribute -- they tell how you can submit your changes back to JOGL for everyone to enjoy
Reply | Threaded
Open this post in threaded view
|

Re: JOGL - High performance text rendering

Sven Gothel
Administrator
On Thursday, July 14, 2011 03:09:04 AM Wade Walker [via jogamp] wrote:
>
> Sounds like you already found TextRenderer in com.jogamp.opengl.util.awt
>
> If you've got some modifications to improve it, please look at the
> directions at http://jogamp.org/wiki/index.php/How_to_Contribute -- they
> tell how you can submit your changes back to JOGL for everyone to enjoy

I have to emphasize Rami's hint to our new GLSL based text rendering ..

http://jogamp.org/git/?p=jogl.git;a=blob;f=src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextRendererListenerBase01.java;h=0fced47158760ff3777a4f1dc16fcf42928786b8;hb=HEAD

http://www.youtube.com/watch?v=Rqsu46ifMaw

.. and our blogs.

Yes, we will change the API, however,
the graph package's implementation will be the next big thing
in regards to NURBS and TEXT rendering.

Just though I shall mention this, before anybody wastes more time
with the AWT CPU based text renderer.

~Sven
Reply | Threaded
Open this post in threaded view
|

Re: JOGL - High performance text rendering

texone
I have already created a couple of classes for text rendering using jogl, it is part of my creativecomputing framework. I have implemented different font types the fasted is texturemap font where I put all chars into a texture and than break down the text to textured quads. There are also utilities to put a lot of text into a vbo.

http://code.google.com/p/creativecomputing/source/browse/#svn%2Ftrunk%2Fcc2.0%2Fsrc%2Fcc%2Fcreativecomputing%2Fgraphics%2Ffont

http://code.google.com/p/creativecomputing/source/browse/#svn%2Ftrunk%2Fcc2.0%2Fsrc%2Fcc%2Fcreativecomputing%2Fgraphics%2Ffont%2Ftext

Maybe this might also serve as starting point for a jogl implementation.

Cheers Christian
Reply | Threaded
Open this post in threaded view
|

Re: JOGL - High performance text rendering

Rbajter
In reply to this post by Sven Gothel
Hi,
I just got a little time to look at the new text rendering api in jogl. Btw, the demos look great. :) I'm really exited to try and get this working in my app. I've scoured the demo code and think I have all the bits required to make it work. Before I start fiddling with a test app I just wanted to check that I haven't missed anything and also ask a few questions.

Below is what I think are the relevant classes and calls:

//Initialization
Font font = FontFactory.get(FontFactory.JAVA ).getDefault();
ShaderState shaderState = new ShaderState();
RenderState renderState = RenderState.createRenderState( shaderState, SVertex.factory() );
int renderModes = 0;
TextRenderer textRenderer = TextRenderer.create( renderState,  renderModes);  //Render modes?

//Rendering
textRenderer.reshapeOrtho( null, width, height, near, far );  //GL context null
textRenderer.setColorStatic( gl, 0.0f, 0.0f, 0.0f );
textRenderer.setAlpha( gl, 1.0f );
textRenderer.resetModelview( null );                    //GL context null
textRenderer.translate( gl, 10.0f, 10.0f, 0.0f );
float[] pos = new float[] {0,0,0};
int fontSize = 10;
int textureSize = 400; 
textRenderer.drawString3D( gl, font, "text", pos, fontSize, textureSize );

1. What are render modes? And why should I care?
2. Apparently I can set a projection directly on the text renderer. Why? Can't I just use whatever projection I already have set up?
3. Some calls to the renderer are done with a null GL context. What does that mean?
4. In the drawString3D call there is a texture size argument for multipass rendering. What size should I set and when is it used?

Now what would be really cool is a blow-by-blow minimal usage example, maybe posted in the blog, but I guess that is just wishful thinking. :)
Anyway, thanks for all the great work!

//Johan
Reply | Threaded
Open this post in threaded view
|

Re: JOGL - High performance text rendering

Sven Gothel
Administrator
On Sunday, October 09, 2011 04:04:07 PM Rbajter [via jogamp] wrote:

>
> Hi,
> I just got a little time to look at the new text rendering api in jogl. Btw,
> the demos look great. :) I'm really exited to try and get this working in my
> app. I've scoured the demo code and think I have all the bits required to
> make it work. Before I start fiddling with a test app I just wanted to check
> that I haven't missed anything and also ask a few questions.
>
> Below is what I think are the relevant classes and calls:
>
>
>
> 1. What are render modes? And why should I care?
For now, just don't care - pass 0.
You could use 2-pass mode w/ texSize etc (see demo's w/ '02') .. however,
it's not thoroughly done yet, ie finding the texSize for the FBO.
This also doesn't work well on Tegra2 (mobile).

> 2. Apparently I can set a projection directly on the text renderer. Why?
> Can't I just use whatever projection I already have set up?
We need it to advance to the next position .. characters ..
But you are free to [re-]use the matrix, I guess it's accessible.

> 3. Some calls to the renderer are done with a null GL context. What does
> that mean?
Some matrix op's are done in a batch, so only the last one passes the GL ctx,
which then updates the GLSL uniform data.

> 4. In the drawString3D call there is a texture size argument for multipass
> rendering. What size should I set and when is it used?
See above (mode) .. let's ignore this for now :)

>
> Now what would be really cool is a blow-by-blow minimal usage example, maybe
> posted in the blog, but I guess that is just wishful thinking. :)

No, you are right.
We started with such (Rami did) .. then I blew it up to the current complex one.

We should bring a 'one file' demo back, right.
Maybe you like to contribute yours ?
[Since it's always better to write these docs as an 'outsider']
I would love to check in your demo/unit test.

> Anyway, thanks for all the great work!

Thank you for testing.

~Sven

>
> //Johan
>
Reply | Threaded
Open this post in threaded view
|

Re: JOGL - High performance text rendering

Rbajter
Hi Sven,

I managed to get a minimal example running but I'm having some issues with smaller font sizes, like 20 and smaller (I'm trying to render 12 pts). The rendering breaks down and becomes quite ugly. Any tips?

//Johan
Reply | Threaded
Open this post in threaded view
|

Re: JOGL - High performance text rendering

Sven Gothel
Administrator
On Monday, October 10, 2011 06:47:43 PM Rbajter [via jogamp] wrote:
>
> Hi Sven,
>
> I managed to get a minimal example running but I'm having some issues with
> smaller font sizes, like 20 and smaller (I'm trying to render 12 pts). The
> rendering breaks down and becomes quite ugly. Any tips?
>

enable samples in caps (4), link your code here maybe ?

~Sven

> //Johan