I have the same problem when I use the Animator object. In the code above I put the display method inside a loop. Well it isn’t the best solution for me. Any one knows if is possible to use the Animator object with GLWindow?
import javax.media.opengl.*;
import com.sun.javafx.newt.*;
import com.sun.javafx.newt.opengl.*;
import javax.media.opengl.glu.GLU;
/**
* @author Brian Paul
* converted to Java by Ron Cemer and Sven Goethel, ported to JOGL2 by Michael Bien
*
* This version is equal to Brian Paul's version 1.2 1999/10/21
*/
public class ExemploFullScreenGLWindow implements GLEventListener {
int teclaPressionada;
public ExemploFullScreenGLWindow() {
GLCapabilities caps = new GLCapabilities(null);
final GLWindow window = GLWindow.create(caps);
window.addGLEventListener(this);
window.addKeyListener(new KeyListener() {
@Override
public void keyPressed(KeyEvent arg0) {
teclaPressionada = arg0.getKeyCode();
}
@Override
public void keyReleased(KeyEvent arg0) { }
@Override
public void keyTyped(KeyEvent arg0) { }
});
window.addWindowListener(new WindowListener() {
@Override
public void windowResized(WindowEvent arg0) { }
@Override
public void windowMoved(WindowEvent arg0) { }
@Override
public void windowDestroyNotify(WindowEvent arg0) {
new Thread(new Runnable() {
public void run() {
// animator.stop();
window.getFactory().shutdown();
System.exit(0);
}
}).start();
}
@Override
public void windowGainedFocus(WindowEvent arg0) { }
@Override
public void windowLostFocus(WindowEvent arg0) { }
});
window.enablePerfLog(true);
// Size OpenGL to Video Surface
window.setSize(800, 600);
window.setFullscreen(true);
window.setVisible(true);
while (teclaPressionada!=KeyEvent.VK_ESCAPE) {
window.display();
}
window.destroy();
window.getFactory().shutdown();
}
public static void main(String[] args) {
new ExemploFullScreenGLWindow();
}
public void init(GLAutoDrawable drawable) {
GL2 gl = drawable.getGL().getGL2();
System.err.println("INIT GL2 IS: " + gl.getClass().getName());
// Enable VSync
gl.setSwapInterval(1);
// Setup the drawing area and shading mode
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
gl.glShadeModel(GL2.GL_SMOOTH); // try setting this to GL_FLAT and see what happens.
}
public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
GL2 gl = drawable.getGL().getGL2();
GLU glu = new GLU();
// avoid a divide by zero error!
if (height <= 0)
height = 1;
final float h = (float) width / (float) height;
gl.glViewport(0, 0, width, height);
gl.glMatrixMode(GL2.GL_PROJECTION);
gl.glLoadIdentity();
glu.gluPerspective(45.0f, h, 1.0, 20.0);
gl.glMatrixMode(GL2.GL_MODELVIEW);
gl.glLoadIdentity();
}
public void display(GLAutoDrawable drawable) {
GL2 gl = drawable.getGL().getGL2();
// Clear the drawing area
gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);
// Reset the current matrix to the "identity"
gl.glLoadIdentity();
// Move the "drawing cursor" around
gl.glTranslatef(-1.5f, 0.0f, -6.0f);
// Drawing Using Triangles
gl.glBegin(GL2.GL_TRIANGLES);
gl.glColor3f(1.0f, 0.0f, 0.0f); // Set the current drawing color to red
gl.glVertex3f(0.0f, 1.0f, 0.0f); // Top
gl.glColor3f(0.0f, 1.0f, 0.0f); // Set the current drawing color to green
gl.glVertex3f(-1.0f, -1.0f, 0.0f); // Bottom Left
gl.glColor3f(0.0f, 0.0f, 1.0f); // Set the current drawing color to blue
gl.glVertex3f(1.0f, -1.0f, 0.0f); // Bottom Right
// Finished Drawing The Triangle
gl.glEnd();
// Move the "drawing cursor" to another position
gl.glTranslatef(3.0f, 0.0f, 0.0f);
// Draw A Quad
gl.glBegin(GL2.GL_QUADS);
gl.glColor3f(0.5f, 0.5f, 1.0f); // Set the current drawing color to light blue
gl.glVertex3f(-1.0f, 1.0f, 0.0f); // Top Left
gl.glVertex3f(1.0f, 1.0f, 0.0f); // Top Right
gl.glVertex3f(1.0f, -1.0f, 0.0f); // Bottom Right
gl.glVertex3f(-1.0f, -1.0f, 0.0f); // Bottom Left
// Done Drawing The Quad
gl.glEnd();
}
public void dispose(GLAutoDrawable arg0) { }
}
Best Regards.
Claudio Eduardo Goes