import java.awt.Frame; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import javax.media.opengl.GL; import javax.media.opengl.GLAutoDrawable; import javax.media.opengl.GLCanvas; import javax.media.opengl.GLEventListener; import javax.media.opengl.glu.GLU; import com.sun.opengl.util.j2d.TextRenderer; public class TextTest extends Frame implements GLEventListener { private static final long serialVersionUID = 1L; int width, height; public static void main(String[] args) { new TextTest(); } GLCanvas canvas; TextRenderer tr ; String whitespacestring = "emzic";//"h e l l o w o r l d . t h i s i s a s t r i n g w i t h l o t s o f s p a c e s"; public TextTest() { super("TextTest"); this.setSize(800, 200); canvas = new GLCanvas(); canvas.addGLEventListener(this); add(canvas); setVisible(true); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); } public void display(GLAutoDrawable drawable) { GL gl = drawable.getGL(); gl.glClearColor(1,1,1,1); gl.glClear(GL.GL_COLOR_BUFFER_BIT|GL.GL_DEPTH_BUFFER_BIT); gl.glMatrixMode(GL.GL_PROJECTION); gl.glLoadIdentity(); new GLU().gluPerspective(45f, (float)width/(float)height, 0.1f, 1000f); gl.glMatrixMode(GL.GL_MODELVIEW); gl.glLoadIdentity(); gl.glTranslatef(-10,-3,-10); gl.glRotatef(1,0,0,1); gl.glScalef(0.1f,0.1f,0.1f); tr.begin3DRendering(); tr.draw("some text", 0, 0); tr.draw("bla blo blu", 0, 14); tr.draw(whitespacestring, 0, 28); tr.end3DRendering(); } public void init(GLAutoDrawable arg0) { tr = new TextRenderer(new java.awt.Font("Verdana", java.awt.Font.PLAIN, 10), true, false, null, false); tr.setColor(0,0,1,1); } public void reshape(GLAutoDrawable arg0, int arg1, int arg2, int arg3, int arg4) { width = arg3; height = arg4; GL gl = arg0.getGL(); gl.glViewport(0, 0, width, height); gl.glMatrixMode(GL.GL_PROJECTION); gl.glLoadIdentity(); gl.glOrtho(0.0, 800, 0.0, 200, -100.0, 100.0); gl.glMatrixMode(GL.GL_MODELVIEW); gl.glLoadIdentity(); } public void displayChanged(GLAutoDrawable arg0, boolean arg1, boolean arg2) {} }