help a noob draw a cube! (using GLUT) :)

Here’s my code to draw a cube on a GLCanvas:

`import javax.media.opengl.GLCanvas;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLContext;
import javax.media.opengl.GLDrawableFactory;
import javax.media.opengl.glu.GLU;
import javax.swing.JFrame;

import com.sun.opengl.util.GLUT;

public class Viewer {
public static void main(String[] args) {
JFrame mainFrame = new JFrame();
GLCanvas canvas = new GLCanvas();
canvas.setSize(300, 300);

	GLContext drawingContext = canvas.getContext();
	drawingContext.makeCurrent();
	GLUT glut = new GLUT();
	glut.glutSolidCube(1.0f);
	mainFrame.add(canvas);
	mainFrame.pack();
	mainFrame.setVisible(true);
}

}`

and here’s my error:

Exception in thread "main" javax.media.opengl.GLException: No OpenGL context current on this thread at javax.media.opengl.glu.GLU.getCurrentGL(GLU.java:234) at com.sun.opengl.util.GLUT.glutSolidCube(GLUT.java:212) at Viewer.main(Viewer.java:20)

Now i tried to set the current GLcontext for my thread using drawingContext.makeCurrent().
As you can see it does not work. Can anybody tell me how this is done? ???

Oh yeah I’m using JSR-231 btw. That’s part of the problem, because I’m used to using the deprecated APIs which look more C like!

Uh, look at the jogl tutorial…things are not done that way :wink:

More specifically, the problem is that the “main” thread, is not a proper OpenGL rendering thread. The JOGL tutorial will show you how to create a class which can participate in OpenGL rendering, by using one of the JOGL utility classes.