Posted by
Dan on
Oct 26, 2010; 11:10pm
URL: https://forum.jogamp.org/A-problem-with-a-tutorial-tp1777294.html
Hello, I've recently been following the great tutorial at
http://sites.google.com/site/justinscsstuff/jogl-tutorial-3 .
Although I've stumbled upon a problem when I try to render a static triangle in the window. Instead of getting a triangle as one would expect, I get a blank window.
The source code I'm trying is as follows:
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.media.opengl.*;
import javax.media.opengl.awt.GLCanvas;
public class SimpleScene implements GLEventListener {
public static void main(String[] args) {
GLProfile.initSingleton();
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());
}
@Override
public void display(GLAutoDrawable drawable) {
update();
render(drawable);
}
private void update() {
}
private void render(GLAutoDrawable drawable) {
GL2 gl = drawable.getGL().getGL2();
gl.glBegin(GL.GL_TRIANGLES);
gl.glColor3f(1, 0, 0);
gl.glVertex2f(-1, -1);
gl.glColor3f(0, 1, 0);
gl.glVertex2f(0, 1);
gl.glColor3f(0, 0, 1);
gl.glVertex2f(1, -1);
gl.glEnd();
}
@Override
public void dispose(GLAutoDrawable arg0) {
}
@Override
public void init(GLAutoDrawable arg0) {
}
@Override
public void reshape(GLAutoDrawable arg0, int arg1, int arg2, int arg3,
int arg4) {
}
}
To make sure it wasn't me setting up JOGL badly, I also checked to the next part of the tutorial (with the animated triangle), for some reason this seems to work perfectly.
I've read around that you need an animation in the program to get it working, although I could be confused with something very different.
Thanks in advance.