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)
{
}
}