opengl jogl problem with TextRenderer

Hi List
I hope you can help me out.

I am using JOGL, and cannot show text using the TextRenderer for some reason. The program should be simple enough, so there must be a basic rule that I have not understood yet.

The program show a square and attemps to show the text “Hello World”. Only the square is visible.


— program text below —
package test;

import com.sun.opengl.util.awt.TextRenderer;
import java.awt.Font;

public class TestHW implements GLEventListener {

public void init(GLAutoDrawable drawable)
	GL2 gl = drawable.getGL().getGL2();
	gl.glClearColor(1.0f, 1.0f, 1.0f, 0.0f);

public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
	GL2 gl = drawable.getGL().getGL2();
	GLU glu = new GLU();

	if (height <= 0)  // avoid a divide by zero error!
		height = 1;

	final float h = (float) width / (float) height;
	gl.glViewport(0, 0, width, height);
	glu.gluPerspective(45.0f, h, 1.0, 20.0);

public void display(GLAutoDrawable drawable)
	GL2 gl = drawable.getGL().getGL2();

	// Clear the drawing area
	// Reset the current matrix to the "identity"
	gl.glTranslatef(0.0f, 0.0f, -10f);

	 * show a square, just to prove that I can actually show something!
    gl.glColor3f(0.0f, 1.0f, 0.0f);
    gl.glVertex3f(-4.0f, 0.0f, 0.0f);
    gl.glVertex3f(0.0f, 0.0f, 0.0f);
    gl.glVertex3f(0.0f, 2.0f, 0.0f);
    gl.glVertex3f(-4.0f, 2.0f, 0.0f);
     * now draw some text (it doesn't show on screen :-(  )
    String text = "Hello World";
    TextRenderer renderer = new TextRenderer(new Font("Serif", Font.PLAIN, 72), true, true);
    renderer.beginRendering(drawable.getWidth(), drawable.getHeight());

    gl.glTranslatef(2.0f, 2.0f, 0.0f);
    renderer.setColor(0.0f, 1.0f, 1.0f, 1);
    renderer.draw(text, 0, 0);

     * No explicit cleanup necessary.
    public void dispose(GLAutoDrawable drawable)

I am using JOGL, and cannot show text using the TextRenderer for some reason.

OpenGL drawable surfaces are owned by OpenGL. Java rendering functions will have no effect on them. So if you want to draw text in an OpenGL window, you will have to draw text via OpenGL rendering commands. Which is not going to be a trivial process.

Thanks for the response.

The non-trivial task is already performed by Sun, who wrote the TextRenderer java class to encapsulate the tasks involved in drawing text in opengl.
Accordingly, it should only be a simple matter of calling “textRenderer.draw(…)” or “textRenderer.draw3D(…)” to output text on the drawable area.

There must be some other error I don’t see.

It seems to be an issue with the libraries I use.It could also be caused by a software-only implementation, I guess. It doesn’t seem to be a general opengl issue, so it is not relevant for this forum.
happy programming everybody.

(can I mark this thread as closed?)