Skip to content

Instantly share code, notes, and snippets.

@xranby
Created November 8, 2012 17:57
Show Gist options
  • Save xranby/4040407 to your computer and use it in GitHub Desktop.
Save xranby/4040407 to your computer and use it in GitHub Desktop.
/*
# This code is a NEWT JogAmp JOGL 2 port of:
# https://sites.google.com/site/justinscsstuff/jogl-tutorial-3
#
# Get the latest JogAmp JOGL 2
wget http://jogamp.org/deployment/jogamp-current/archive/jogamp-all-platforms.7z
7z x jogamp-all-platforms.7z
cd jogamp-all-platforms
# Compile this demo.
javac -cp jar/jogl-all.jar:jar/gluegen-rt.jar SimpleScene.java
# And run it!
java -cp jar/jogl-all.jar:jar/gluegen-rt.jar:. SimpleScene
# Xerxes Rånby
*/
import javax.media.opengl.*;
import com.jogamp.opengl.util.*;
import com.jogamp.newt.opengl.GLWindow;
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);
GLWindow window = GLWindow.create(caps);
window.setSize(300, 300);
window.setVisible(true);
window.addGLEventListener(new SimpleScene());
FPSAnimator animator = new FPSAnimator(window, 60);
animator.add(window);
animator.start();
}
@Override
public void display(GLAutoDrawable drawable) {
update();
render(drawable);
}
@Override
public void dispose(GLAutoDrawable drawable) {
System.exit(0);
}
@Override
public void init(GLAutoDrawable drawable) {
}
@Override
public void reshape(GLAutoDrawable drawable, int x, int y, int w, int h) {
}
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.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();
}
}
@Vennik
Copy link

Vennik commented Apr 1, 2015

Same issue as BonzaiThePenguin (his fix works):

Drawable already added to animator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment