Beispiel #1
0
  private void run(int type, PerfModule pm) {
    int width = 800;
    int height = 480;
    pmod = pm;
    System.err.println("Perftst.run()");
    try {
      GLCapabilities caps = new GLCapabilities(GLProfile.getGL2ES2());
      // For emulation library, use 16 bpp
      caps.setRedBits(5);
      caps.setGreenBits(6);
      caps.setBlueBits(5);
      caps.setDepthBits(16);

      Window nWindow = null;
      if (0 != (type & USE_AWT)) {
        Display nDisplay =
            NewtFactory.createDisplay(NativeWindowFactory.TYPE_AWT, null); // local display
        Screen nScreen =
            NewtFactory.createScreen(NativeWindowFactory.TYPE_AWT, nDisplay, 0); // screen 0
        nWindow = NewtFactory.createWindow(NativeWindowFactory.TYPE_AWT, nScreen, caps);
        window = GLWindow.create(nWindow);
      } else {
        window = GLWindow.create(caps);
      }

      window.addMouseListener(this);
      window.addGLEventListener(this);
      // window.setEventHandlerMode(GLWindow.EVENT_HANDLER_GL_CURRENT); // default
      // window.setEventHandlerMode(GLWindow.EVENT_HANDLER_GL_NONE); // no current ..

      // Size OpenGL to Video Surface
      window.setSize(width, height);
      window.setFullscreen(true);
      window.setVisible(true);

      window.display();

      // Shut things down cooperatively
      window.destroy();
      window.getFactory().shutdown();
      System.out.println("Perftst shut down cleanly.");
    } catch (Throwable t) {
      t.printStackTrace();
    }
  }
Beispiel #2
0
  public Sculptnect() {
    // Set up Kinect
    kinectContext = Freenect.createContext();
    if (kinectContext.numDevices() > 0) {
      kinect = kinectContext.openDevice(0);
    } else {
      System.err.println("Error, no Kinect detected.");
    }

    GLProfile.initSingleton();
    GLProfile glp = GLProfile.getDefault();

    // Set the OpenGL canvas creation parameters
    GLCapabilities caps = new GLCapabilities(glp);
    caps.setRedBits(8);
    caps.setGreenBits(8);
    caps.setBlueBits(8);
    caps.setDepthBits(32);

    final SculptScene scene = new SculptScene();

    final Frame frame = new Frame();
    final GLCanvas canvas = new GLCanvas(caps);
    canvas.addGLEventListener(scene);

    // Add and start a display link
    final FPSAnimator animator = new FPSAnimator(canvas, 60, true);

    frame.add(canvas);
    frame.setSize(800, 800);

    GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice device = environment.getDefaultScreenDevice();
    frame.setUndecorated(true);
    device.setFullScreenWindow(frame);
    frame.setVisible(true);
    canvas.requestFocus();
    animator.start();

    // Add listener to respond to window closing
    frame.addWindowListener(
        new WindowAdapter() {
          @Override
          public void windowClosing(WindowEvent e) {
            super.windowClosing(e);
            exit(0);
          }
        });

    // Add key listener
    canvas.addKeyListener(
        new KeyAdapter() {
          @Override
          public void keyPressed(KeyEvent event) {
            switch (event.getKeyCode()) {
              case KeyEvent.VK_ESCAPE:
                exit(0);
                break;
              case KeyEvent.VK_SPACE:
                dump = true;
                break;
              case 'R':
                if (depthRecord == null) {
                  try {
                    String file = new Date().getTime() + ".raw.gz";
                    depthRecord = new KinectDepthRecord(file);
                    System.out.println("Recording started to " + file);
                  } catch (Exception e) {
                    e.printStackTrace();
                  }
                } else {
                  depthRecord.close();
                  depthRecord = null;
                  System.out.println("Recording stopped");
                }
                break;
              case KeyEvent.VK_LEFT:
                scene.modifyModelRotationY(-1.0f);
                break;
              case KeyEvent.VK_RIGHT:
                scene.modifyModelRotationY(1.0f);
                break;
              case KeyEvent.VK_UP:
                scene.modifyModelRotationX(1.0f);
                break;
              case KeyEvent.VK_DOWN:
                scene.modifyModelRotationX(-1.0f);
                break;
              case 'O':
                scene.removeRandomSphere();
                break;
              case 'K':
                scene.resetModel();
                break;
              case 'F':
                GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment();
                GraphicsDevice device = environment.getDefaultScreenDevice();
                if (device.getFullScreenWindow() != null) {
                  device.setFullScreenWindow(null);
                  frame.dispose();
                  frame.setUndecorated(false);
                  frame.setVisible(true);
                } else {
                  frame.dispose();
                  frame.setUndecorated(true);
                  device.setFullScreenWindow(frame);
                }
                canvas.requestFocus();
                break;
              case 'T':
                scene.toggleTurningMode();
                break;
              case 'I':
                insertKinectPlaceholder(scene);
                break;
              case 'M':
                scene.toggleRenderMode();
                break;
              case 'D':
                scene.dumpMesh();
                break;
            }
          }
        });

    // Create mouse listener
    MouseAdapter mouseAdapter =
        new MouseAdapter() {
          int prevX, prevY;

          @Override
          public void mousePressed(MouseEvent e) {
            prevX = e.getX();
            prevY = e.getY();
          }

          @Override
          public void mouseDragged(MouseEvent e) {
            scene.mouseDragged(prevX, prevY, e.getX(), e.getY());
            prevX = e.getX();
            prevY = e.getY();
          }
        };

    // Add the mouse listener
    canvas.addMouseMotionListener(mouseAdapter);
    canvas.addMouseListener(mouseAdapter);

    if (kinect != null) {
      kinect.setDepthFormat(DepthFormat.D10BIT);
      kinect.startDepth(
          new DepthHandler() {
            @Override
            public void onFrameReceived(FrameMode arg0, ByteBuffer arg1, int arg2) {
              if (dump) {
                // Dump a raw depth image
                arg1.rewind();
                FileOutputStream fos = null;
                try {
                  fos = new FileOutputStream(new Date().getTime() + ".raw");
                  while (arg1.remaining() > 0) {
                    fos.write(arg1.get());
                  }
                  fos.close();
                } catch (Exception e) {
                  e.printStackTrace();
                }
                dump = false;
              }

              scene.updateKinect(arg1);

              if (depthRecord != null) {
                try {
                  depthRecord.addFrame(arg1);
                } catch (Exception e) {
                  e.printStackTrace();
                }
              }
            }
          });
    } else {
      insertKinectPlaceholder(scene);
    }

    // Set up Playstation 2 controller
    Joystick joystick = JoystickManager.getJoystick(Controller.Type.STICK);
    if (joystick != null) {
      joystick.setJoystickListener(scene);
    }
  }