JOGL refresh window problem

Hello,

i work on a little JOGL app for study and had a problem. Nearly everything works perfect just events don’t do like i want.
I had a EventManager class that cannot call the RenderManager (the class that have the init,reshape,display methods) to refresh the window and make the change of position visible.

In detail the problem is that i use the EventManager to catch mouse events that i want to use for navigate throw the szene. In a app that i programmed in c++ with opengl i had a reference of the RenderManager in my EventManager, and simply do a RenderManager.reshape() or .display() and the szene was been refreshed.
In java i also have the reference to my RenderManager in my EventManager object and i attempt to call the reshape() function of my RenderManager.

here is what i attempt to do:


public class RenderManager implements GLEventListener {
     private GL ourGL;
     private final GLU glu;
     private final GLUT glut;
     ...
     ...
     public RenderManager (int x, int y,int w, int h) {
           ...
           ...
	   GLCanvas canvas = new GLCanvas();
	   canvas.addGLEventListener(this);
           this.glu = new GLU();
	   this.glut = new GLUT();
           ...
           ...
     }//RenderManager 


     public void init(GLAutoDrawable drawable) {
           ...
           ...	    	
          this.ourGL= drawable.getGL();
          EventManager myEvents = new EventManager(drawable,this);
           ...
           ...
     }// init

     public void reshape(GLAutoDrawable drawable, int x, int y, int w, int h) {
	    	ourGL.glViewport(posX, posY, width, height);
	    	ourGL.glMatrixMode(GL.GL_PROJECTION);
	    	ourGL.glLoadIdentity();

	    	glu.gluPerspective(45, (double)width/height, 1, 2000);

	    	Point3d pos = this.viewpoint.getPositionPoint();
	    	Point3d center = this.viewpoint.getCenterPoint();

	    	glu.gluLookAt(pos.getX(), pos.getY(), pos.getZ(),center.getX(), center.getY(), center.getZ(), 0, 1, 0);
     }// reshape
}// class

And here whats important in EventManager


public class EventManager implements MouseListener, MouseMotionListener {
           ...
     private GLAutoDrawable drawAble;
     private RenderManager rm;
           ...
     public EventManager(GLAutoDrawable drawable,RenderManager rm) {
           ...
           ...
          this.drawAble=dramable;
          this.rm=rm;
          drawable.addMouseListener(this);
          drawable.addMouseMotionListener(this);
           ...
           ...
     }

           ...
           ...
     public void mouseDragged(MouseEvent e) {
          // change some vars
          this.rm.display(drawAble);
     }
           ...
           ...
}// class

without the line
this.rm.display(drawAble);
everything is working when i reshape the window (by resize it), it navigates as it should. But it does not refresh the window and i don’t see the navigation if i don’t resize the window.

If the codeline is included it crashes when i want to navigate.
i got the following error:

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:234)
	at com.sun.opengl.util.GLUT.glutStrokeCharacter(GLUT.java:391)
	at de.neoberserker.JOGLtest.OrientierungsNode.zeichneObjekt(OrientierungsNode.java:42)
	at de.neoberserker.JOGLtest.Node.display(Node.java:73)
	at de.neoberserker.JOGLtest.NodeManager.displaySzene(NodeManager.java:118)
	at de.neoberserker.JOGLtest.RenderManager.display(RenderManager.java:142)
	at de.neoberserker.JOGLtest.EventManager.mouseDragged(EventManager.java:90)
	at java.awt.Component.processMouseMotionEvent(Component.java:6086)
	at java.awt.Component.processEvent(Component.java:5807)
	at java.awt.Component.dispatchEventImpl(Component.java:4410)
	at java.awt.Component.dispatchEvent(Component.java:4240)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)

My question is now how i can solve this. It looks to me like it is a synchronisation problem between the threads of my events class (EventManager) and the internal threads of jogl/GL) that makes it impossible to give a external class a reference to my RenderManager and then let the external class run the display or reshape methods.

Then i added a global
private GLAutoDrawable drawable;
to my RenderManager class, and added
this.drawable=drawable;
in init function

then i wrote a method RenderManager.redrawIt();


public void redrawIt() {
     this.display(this.drawable);
}

then i call the RenderManager.redraw() method from EventManager in the mouseDragged method.

this.display(this.drawable);

Result:

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:234)
	at javax.media.opengl.glu.GLU.gluPerspective(GLU.java:1188)
	at de.neoberserker.JOGLtest.RenderManager.reshape(RenderManager.java:172)
	at de.neoberserker.JOGLtest.RenderManager.display(RenderManager.java:130)
	at de.neoberserker.JOGLtest.RenderManager.redrawIt(RenderManager.java:186)
	at de.neoberserker.JOGLtest.EventManager.mouseDragged(EventManager.java:92)
	at java.awt.Component.processMouseMotionEvent(Component.java:6086)
	at java.awt.Component.processEvent(Component.java:5807)
	at java.awt.Component.dispatchEventImpl(Component.java:4410)
	at java.awt.Component.dispatchEvent(Component.java:4240)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)

How can i realize that RenderManger runs display() when a external class want it. Or is it nonsense to make a own event class. Please help ??? ???

Or is there another solution how to handle this ?

thanks
Sebastian

I solved it ;D ;D ;D

i gave the EventManager the reference for GLCanvas from RenderManager. Then i was able to make

canvas.display();

in MouseDragged Method from EventManager, and everything is fine . . .