Login  Register

Re: TextRenderer - my text won't show

Posted by chakie on Aug 09, 2013; 10:48am
URL: https://forum.jogamp.org/TextRenderer-my-text-won-t-show-tp4029291p4029784.html

I have yet to see any rendered text though. Trying to reverse engineer what the code actually does based on:

https://github.com/sgothel/jogl/blob/master/src/jogl/classes/com/jogamp/graph/curve/opengl/Renderer.java

What I do is basically:

        // get a font
        font = FontFactory.get( FontFactory.JAVA ).getDefault();

        // set up a renderer
        RenderState renderState = RenderState.createRenderState( new ShaderState(), SVertex.factory() );
        renderer = TextRenderer.create( renderState, 0 );

        renderer.init( gl );
       
        renderer.setAlpha( gl, color.alpha );
        renderer.setColorStatic( gl, color.red, color.green, color.blue );

        // disable blending for now, enable when actually rendering text
        gl.glDisable(GL3.GL_BLEND);

And when rendering:

        // re-enable blending
        gl.glEnable( GL3.GL_BLEND );

        // set up any transformation
        renderer.reshapeOrtho( gl, width, height, 1, 10 );
        renderer.resetModelview( gl );

        // TODO: why is this needed, the position is set below
        renderer.translate( gl, 0, 0, 2 );

        // position of the rendered text
        final float[] textPosition = new float[]{ 100, 100, 5 };

        // size of the created texture map. TODO: is this sane?
        final int[] textureSize = new int[]{ 400 };

        // set color
        renderer.setColorStatic( gl, color.red, color.green, color.blue );
        renderer.setAlpha( gl, color.alpha );

        // draw the text
        renderer.drawString3D( gl, font, "Hello world", textPosition, fontSize, textureSize );

        gl.glDisable(GL3.GL_BLEND);

To me it seems like that ought to render my string as for a HUD. The font is valid, the font size too, the color is white with no alpha. Everything seems sane. I also see no warnings or errors in the console. Will dig more.