Hi Ken,
I have a MacBook Pro, it has a 256 MB ATI Mobility Radeon X1600 graphics card.
I heard that Eclipse for Mac has some issues with SWT / AWT…so I tried running the same program on NetBeans. FPS is better at around 57…but still remarkably slow. (The Windows machine mentioned earlier actually runs the program at 750 FPS, not 1000)
I’ve also set the gl.setSwapBuffers(0), no effect.
I’ve attached my code in case you’d like to try it. I took this from the Wikipedia JOGL article and modified it so that it displays FPS once the close window button (X) is clicked. The code renders a triangle base pyramid that rotates faster as the frame rate is higher.
Run JavaDia to start the program.
Anything else that I should try?
Thanks
JavaDia
import com.sun.opengl.util.Animator;
import javax.media.opengl.GLCanvas;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class JavaDia implements Runnable {
static Thread displayT = new Thread(new JavaDia());
static boolean bQuit = false;
static long startTime = 0;
public static void main(String[] args) {
displayT.start();
}
public void run() {
Frame frame = new Frame("Jogl 3d Shape/Rotation");
GLCanvas canvas = new GLCanvas();
canvas.addGLEventListener(new JavaRenderer());
frame.add(canvas);
frame.setSize(640, 480);
//frame.setUndecorated(true);
int size = frame.getExtendedState();
size |= Frame.MAXIMIZED_BOTH;
frame.setExtendedState(size);
Animator animator = new Animator(canvas);
startTime = System.currentTimeMillis();
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
bQuit = true;
displayT.stop();
long endTime = System.currentTimeMillis();
double runTime = ((double) (endTime - startTime) / 1000);
System.out.println("Runtime: " + runTime);
double fps = (double) JavaRenderer.frames / runTime;
System.out.println("FPS: " + fps);
System.exit(0);
}
});
frame.setVisible(true);
// frame.show();
canvas.requestFocus();
animator.start();
}
}
JavaRenderer
import javax.media.opengl.GL;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.glu.GLU;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
public class JavaRenderer implements GLEventListener, KeyListener {
private float rotateT = 0.0f;
private static final GLU glu = new GLU();
public static long frames = 0;
public void display(GLAutoDrawable gLDrawable) {
final GL gl = gLDrawable.getGL();
gl.glClear(GL.GL_COLOR_BUFFER_BIT);
gl.glClear(GL.GL_DEPTH_BUFFER_BIT);
gl.glLoadIdentity();
gl.glTranslatef(0.0f, 0.0f, -5.0f);
gl.glRotatef(rotateT, 1.0f, 0.0f, 0.0f);
gl.glRotatef(rotateT, 0.0f, 1.0f, 0.0f);
gl.glRotatef(rotateT, 0.0f, 0.0f, 1.0f);
gl.glRotatef(rotateT, 0.0f, 1.0f, 0.0f);
gl.glBegin(GL.GL_TRIANGLES);
// Front
gl.glColor3f(0.0f, 1.0f, 1.0f); gl.glVertex3f(0.0f, 1.0f, 0.0f);
gl.glColor3f(0.0f, 0.0f, 1.0f); gl.glVertex3f(-1.0f, -1.0f, 1.0f);
gl.glColor3f(0.0f, 0.0f, 0.0f); gl.glVertex3f(1.0f, -1.0f, 1.0f);
// Right Side Facing Front
gl.glColor3f(0.0f, 1.0f, 1.0f); gl.glVertex3f(0.0f, 1.0f, 0.0f);
gl.glColor3f(0.0f, 0.0f, 1.0f); gl.glVertex3f(1.0f, -1.0f, 1.0f);
gl.glColor3f(0.0f, 0.0f, 0.0f); gl.glVertex3f(0.0f, -1.0f, -1.0f);
// Left Side Facing Front
gl.glColor3f(0.0f, 1.0f, 1.0f); gl.glVertex3f(0.0f, 1.0f, 0.0f);
gl.glColor3f(0.0f, 0.0f, 1.0f); gl.glVertex3f(0.0f, -1.0f, -1.0f);
gl.glColor3f(0.0f, 0.0f, 0.0f); gl.glVertex3f(-1.0f, -1.0f, 1.0f);
// Bottom
gl.glColor3f(0.0f, 0.0f, 0.0f); gl.glVertex3f(-1.0f, -1.0f, 1.0f);
gl.glColor3f(0.1f, 0.1f, 0.1f); gl.glVertex3f(1.0f, -1.0f, 1.0f);
gl.glColor3f(0.2f, 0.2f, 0.2f); gl.glVertex3f(0.0f, -1.0f, -1.0f);
gl.glEnd();
rotateT += 0.2f;
frames++;
}
public void displayChanged(GLAutoDrawable gLDrawable, boolean modeChanged, boolean deviceChanged) {
}
public void init(GLAutoDrawable gLDrawable) {
final GL gl = gLDrawable.getGL();
gl.glShadeModel(GL.GL_SMOOTH);
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
gl.glClearDepth(1.0f);
gl.glEnable(GL.GL_DEPTH_TEST);
gl.glDepthFunc(GL.GL_LEQUAL);
gl.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);
gl.setSwapInterval(0);
gLDrawable.addKeyListener(this);
}
public void reshape(GLAutoDrawable gLDrawable, int x, int y, int width, int height) {
final GL gl = gLDrawable.getGL();
if(height <= 0) {
height = 1;
}
final float h = (float)width / (float)height;
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();
glu.gluPerspective(50.0f, h, 1.0, 1000.0);
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glLoadIdentity();
}
public void keyPressed(KeyEvent e) {
if(e.getKeyCode() == KeyEvent.VK_ESCAPE) {
JavaDia.bQuit = true;
JavaDia.displayT.stop();
System.exit(0);
}
}
public void keyReleased(KeyEvent e) {
}
public void keyTyped(KeyEvent e) {
}
}