import java.awt.*; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.nio.FloatBuffer; import com.sun.opengl.util.Animator; import com.sun.opengl.util.BufferUtil; import com.sun.opengl.util.j2d.TextRenderer; import javax.media.opengl.GL; import javax.media.opengl.GLCanvas; import javax.media.opengl.GLCapabilities; import javax.media.opengl.GLAutoDrawable; import javax.media.opengl.GLEventListener; public class HelloWorldDemo extends Frame implements GLEventListener{ private static final long serialVersionUID = 1L; private TextRenderer textRenderer; private int[] id=new int[1]; private FloatBuffer buffer=BufferUtil.newFloatBuffer(0); public HelloWorldDemo(){ super("JOGL 1.1.1"); setLayout(new BorderLayout()); setSize(400, 400); setLocation(40, 40); setVisible(true); GLCapabilities caps = new GLCapabilities(); caps.setDoubleBuffered(true); caps.setHardwareAccelerated(true); GLCanvas canvas = new GLCanvas(caps); canvas.addGLEventListener(this); add(canvas, BorderLayout.CENTER); Animator anim = new Animator(canvas); anim.start(); addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e){ System.exit(0); } }); buffer.put(new float[]{}); buffer.position(0); } public void init(GLAutoDrawable drawable){ GL gl = drawable.getGL(); gl.glClearColor(0, 0, 0, 0); gl.glMatrixMode(GL.GL_PROJECTION); gl.glLoadIdentity(); gl.glOrtho(0, 1, 0, 1, -1, 1); textRenderer=new TextRenderer(new Font("SansSerif",Font.PLAIN,12)); gl.glGenBuffers(1,id,0); gl.glBindBuffer(GL.GL_ARRAY_BUFFER,id[0]); gl.glBufferData(GL.GL_ARRAY_BUFFER,BufferUtil.SIZEOF_FLOAT*buffer.capacity(),buffer,GL.GL_STATIC_DRAW_ARB); this.buffer.position(0); } public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height){ } public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged){ } public void display(GLAutoDrawable drawable){ GL gl = drawable.getGL(); gl.glClear(GL.GL_COLOR_BUFFER_BIT); gl.glEnableClientState(GL.GL_VERTEX_ARRAY); gl.glEnableClientState(GL.GL_TEXTURE_COORD_ARRAY); gl.glBindBuffer(GL.GL_ARRAY_BUFFER,id[0]); gl.glDrawArrays(GL.GL_QUADS,0,0); gl.glDisableClientState(GL.GL_TEXTURE_COORD_ARRAY); gl.glDisableClientState(GL.GL_VERTEX_ARRAY); textRenderer.beginRendering(100,100); textRenderer.draw("JOGL 1.1.1",0,0); textRenderer.endRendering(); gl.glFlush(); } public static void main(String[] args){ HelloWorldDemo demo = new HelloWorldDemo(); demo.setVisible(true); } }