Original Post
Okay, so rendering text is pretty shitty with the normal OpenGL calls. I've written a system to use Java2D, but it really bogs when user events occur (moving the window, dragging the mouse, etc). Other than using display lists, is there anything anyone else is using? here is the basic breakdown: The really slow method is the flushText method, and TextureIO.newTexture() call is the only heavy method in the bunch (try stepping through it once. There is waaay too much indirection). I have a sample app that calls it and makes 20fps on my p4 2.4ghz machine with a Radeon 9800 GPU. If I cut just the call to flushText (even leaving in the print calls, so still having the Java2D overhead), the avg FPS jumps to 2000+. [Edited by - capn_midnight on May 7, 2006 4:25:51 PM]
/*
* Created on May 7, 2006
*
*/
package testjogl;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import javax.media.opengl.GL;
import com.sun.opengl.util.texture.Texture;
import com.sun.opengl.util.texture.TextureCoords;
import com.sun.opengl.util.texture.TextureIO;
public class TextLayer
{
BufferedImage textLayer;
Graphics2D java2d;
float left, right, top, bottom;
public TextLayer (int width, int height, float left, float right,
float top, float bottom)
{
textLayer = new BufferedImage (width, height,
BufferedImage.TYPE_INT_ARGB_PRE);
java2d = (Graphics2D) textLayer.getGraphics ();
this.left = left;
this.right = right;
this.top = top;
this.bottom = bottom;
}
public void print (String output, float x, float y, Font font, Color color)
{
java2d.setColor (color);
java2d.setFont (font);
java2d.drawString (output, x, y);
}
public void flushText (GL gl)
{
Texture temp = TextureIO.newTexture (textLayer, false);
java2d.setColor (new Color (0, 0, 0, 0));
java2d.clearRect (0, 0, textLayer.getWidth (), textLayer.getHeight ());
temp.enable ();
temp.bind ();
gl.glBegin (GL.GL_QUADS);
TextureCoords tc = temp.getImageTexCoords ();
gl.glTexCoord2f (tc.left (), tc.bottom ());
gl.glVertex2f (left, bottom);
gl.glTexCoord2f (tc.right (), tc.bottom ());
gl.glVertex2f (right, bottom);
gl.glTexCoord2f (tc.right (), tc.top ());
gl.glVertex2f (right, top);
gl.glTexCoord2f (tc.left (), tc.top ());
gl.glVertex2f (left, top);
gl.glEnd ();
temp.disable ();
}
}