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? ???