Skip to content

Instantly share code, notes, and snippets.

@tyfkda
Created April 12, 2016 07:41
Show Gist options
  • Save tyfkda/086669ec065fd323e2d585883c5d6a94 to your computer and use it in GitHub Desktop.
Save tyfkda/086669ec065fd323e2d585883c5d6a94 to your computer and use it in GitHub Desktop.
jogl sample
// Modified from
// JOGL Tutorial 3 - Creating a Render Loop - Justin's Home
// https://sites.google.com/site/justinscsstuff/jogl-tutorial-3
// for jogl-1.1.1
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.media.opengl.*;
//import javax.media.opengl.awt.GLCanvas;
//import com.jogamp.opengl.util.*;
import com.sun.opengl.util.Animator;
import com.sun.opengl.util.FPSAnimator;
public class SimpleScene implements GLEventListener {
private double theta = 0;
private double s = 0;
private double c = 0;
public static void main(String[] args) {
//GLProfile glp = GLProfile.getDefault();
GLCapabilities caps = new GLCapabilities(/*glp*/);
GLCanvas canvas = new GLCanvas(caps);
Frame frame = new Frame("AWT Window Test");
frame.setSize(300, 300);
frame.add(canvas);
frame.setVisible(true);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
canvas.addGLEventListener(new SimpleScene());
Animator animator = new FPSAnimator(canvas, 60);
animator.add(canvas);
animator.start();
}
@Override public void display(GLAutoDrawable drawable) {
update();
render(drawable);
}
//@Override public void dispose(GLAutoDrawable drawable) {
//}
@Override public void init(GLAutoDrawable drawable) {
}
@Override public void reshape(GLAutoDrawable drawable, int x, int y, int w, int h) {
}
@Override public void displayChanged(GLAutoDrawable arg0, boolean arg1, boolean arg2) {
// TODO Auto-generated method stub
}
private void update() {
theta += 0.01;
s = Math.sin(theta);
c = Math.cos(theta);
}
private void render(GLAutoDrawable drawable) {
//GL2 gl = drawable.getGL().getGL2();
GL gl = drawable.getGL();
gl.glClear(GL.GL_COLOR_BUFFER_BIT);
// draw a triangle filling the window
gl.glBegin(GL.GL_TRIANGLES);
gl.glColor3f(1, 0, 0);
gl.glVertex2d(-c, -c);
gl.glColor3f(0, 1, 0);
gl.glVertex2d(0, c);
gl.glColor3f(0, 0, 1);
gl.glVertex2d(s, -s);
gl.glEnd();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment