Is this the correct way to draw rotated text with TextRenderer?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Is this the correct way to draw rotated text with TextRenderer?

farrellf
I'm writing a 2D program and I'm using some TextRenderer objects to overlay text in my GLCanvas. I have a weird intermittent problem: when I try to draw rotated text (code below) it usually works perfectly, but sometimes it instead draws the text at the bottom-left of the GLCanvas with no rotation. Sometimes it will flicker between drawing correctly, and drawing at the bottom-left-without-rotation quirk. It's intermittent, but somewhat repeatable. It happens with both an Nvidia card and on another PC with integrated Intel graphics.

Code snippet:
...
import com.jogamp.opengl.util.awt.TextRenderer;
...
myTextRenderer.beginRendering(width, height);
gl.glMatrixMode(GL2.GL_MODELVIEW);
gl.glPushMatrix();
gl.glTranslatef(xOffset, yOffset, 0.0f);
gl.glRotatef(90.0f, 0.0f, 0.0f, 1.0f);
myTextRenderer.setColor(myColor);
myTextRenderer.draw(myText, 0, 0);
myTextRenderer.endRendering();
gl.glPopMatrix();
...

When I render not-rotated text, it always works perfect. Only when I try to rotate does this bug appear.

Thanks,
-Farrell
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Is this the correct way to draw rotated text with TextRenderer?

farrellf
Never mind, I just noticed the flush() method, that fixed it.

For anyone that runs across this thread in the future, you need to:

...
myTextRenderer.beginRendering(width, height);
gl.glMatrixMode(GL2.GL_MODELVIEW);
gl.glPushMatrix();
gl.glTranslatef(xOffset, yOffset, 0.0f);
gl.glRotatef(90.0f, 0.0f, 0.0f, 1.0f);
myTextRenderer.setColor(myColor);
myTextRenderer.draw(myText, 0, 0);
myTextRenderer.endRendering();
myTextRenderer.flush(); // <----- add this here
gl.glPopMatrix();
...

-Farrell
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Is this the correct way to draw rotated text with TextRenderer?

gouessej
Administrator
Hi

Thank you for sharing your findings but why not posting a full example so that we have a chance to understand why flush() is necessary?
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Is this the correct way to draw rotated text with TextRenderer?

farrellf
The code snippet covers pretty much all of the relevant stuff. Calling flush() is necessary in this case (where I modified the modelview matrix) because, well, the Javadoc says so :)

http://download.java.net/media/jogl/jogl-2.x-docs/com/sun/opengl/util/awt/TextRenderer.html#flush()

-Farrell
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Is this the correct way to draw rotated text with TextRenderer?

gouessej
Administrator
Sorry but the right documentation is here:
http://jogamp.org/deployment/jogamp-next/javadoc/jogl/javadoc/com/jogamp/opengl/util/awt/TextRenderer.html#flush()

Your link points to an obsolete documentation managed by Oracle whereas it's none of its business since about 6 years.
Julien Gouesse | Personal blog | Website
Loading...