Problem with glGetIntegerv/glGetDoublev

Hi,

I have a problem to get values for modelMatrix, projectionMatrix and viewport. I only obtain the values for this matrices if the respective init function are called in Display() method.

Follows the code:

  private YxxfGfxPointW DCStoMCS(YxxfGfxPointS pt) {
        int[] viewport = new int[4];
        double[] matrizModelo = new double[16];
        double[] matrizProjecao = new double[16];
        int winY;
        double[] x = new double[1];
        double[] y = new double[1];
        double[] z = new double[1];
        
        // get the matrix values
        gl.glGetIntegerv(GL.GL_VIEWPORT, viewport);
        winY = viewport[3] - pt.y - 1;
        gl.glGetDoublev(GL.GL_MODELVIEW_MATRIX, matrizModelo);
        gl.glGetDoublev(GL.GL_PROJECTION_MATRIX, matrizProjecao);

somebody knows the reason?

Maurício

Sweet zombie jesus thats one hell of an obscurificated method signiture!

I suspect you’re attempting to call GL methods from outside of the GL thread, which isn’t allowed (ie. outside of the GLEventListener methods). In general, don’t hang on to a reference to the gl object to avoid this.

How you fix it is another matter. I suggest you’ll probably want to queue up your mouse clicks and flush the queue manually from your gl display callback.

Can you write a simple code with the skeleton of sugestion?

Actually. The solution is quite simple. Call glGetIntegerv etc. from the same thread as your GLEventListener.
For instance in the display function with GL handle retrieved from getGL() on the GLDrawable you get :slight_smile:

A common error when picking is to call it from some AWT callback which is in a different thread.

Ok, suppose you have this class


public class GLfunctions extends JPanel implements GLEventListener, MouseListener, 
      MouseWheelListener, KeyListener, Animated {
....

The methods that implement MouseListener are run on a different thread from GLfunctions?

[quote]Ok, suppose you have this class


public class GLfunctions extends JPanel implements GLEventListener, MouseListener, 
      MouseWheelListener, KeyListener, Animated {
....

The methods that implement MouseListener are run on a different thread from GLfunctions?
[/quote]
Yes, the mouse events happen on the awt dispatch thread.

That would be my point, yes :slight_smile: