TextRenderer (missing transformation when using 1.1.1RC6)

Hi all,

switching from 1.1.0 to 1.1.1RC6 I noticed that the position of text rendered by TextRenderer is not affected by any transformations (f.e. glTranslated). All text is rendered at exactly the same position within my 3D scene.
(I just checked again and the code works correctly using Jogl 1.1.0)

Any ideas, anything I have overseen or anything I could help with?

Thx, Martin


protected void renderText(GL gl, GLU glu, TextRenderer textRenderer, OrbitRotation orbitRotation, 
            String text, Color4f textColor, Vector3d textPosition, double zOffset, double scaleFactor, boolean centered) {
        textRenderer.begin3DRendering();
        textRenderer.setColor( textColor.x, textColor.y, textColor.z, textColor.w );
        
        gl.glEnable(GL.GL_CULL_FACE);
        // Note that the defaults for glCullFace and glFrontFace are
        // GL_BACK and GL_CCW, which match the TextRenderer's definition
        // of front-facing text.
        
        gl.glPushMatrix();
        gl.glTranslated( textPosition.x, textPosition.y, textPosition.z );
        gl.glMultMatrixd( orbitRotation.getRotationalInverseOfCameraMatrix(), 0 );
        
        Rectangle2D bounds = textRenderer.getBounds(text);
        float w = (float) bounds.getWidth();
        float h = (float) bounds.getHeight();
        
        if (centered) {
            textRenderer.draw3D(text,
                    (w / -2.0f * (float)scaleFactor ),
                    (h / -2.0f * (float)scaleFactor ),
                    (float)zOffset,
                    (float)scaleFactor);
        } else {
            textRenderer.draw3D(text,
                    0,
                    0,
                    (float)zOffset,
                    (float)scaleFactor);
        }
        
        gl.glPopMatrix();

        textRenderer.end3DRendering();
    }

The TextRenderer is now doing more caching internally. There is a new flush() method which you now need to call if you are changing OpenGL state which you expect to affect your text. See demos.j2d.FlyingText in the jogl-demos workspace for a concrete example of where to call this method (basically, after you render your text and before you change the OpenGL state again).

you have to do the transformations outside of the begin3DRendering() call

First of all, thx to both of you for your help.

Either calling flush explicitely or changing the order of execution did the job :slight_smile:

Just a technical remark / question:

internal_draw3D switches to use either drawGlyphs(glyphs,x,y,z,scaleFactor) or draw3D_ROBUST.

Is my assumption right, that for a given text f.e. “ab cd” (note the space)

draw3D_Robust will use two different rectangle parts of the backing texture. One rectangle area for “ab” and one for “cd”

drawGlyphs on the other hand will use textures for each different character, thus using “a”, “b”, “c” and “d” for each character and assemble them later during output?

Best regards, Martin

Right now the “robust” version isn’t doing any tokenization, so it will draw one quad. You’re right that the glyph version will draw five rectangles, one per glyph.