public static void main(String[] args) {
    // Initialization
    // Setting up GL
    GLProfile.initSingleton();
    GLProfile glp = GLProfile.getDefault();
    GLCapabilities caps = new GLCapabilities(glp);
    GLCanvas canvas = new GLCanvas(caps);

    // Making the AWT frame window
    Frame frame = new Frame("Assignment 1");
    frame.setSize(800, 600);
    frame.add(canvas);
    frame.setVisible(true);

    // Adding a render listener
    canvas.addGLEventListener(new Assignment1());

    // Fixes so the exit button exits the program
    frame.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            System.exit(0);
          }
        });
  }
  public static void main(String args[]) {

    GLProfile.initSingleton();
    SwingUtilities.invokeLater(
        new Runnable() {
          public void run() {
            (new Main()).start();
          }
        });
  }
Beispiel #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();

    Frame frame = new Frame();
    GLCanvas canvas = new GLCanvas();
    canvas.addGLEventListener(new Listener());
    frame.setUndecorated(true);
    frame.add(canvas);
    frame.setSize(1, 1);
    frame.setVisible(true);
  }
Beispiel #4
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();
  }
Beispiel #5
0
 static {
   GLProfile.initSingleton();
 }
 @BeforeClass
 public static void initClass() {
   GLProfile.initSingleton();
 }
Beispiel #7
0
 /*
  * Improves OpenGL performances.
  */
 static {
   GLProfile.initSingleton(true);
 }
Beispiel #8
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);
    }
  }