openglexceptiongluopenglcontext

No OpenGL context current on this thread at javax.media.opengl.glu.GLU.getCurrentGL


I encountered a similar problem when I started learning Opengl (JOGL) for the "GL2 gl" months ago.... and then I discovered how to solve (everything having something to do with "gl" should be called from within the display/init method).

After some time I also needed to use the "GLU glu" (for the gluOrtho2D). Therefore this problem arose again. But lets say that it wasn't such a big problem, because the program was running fine despite this error.

Unfortunately, it seems that now this problem has some annoying effects.. so I really would like to solve it.

Here some code:

...
GLU glu = new GLU();

public void display(GLAutoDrawable gLAutoDrawable) {
    ...
    //  map a 2D bild width*height on OpenGL
    glu.gluOrtho2D(-width/2, (width+1)/2, -(height+1)/2, height/2);
}        

The funny thing is that:

but nothing so far worked:

Exception in thread "AWT-EventQueue-0" javax.media.opengl.GLException: No OpenGL context current on this thread at javax.media.opengl.glu.GLU.getCurrentGL(GLU.java:175) at javax.media.opengl.glu.GLU.gluOrtho2D(GLU.java:1344)


Solution

  • I tried to move the getContext and the makeCurrent just before the glu.gluOrtho2D and it worked..