Picking library with Eclipse

I'm trying to use the Picking library by Nicolas Clavaud for a project that I'm programming in Eclipse. I was able to get a picking demo to work in the Processing application, but the same code doesn't run in Eclipse, it produces a null pointer exception. Here's the stack trace:

Exception in thread "Animation Thread" java.lang.RuntimeException: java.lang.NullPointerException
    at com.jogamp.common.util.awt.AWTEDTExecutor.invoke(AWTEDTExecutor.java:58)
    at jogamp.opengl.awt.AWTThreadingPlugin.invokeOnOpenGLThread(AWTThreadingPlugin.java:103)
    at jogamp.opengl.ThreadingImpl.invokeOnOpenGLThread(ThreadingImpl.java:206)
    at javax.media.opengl.Threading.invokeOnOpenGLThread(Threading.java:172)
    at javax.media.opengl.Threading.invoke(Threading.java:191)
    at javax.media.opengl.awt.GLCanvas.display(GLCanvas.java:541)
    at processing.opengl.PJOGL.requestDraw(PJOGL.java:688)
    at processing.opengl.PGraphicsOpenGL.requestDraw(PGraphicsOpenGL.java:1623)
    at processing.core.PApplet.run(PApplet.java:2177)
    at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.NullPointerException
    at processing.opengl.PJOGL.enable(PJOGL.java:1640)
    at processing.opengl.PGraphicsOpenGL.blendModeImpl(PGraphicsOpenGL.java:5947)
    at processing.core.PGraphics.blendMode(PGraphics.java:1842)
    at processing.core.PGraphics.defaultSettings(PGraphics.java:952)
    at processing.opengl.PGraphicsOpenGL.defaultSettings(PGraphicsOpenGL.java:2003)
    at processing.core.PGraphics.checkSettings(PGraphics.java:892)
    at Buffer.callCheckSettings(Buffer.java:38)
    at Picker.(Picker.java:49)
    at PickingDemo.setup(PickingDemo.java:25)
    at processing.core.PApplet.handleDraw(PApplet.java:2281)
    at processing.opengl.PJOGL$PGLListener.display(PJOGL.java:862)
    at jogamp.opengl.GLDrawableHelper.displayImpl(GLDrawableHelper.java:652)
    at jogamp.opengl.GLDrawableHelper.display(GLDrawableHelper.java:636)
    at javax.media.opengl.awt.GLCanvas$10.run(GLCanvas.java:1284)
    at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1106)
    at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:981)
    at javax.media.opengl.awt.GLCanvas$11.run(GLCanvas.java:1295)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:199)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:672)
    at java.awt.EventQueue.access$400(EventQueue.java:81)
    at java.awt.EventQueue$2.run(EventQueue.java:633)
    at java.awt.EventQueue$2.run(EventQueue.java:631)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:642)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

And here's the code I'm running:

import picking.*;
import processing.core.*;
import processing.opengl.*;
public class PickingDemo extends PApplet{

    Picker picker;

    // Set up variables for the scene.
    float r = (float) 0.0;
    int[] colors = {
      color(064,064,064), // Black
      color(255,000,000), // Red
      color(000,255,000), // Green
      color(000,000,255), // Blue
      color(255,255,000), // Yellow
      color(255,000,255), // Purple
      color(000,255,255), // Cyan
      color(255,255,255) }; // White
      int bgcolor = color(32);

    public void setup(){
      // Set the size, and make this a 3D sketch.
      size(300,300, P3D);
      // Set up the picking object.
      picker = new Picker(this);
    }

    public void draw(){
      // Define a variable to track the current object's ID.
      int currentID = 0;
      // The background's ID is always -1
      background(bgcolor);
      lights();
      noStroke();
      translate((float) (width/2.0), (float) (height/2.0), (float) 30);
      rotateY(r);
      r=(float) ((r+0.01)%TWO_PI);
      for(int x=-1;x<2;x++){
        for(int y=-1;y<2;y++){
          for(int z=-1;z<2;z++){
            // Each box has a different object ID, so you have to tell the picker which ID to use. 
            picker.start(currentID);
            pushMatrix();
            scale(40);
            translate(x,y,z);
            if(x*y*z != 0){
              // Each box is has a different color.
              fill(colors[currentID]);
              // Draw the box.
              box(1);
              currentID++;
            }
            popMatrix();
            // Tell the picker to stop using the ID, since we don't want any other objects to use this ID.
            picker.stop();
          }
        }
      }

    // See the click buffer. Warning: Heavy code.
    //loadPixels();
    //picker.getBuffer().loadPixels();
    //for( int i = 0; i < width * height; i++){
    //  pixels[i] = 200 * picker.getBuffer().pixels[i];
    //}
    //updatePixels();

    }

    public void mouseClicked(){
      // Get the object ID at the mouse's position.
      int mouseID = picker.get(mouseX,mouseY);
      println( mouseID );
      if(mouseID!=-1){
        // Set the background to the same color (but darker) to indicate which box was clicked.
        bgcolor = color( red(colors[mouseID])/2, green(colors[mouseID])/2, blue(colors[mouseID])/2 );
      } 
    }
}

Any help would be appreciated, thanks.

Answers

  • I think you have not included the OpenGL (P3D uses OpenGL) libraries see this topic

  • I have core, jogl-all* and glugen-rt* all included. I don't recognize the others from that screenshot, so I'll look into them (are they necessary)?

  • are they necessary?

    events-on-fire is a library that creates asynchronous events and pde is the Processing IDE, so the answer is no you don't need them.

    Since you have there it maybe caused by the Picking library - I have seen topics about using Picking with Processing 2 but can't remember the details. Might be worth searching the forum.

Sign In or Register to comment.