Created
November 8, 2012 17:57
-
-
Save xranby/4040407 to your computer and use it in GitHub Desktop.
A NEWT JogAmp JOGL 2 port of: https://sites.google.com/site/justinscsstuff/jogl-tutorial-3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
# 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(); | |
} | |
} |
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
The line "animator.add(window)" needs to be removed to work with version 2.2.4 of JOGL, presumably because the window was already added in the constructor.