problem with gl object

Hi folks,

I have a silly question but now I cant get with the answer. I want a button in my JOGL app that reset the point of view when the user press it. The problem is, from where do I get the gl object ?
In display, init, etc methods, we get it this way -> GL gl = autodrawable.getGL(), but now? the api spef says yoy shouldnt save it because multithreading.

Thank you in advance.

Use a GLJPanel and use a normal button, when they click the button, store the event in a variable so that the next time a frame is rendered, you can reset the view. Also, you can create a Runnable that resets the view and use the Threading class in jogl to invoke it later on the opengl thread.

usually you save coordinates of objects and the camera setup in variables. if you have that, just modify these variables and in the next frame they will be rendered at the new coordinates.

Thanks ;). I was thinking on the hard solution. Lhkbob, could you explain a bit deeper your second solution ?

If I’m thinking of the same problem that you are, you could try this:
Create an FPSAnimator for your GLCanvas/GLEventListener. This way it will automatically update the graphics. In the JFrame holding the GLJPanel (we want it to be lightweight), also add a JButton with an ActionListener added to it. In the ActionListener (preferably the same class that implement GLEventListener), have a boolean called buttonClicked. When the button is clicked, set this true. When a display() is called in the GLEventListener, check if buttonClicked is true. If it is, set the view/do whatever you’d want the button to do, then be sure to set buttonClicked to false.

If you’re updating the GLJPanel fast enough, there shouldn’t be any noticeable lag between click and update.