Re: Possible to have GLCanvas's display() called *after* all other Swing events?
Posted by farrellf on Nov 28, 2017; 11:09pm
URL: https://forum.jogamp.org/Possible-to-have-GLCanvas-s-display-called-after-all-other-Swing-events-tp4038306p4038342.html
Source code for that demo is:
import javax.swing.JFrame;
import com.jogamp.opengl.GL2;
import com.jogamp.opengl.GLAutoDrawable;
import com.jogamp.opengl.GLCapabilities;
import com.jogamp.opengl.GLEventListener;
import com.jogamp.opengl.GLProfile;
import com.jogamp.opengl.awt.GLCanvas;
import com.jogamp.opengl.util.Animator;
public class Test {
public static void main(String[] args) {
JFrame window = new JFrame("Test");
GLCanvas canvas = new GLCanvas(new GLCapabilities(GLProfile.get(GLProfile.GL2)));
canvas.addGLEventListener(new GLEventListener() {
@Override public void init(GLAutoDrawable drawable) {
GL2 gl = drawable.getGL().getGL2();
gl.setSwapInterval(1);
}
@Override public void display(GLAutoDrawable drawable) {
GL2 gl = drawable.getGL().getGL2();
gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
gl.glClear(GL2.GL_COLOR_BUFFER_BIT);
gl.glColor3f(0, 0, 0);
gl.glBegin(GL2.GL_TRIANGLES);
gl.glVertex2f(-0.9f, -0.9f);
gl.glVertex2f( 0.0f, 0.9f);
gl.glVertex2f( 0.9f, -0.9f);
gl.glEnd();
}
@Override public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { }
@Override public void dispose(GLAutoDrawable drawable) { }
});
Animator animator = new Animator(canvas);
animator.setUpdateFPSFrames(1, null);
animator.start();
window.add(canvas);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setSize(600, 600);
window.setVisible(true);
}
}