Exemplo n.º 1
0
 public GameMenu(String title, int width, int height, int FPS) {
   fPS = FPS;
   frame = new JFrame(title);
   canvas = new DrawMenu();
   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   // Create the OpenGL rendering canvas
   canvas.setPreferredSize(new Dimension(width, height));
   canvas.addMouseListener(new SelectMenuListener());
   canvas.addMouseMotionListener(new MotionListener());
   frame.getContentPane().add(canvas);
   frame.pack();
 }
  public SwingScilabCanvasImpl(GLCapabilities cap) {
    if (enableGLCanvas) {
      Debug.DEBUG(this.getClass().getSimpleName(), "Using GLCanvas for OpenGL implementation.");
      realGLCanvas = new GLCanvas(cap);
      realGLCanvas.addMouseMotionListener(
          new MouseMotionListener() {
            public void mouseDragged(MouseEvent arg0) {
              arg0.setSource(realGLCanvas.getParent());
              realGLCanvas.getParent().dispatchEvent(arg0);
            }

            public void mouseMoved(MouseEvent arg0) {
              arg0.setSource(realGLCanvas.getParent());
              realGLCanvas.getParent().dispatchEvent(arg0);
            }
          });
      realGLCanvas.addMouseListener(
          new MouseListener() {
            public void mouseClicked(MouseEvent arg0) {
              arg0.setSource(realGLCanvas.getParent());
              realGLCanvas.getParent().dispatchEvent(arg0);
            }

            public void mouseEntered(MouseEvent arg0) {
              arg0.setSource(realGLCanvas.getParent());
              realGLCanvas.getParent().dispatchEvent(arg0);
            }

            public void mouseExited(MouseEvent arg0) {
              arg0.setSource(realGLCanvas.getParent());
              realGLCanvas.getParent().dispatchEvent(arg0);
            }

            public void mousePressed(MouseEvent arg0) {
              arg0.setSource(realGLCanvas.getParent());
              realGLCanvas.getParent().dispatchEvent(arg0);
            }

            public void mouseReleased(MouseEvent arg0) {
              arg0.setSource(realGLCanvas.getParent());
              realGLCanvas.getParent().dispatchEvent(arg0);
            }
          });
    } else {
      Debug.DEBUG(this.getClass().getSimpleName(), "Using GLJPanel for OpenGL implementation.");
      realGLJPanel = new GLJPanel(cap);
    }
  }
Exemplo n.º 3
0
  public static void main(String[] args) {
    // set argument 'NotFirstUIActionOnProcess' in the JNLP's application-desc tag for example
    // <application-desc main-class="demos.j2d.TextCube"/>
    //   <argument>NotFirstUIActionOnProcess</argument>
    // </application-desc>
    boolean firstUIActionOnProcess =
        0 == args.length || !args[0].equals("NotFirstUIActionOnProcess");
    GLProfile.initSingleton(firstUIActionOnProcess);

    GLCapabilities caps = new GLCapabilities(null);
    GLCanvas canvas = new GLCanvas(caps);

    FBCubes cubes = new FBCubes();
    canvas.addMouseListener(cubes);
    canvas.addMouseMotionListener(cubes);
    canvas.addGLEventListener(cubes);

    Frame frame = new Frame("FBCubes Demo ES 1.1");
    frame.add(canvas);
    frame.setSize(800, 480);

    final GLAnimatorControl animator = new FPSAnimator(canvas, 60);
    frame.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            // Run this on another thread than the AWT event queue to
            // make sure the call to Animator.stop() completes before
            // exiting
            new Thread(
                    new Runnable() {
                      public void run() {
                        animator.stop();
                        System.exit(0);
                      }
                    })
                .start();
          }
        });

    frame.setVisible(true);
    animator.start();
  }
Exemplo n.º 4
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);
    }
  }