Most JOGL examples I’ve seen create an Animator and put game logic (usually just animation) in display(). Is this the safest place to put it, or can there be problems because you’re in JOGL’s thread? Also, is it safe to use Thread.sleep in the display() method? (I noticed that if I minimize my application, display() is still called, leading to 1000+ “fps”; is there a way to tell whether the canvas is visible and sleep in this case?)
Also, an unrelated question, about JOGL performance: I started with the second lesson on http://nehe.gamedev.net, and modified display() to draw 10000 triangles instead of 1 as follows:
gl.glBegin(GL.GL_TRIANGLES); // Drawing Using Triangles
for(int i=0; i<10000; i++) {
gl.glVertex3f(0.0f, 1.0f, 0.0f); // Top
gl.glVertex3f(-1.0f, -1.0f, 0.0f); // Bottom Left
gl.glVertex3f(1.0f, -1.0f, 0.0f); // Bottom Right
}
gl.glEnd(); // Finished Drawing The Triangle
This slows down performance pretty significantly, from about 60 fps (which is my monitor’s refresh rate - if I turn off wait-for-vsync I get about 200) to maybe 5 fps. (My software 3d renderer probably does better than that!). I assume this is because glVertex3f is a native method, and there’s a high overhead in calling it. Is there a way to specifiy the mesh within an array and then pass it to OpenGL in a “batch”? (I’d also like to use skeletal animation so I want to build up or modify this thing every frame, if possible).