/** * (C) Copyright Softwareschneiderei GmbH, Karlsruhe, Germany * @author mmv * @since 02.02.2009 */ package com.schneide.ramses.demo; import java.awt.Dimension; import javax.media.opengl.GL; import javax.media.opengl.GLAutoDrawable; import javax.media.opengl.GLEventListener; import javax.media.opengl.GLJPanel; import javax.swing.JFrame; import javax.swing.WindowConstants; import com.sun.opengl.util.Animator; import com.sun.opengl.util.j2d.TextRenderer; public class TextRendererDisplayListDemo extends JFrame implements GLEventListener { private static final long serialVersionUID = -57945727447508397L; private GLJPanel glpanel; private Animator animator; private TextRenderer textRenderer; private int displayList; public TextRendererDisplayListDemo() { super("TextRendererDisplayListDemo"); //$NON-NLS-1$ setMinimumSize(new Dimension(600, 500)); this.glpanel = new GLJPanel(); this.glpanel.setSize(400, 400); this.glpanel.addGLEventListener(this); this.animator = new Animator(this.glpanel); getContentPane().add(this.glpanel); setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); } @Override public void display(GLAutoDrawable drawable) { drawable.getGL().glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); drawable.getGL().glLoadIdentity(); paintText(drawable, 100, 100); drawable.getGL().glCallList(this.displayList); } private void paintText(GLAutoDrawable drawable, int x, int y) { this.textRenderer.beginRendering(drawable.getWidth(), drawable.getHeight()); this.textRenderer.setColor(1.0f, 0.2f, 0.2f, 0.8f); this.textRenderer.draw("Text to draw", x, y); //$NON-NLS-1$ this.textRenderer.endRendering(); } @Override public void displayChanged(GLAutoDrawable gl, boolean arg1, boolean arg2) { // do nothing } @Override public void init(GLAutoDrawable drawable) { GL gl = drawable.getGL(); gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); if (null != this.textRenderer) { this.textRenderer.dispose(); } this.textRenderer = new TextRenderer(getFont()); if (0 != this.displayList) { gl.glDeleteLists(this.displayList, 1); } this.displayList = gl.glGenLists(1); gl.glNewList(this.displayList, GL.GL_COMPILE); paintText(drawable, 200, 200); gl.glEndList(); } @Override public void reshape(GLAutoDrawable gl, int arg1, int arg2, int arg3, int arg4) { // do nothing } public static void main(String[] args) { TextRendererDisplayListDemo demo = new TextRendererDisplayListDemo(); demo.setVisible(true); demo.animator.start(); } }