Projection problems

I’m at something of a loss here, and i’m not sure whether my problem is Gl or native buffer related, but hopefully someone here can give some hints…

I’m attempting to get screen x/y coords from a x/y/z position in world space. Now while the theory behind doing this manually is pretty simple, I thought it would be easier to use the glu.project routine for ease. Unfortunatly this works once, and only once on the first usage, and then clams up on me :frowning: the method returns GL.FALSE to indicate faliure, yet gl.getError returns GL.NO_ERROR ???


// Member vars, created in constructor
      private IntBuffer viewport;
      private DoubleBuffer modelViewMatrix;
      private DoubleBuffer projectionMatrix;
      private DoubleBuffer windowCoords;
      
      private DoubleBuffer windowX;
      private DoubleBuffer windowY;
      private DoubleBuffer windowZ;
      private int pWindowX;
      private int pWindowY;
      private int pWindowZ;
      
      private int pViewport;
      private int pModelViewMatrix;
      private int pProjectionMatrix;
      private int pWindowCoords;

// From the mouse classes update():
                  viewport.clear();
                  modelViewMatrix.clear();
                  projectionMatrix.clear();
                  windowCoords.clear();
                  
                  windowX.clear();
                  windowY.clear();
                  windowZ.clear();
                  
                  
                  gl.getIntegerv(GL.VIEWPORT, pViewport);
                  gl.getDoublev(GL.MODELVIEW_MATRIX, pModelViewMatrix);
                  gl.getDoublev(GL.PROJECTION_MATRIX, pProjectionMatrix);
                  
                  
                  // Projection/scrolling test code
                  int returnCode = GL.TRUE;
                      returnCode = glu.project(/*position.x, position.y, position.z,*/
                                                           0, 0, 0,
                                                             pModelViewMatrix,
                                                             pProjectionMatrix,
                                                             pViewport,
                                                      //       pWindowCoords, pWindowCoords+8, pWindowCoords+16);
                                                             pWindowX, pWindowY, pWindowZ);
                  
                  if (returnCode == GL.TRUE)
                  {
                        /*
                        double x = windowCoords.get(0);
                        double y = windowCoords.get(1);
                        double z = windowCoords.get(2);
                        */
                        
                        double x = windowX.get(0);
                        double y = windowY.get(0);
                        double z = windowZ.get(0);
                        
                        
                        System.out.println("Project, x:"+x +" y:"+y +" z:"+z);
                        
                        
                  }
                  else
                  {
                  //      System.out.println("return code: "+returnCode);
                        
                        int error = gl.getError();
                        
                  //      System.out.println("Error code:"+error);
                        
                        
                        
                        if (error == GL.NO_ERROR)
                        {
                  //            System.out.println("no error");
                        }
                        else if (error == GL.INVALID_ENUM)
                        {
                              System.out.println("invalid enum");
                        }
                        else if (error == GL.INVALID_VALUE)
                        {
                              System.out.println("invalid value");
                        }
                        else if (error == GL.INVALID_OPERATION)
                        {
                              System.out.println("invalid operation");
                        }
                        
                        else if (error == GLU.INVALID_ENUM)
                        {
                              System.out.println("glu invalid enum");
                        }
                        else if (error == GLU.INVALID_VALUE)
                        {
                              System.out.println("glu invalid value");
                        }
                        
                        else
                        {
                              System.out.println("not recognised");
                        }

I assume that theres something somewhere that I have to reset before using gl.project for the second time, since everything seems to go ok for the first attempt. Yet I can’t think of anything else i’m missing…

Ooops, my bad - I was calling this method in my update() but it needs to be called during render() for the Gl matricies to be set up correctly. Unfortunatly this ties my update code and my drawing code together in a way I was hoping to avoid. Time to insert some sort of interface layer between the two methinks…