I just upgraded from a PPC Mac with Tiger to an Intel Mac with Leopard. And now some of my JOGL code which worked on my older machine isn’t working anymore. I am using JOGL 1.1.1 and Java 1.5.
Below is a sample program which on the new machine just shows a window with a black background and doesn’t seem to be rendering the polygon. This same program works fine on my old computer. Am I doing something wrong?
import java.awt.;
import java.awt.event.;
import javax.swing.;
import javax.swing.event.;
import java.nio.*;
import javax.media.opengl.;
import javax.media.opengl.glu.;
import com.sun.opengl.util.*;
public class Test6 implements GLEventListener {
private FloatBuffer vertexBuffer =
ByteBuffer.allocateDirect(32).asFloatBuffer();
private FloatBuffer colorBuffer =
ByteBuffer.allocateDirect(48).asFloatBuffer();
{
vertexBuffer.put(10f); vertexBuffer.put(10f);
vertexBuffer.put(90f); vertexBuffer.put(10f);
vertexBuffer.put(90f); vertexBuffer.put(90f);
vertexBuffer.put(10f); vertexBuffer.put(90f);
colorBuffer.put(1f); colorBuffer.put(1f); colorBuffer.put(1f);
colorBuffer.put(1f); colorBuffer.put(0f); colorBuffer.put(0f);
colorBuffer.put(0f); colorBuffer.put(1f); colorBuffer.put(0f);
colorBuffer.put(0f); colorBuffer.put(0f); colorBuffer.put(1f);
}
public static void main(String[] args) {
JFrame frame = new JFrame();
GLCanvas glCanvas = new GLCanvas();
glCanvas.setSize(512, 512);
glCanvas.addGLEventListener(new Test6());
final Animator animator = new FPSAnimator(glCanvas, 30);
frame.getContentPane().add(glCanvas);
frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
animator.stop();
System.exit(0);
}
public void windowOpened(WindowEvent e) {
animator.start();
}
});
frame.pack();
frame.setVisible(true);
}
public void init(GLAutoDrawable drawable) {
GL gl = drawable.getGL();
GLU glu = new GLU();
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
gl.glViewport(0, 0, 512, 512);
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();
glu.gluOrtho2D(0.0, 100.0, 0.0, 100.0);
}
public void display(GLAutoDrawable drawable) {
GL gl = drawable.getGL();
gl.glClear(GL.GL_COLOR_BUFFER_BIT);
gl.glEnableClientState(GL.GL_COLOR_ARRAY);
gl.glEnableClientState(GL.GL_VERTEX_ARRAY);
vertexBuffer.rewind();
gl.glVertexPointer(2, GL.GL_FLOAT, 0, vertexBuffer);
colorBuffer.rewind();
gl.glColorPointer(3, GL.GL_FLOAT, 0, colorBuffer);
gl.glBegin(GL.GL_POLYGON);
gl.glArrayElement(0);
gl.glArrayElement(1);
gl.glArrayElement(2);
gl.glArrayElement(3);
gl.glEnd();
}
public void reshape(GLAutoDrawable drawable,
int x, int y, int width, int height) {
}
public void displayChanged(GLAutoDrawable drawable,
boolean modeChanged, boolean deviceChanged) {
}
}