Unicode problems with TextRenderer. Also weird texture garbage with TextRenderer

Hi, I am having 2 separate problems with the TextRenderer class. I am using the nightly build from two nights ago, but I also tried it with rc6.

Problem 1) If I use TextRenderer to display large text, at a certain point the text starts to go crazy, and throws up random stuff. Here I am printing part of the alphabet:

http://www.mat.ucsb.edu/~a.forbes/jogl_forum/alphabet1.png

http://www.mat.ucsb.edu/~a.forbes/jogl_forum/alphabet2.png

Problem 2) If I use TextRenderer to display large text containing unicode characters-- e.g. curly quotes like \u201C or \u201D or anything with the \u-- then the program crashes, and I have to kill the process manually.

I am using rather large fonts, sizes of 300 and up. But I am trying to run my application across 4 screens (eventually-- right now just using 1 screen), so I will need even larger font sizes than this.

I’ve tried it with all sorts of different fonts, from the default Java font, to the extended Arial Unicode, to Lucian Sans Unicode, to Georgia. So it’s not a matter of choosing a better font.

It spits up grabage/crashes using Windows and Linux. I have a Nvidia card on Windows and an ATI card on Linux (Ubuntu 7.10).

Specifically I am using the commands:

textRenderer.begin3DRendering();
textRenderer.draw3D(…);
textRenderer.end3DRendering();

Any ideas?

You may try too use smaller Font and a scale factor greater than 1.0.
But I think with font size of 300 there will be too much aliasing.
In my application, I got the same behaviour. I found that the bug starts when font size reaches somthing close to 100.

Jean-Baptiste

Can you please file a bug with the JOGL Issue Tracker (you’ll need to be an Observer of the project) and attach a test case?

Thanks Ken, I will do that gladly-- How do become an observer, etc? Also, is there a particular template for describing bugs, etc, or is it fairly informal?

Jean-Baptiste, using the smaller font makes the text look super-fuzzy when scaling. I am hoping that there is a way to get large crisp looking text in my application.

Thanks, sj

Why not write it yourself? It’s fairly straight-forward. Render text with Java2D, grab the pixels from the image, and put them into a texture.

Hi, it is not that hard to do. but isn’t that what the TextRenderer helper class is for?? Also, I guess I am just making the assumption that advanced OGL/JOGL programmers would know of optimizations, etc that I might not know about. Anyhow, I’ll post the test cases before end of day tomorrow. Thanks, sj

Register and/or log in to java.net, go to http://jogl.dev.java.net/ , and click “Request project membership / role” at the top of the main part of the page. Select “Observer”, click “Submit request”.

Informal bug format. You might want to query the database and look at a few other bugs first. To do so, make sure you select “jogl” as the subcomponent during the query.

Hi, here is some test code (modified from TextCube.java in the JOGL demos). There are two cases (uncomment one or the other in the constructor). The first case shows that unicode characters crash JOGL if large fonts are used. The second case shows the weird artifacts that flip back and forth when using large fonts (and no unicode characters).

I’m going to post it to the bug database too.

Thanks, sj

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.Frame;
import java.awt.event.*;
import java.awt.geom.*;

import javax.media.opengl.*;
import javax.media.opengl.glu.*;
import com.sun.opengl.util.*;
import com.sun.opengl.util.j2d.*;

/** Test Code adapted from TextCube.java (in JOGL demos) */

public class WeirdFontTest implements GLEventListener
{
	GLU glu = new GLU();
	TextRenderer renderer;

	float textScaleFactor;
	String text;
	Font font;
	boolean useMipMaps;

	public WeirdFontTest()
	{
		//test 1 - unicode hangs program with a large font & long string
		//font = new Font("default", Font.PLAIN, 200);
		//text = "\u201Cabcdefghijklmnopqrstuvwxyz\u201D";

		//test 2 - weird artifacts appear with a large font & long string 
		font = new Font("default", Font.PLAIN, 200);
		text = "abcdefghijklmnopqrstuvwxyz1234567890";

		useMipMaps = true; //false
	}

	public static void main(String[] args)
	{
		Frame frame = new Frame("WeirdFontTest");
		frame.setLayout(new BorderLayout());

		GLCanvas canvas = new GLCanvas();
		final WeirdFontTest demo = new WeirdFontTest();

		canvas.addGLEventListener(demo);
		frame.add(canvas, BorderLayout.CENTER);

		frame.setSize(512, 512);
		final Animator animator = new Animator(canvas);
		frame.addWindowListener(new WindowAdapter()
				{
				  public void windowClosing(WindowEvent e)
				  {
				    new Thread(new Runnable()
		                    {
				      public void run()
				      {
				        animator.stop();
					System.exit(0);
			              }
			            }).start();
				  }
				});
		frame.show();
		animator.start();
	}

	public void init(GLAutoDrawable drawable)
	{
		GL gl = drawable.getGL();

		gl.glEnable(GL.GL_DEPTH_TEST);

		renderer = new TextRenderer(font, useMipMaps);

		Rectangle2D bounds = renderer.getBounds(text);
		float w = (float) bounds.getWidth();
		float h = (float) bounds.getHeight();
		textScaleFactor = 2.0f / (w * 1.1f);
		gl.setSwapInterval(0);
	}

	public void display(GLAutoDrawable drawable)
	{
		GL gl = drawable.getGL();
		gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);

		gl.glMatrixMode(GL.GL_MODELVIEW);
		gl.glLoadIdentity();
		glu.gluLookAt(0, 0, 10,
			0, 0, 0,
			0, 1, 0);

		renderer.begin3DRendering();
		Rectangle2D bounds = renderer.getBounds(text);
		float w = (float) bounds.getWidth();
		float h = (float) bounds.getHeight();
		renderer.draw3D(text,
		    w / -2.0f * textScaleFactor,
	            h / -2.0f * textScaleFactor,
		    3f,
		    textScaleFactor);
		
                renderer.end3DRendering();
	}

	public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
	{
		GL gl = drawable.getGL();
		gl.glMatrixMode(GL.GL_PROJECTION);
		gl.glLoadIdentity();
		glu.gluPerspective(15, (float) width / (float) height, 5, 15);
	}

	public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged)
	{
	}
}

This has just been fixed; please see Issue 344 for the details. This will show up in tomorrow’s nightly build as well as the forthcoming 1.1.1-rc8 (which will be officially pushed once some key customers validate the TextRenderer changes).

Hi, the fixes to TextRenderer in rc8 look great!!

I did notice one strange thing when I was testing it: If I include a unicode character as the second-to-last character in the text string, I get this slightly odd overlapping:

http://www.mat.ucsb.edu/~a.forbes/jogl_forum/greetings1.png

If however it is the last character, or at any other position, it renders fine. Here’s an example where the unicode character is third-to-last:

http://www.mat.ucsb.edu/~a.forbes/jogl_forum/greetings2.png

I don’t actually know if this is a jogl bug or just something to do with unicode characters, but I thought I’d point it out in case it is. It happens for any font and at any font size.

~sj

Thanks for pointing this out. It was an off-by-one error in part of my fix. I’ve checked in a fix for this which will be present in tomorrow’s (tonight’s) nightly build numbered 1.1.1-rc8 and dated 2/19.