import javax.media.opengl.*;
import com.sun.opengl.util.Animator;
import java.awt.event.*;
//built on J1_O_Point class
public class J1_1_Point extends J1_0_Point {
static Animator animator; // drive display() in a loop
public J1_1_Point() {
// use super's constructor to initialize drawing
//1. specify using only a single buffer
capabilities.setDoubleBuffered(false);
//2. add a listener for window closing
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
animator.stop(); // stop animation
System.exit(0);
}
});
}
// called one-time for OpenGL initialization
public void init(GLAutoDrawable drawable) {
// specify a drawing color: red
gl.glColor3f(1.0f, 0.0f, 0.0f);
//3. clear the background to black
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
gl.glClear(GL.GL_COLOR_BUFFER_BIT);
//4. drive the display() in a loop
animator = new Animator(canvas);
animator.start(); // start animator thread
}
// called for OpenGL rendering every reshape
public void display(GLAutoDrawable drawable) {
//5. generate a random point
double x = Math.random()*WIDTH;
double y = Math.random()*HEIGHT;
// specify to draw a point
gl.glBegin(GL.GL_POINTS);
gl.glVertex2d(x, y);
gl.glEnd();
}
public static void main(String[] args) {
J1_1_Point f = new J1_1_Point();
//6. add a title on the frame
f.setTitle("JOGL J1_1_Point");
f.setSize(WIDTH, HEIGHT);
f.setVisible(true);
}
}