Esempio n. 1
0
  public Janela(int width, int height, GLCanvas canvas) throws IOException {
    animator = new FPSAnimator(canvas, 240);
    setSize(new Dimension(width, height));
    setLocationRelativeTo(null);
    setMinimumSize(getSize());
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout());
    panel.add(canvas, BorderLayout.CENTER);
    getContentPane().add(panel);
    canvas.addGLEventListener(new GLWindow(panel, canvas));
    addWindowListener(
        new WindowAdapter() {

          @Override
          public void windowClosing(WindowEvent e) {
            super.windowClosing(
                e); // To change body of generated methods, choose Tools | Templates.
            animator.stop();
            System.out.println("Animação parou!");
          }
        });
    setExtendedState(JFrame.MAXIMIZED_BOTH);
    setVisible(true);
    JDInfo info = new JDInfo(this, true);
    info.setVisible(true);
    animator.start();
    clip = Applet.newAudioClip(new File("./resources/Cabin.wav").toURL());
    clip.loop();
  }
  /** KeyListener method. */
  @Override
  public void keyPressed(KeyEvent ke) {
    animator.start();
    int DELTA_SIZE = 1;

    switch (ke.getKeyCode()) {
      case KeyEvent.VK_UP:
        gcodeRenderer.pan(0, DELTA_SIZE);
        // this.eye.y+=DELTA_SIZE;
        break;
      case KeyEvent.VK_DOWN:
        gcodeRenderer.pan(0, -DELTA_SIZE);
        break;
      case KeyEvent.VK_LEFT:
        gcodeRenderer.pan(-DELTA_SIZE, 0);
        break;
      case KeyEvent.VK_RIGHT:
        gcodeRenderer.pan(DELTA_SIZE, 0);
        break;
      case KeyEvent.VK_MINUS:
        if (ke.isControlDown()) gcodeRenderer.zoom(-1);
        break;
      case KeyEvent.VK_0:
      case KeyEvent.VK_ESCAPE:
        gcodeRenderer.resetView();
        break;
    }

    switch (ke.getKeyChar()) {
      case '+':
        if (ke.isControlDown()) gcodeRenderer.zoom(1);
        break;
    }
  }
Esempio n. 3
0
  private void initUI() {
    setTitle("pfps");
    setSize(800, 600);
    setLocationRelativeTo(null);
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    glcanvas_ = new GLCanvas(glcap_);
    glcanvas_.addGLEventListener(this);
    this.getContentPane().add(glcanvas_, BorderLayout.CENTER);
    animator_ = new FPSAnimator(glcanvas_, 60);
    animator_.start();
    glcanvas_.addKeyListener(input_);
    glcanvas_.addMouseMotionListener(input_);

    moveTimer_ =
        new Timer(
            MOVE_TIMER_FREQ,
            new ActionListener() {
              @Override
              public void actionPerformed(ActionEvent e) {
                onMoveTimer();
              }
            });
    moveTimer_.start();

    this.addWindowListener(
        new WindowAdapter() {
          @Override
          public void windowOpened(WindowEvent e) {
            MyFrame.this.windowOpened(e);
          }
        });
  }
Esempio n. 4
0
  /** The entry main() method */
  public static void main(String[] args) {
    // Create the OpenGL rendering canvas
    GLCanvas canvas = new GLCanvas(); // heavy-weight GLCanvas
    canvas.setPreferredSize(new Dimension(CANVAS_WIDTH, CANVAS_HEIGHT));
    canvas.addGLEventListener(new JOGL2Nehe11Flag());

    // Create a animator that drives canvas' display() at the specified FPS.
    final FPSAnimator animator = new FPSAnimator(canvas, FPS, true);

    // Create the top-level container frame
    final JFrame frame = new JFrame(); // Swing's JFrame or AWT's Frame
    frame.getContentPane().add(canvas);
    frame.addWindowListener(
        new WindowAdapter() {
          @Override
          public void windowClosing(WindowEvent e) {
            // Use a dedicate thread to run the stop() to ensure that the
            // animator stops before program exits.
            new Thread() {
              @Override
              public void run() {
                animator.stop(); // stop the animator loop
                System.exit(0);
              }
            }.start();
          }
        });
    frame.setTitle(TITLE);
    frame.pack();
    frame.setVisible(true);
    animator.start(); // start the animation loop
  }
Esempio n. 5
0
 private void run() {
   setSize(800, 800);
   setLocationRelativeTo(null);
   setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   setVisible(true);
   animator.start();
 }
  private void initPanels(GLCapabilities caps) {
    // create panels to draw on
    myPanels = new GLJPanel[3];
    myPanels[0] = new GLJPanel(caps);
    myPanels[1] = new GLJPanel(caps);
    myPanels[2] = new GLJPanel(caps);

    setLayout(new GridLayout(1, 3));
    add(myPanels[0]);
    add(myPanels[1]);
    add(myPanels[2]);

    // The cross section view
    CrossSectionView view0 = new CrossSectionView(this);
    myPanels[0].addGLEventListener(view0);

    // the spine view
    SpineView view1 = new SpineView(this);
    myPanels[1].addGLEventListener(view1);
    myPanels[1].addMouseMotionListener(view1);

    // the extrusion view
    ExtrusionView view2 = new ExtrusionView(this);
    myPanels[2].addGLEventListener(view2);
    myPanels[2].addMouseMotionListener(view2);

    FPSAnimator animator = new FPSAnimator(60);
    animator.add(myPanels[0]);
    animator.add(myPanels[1]);
    animator.add(myPanels[2]);
    animator.start();
  }
Esempio n. 7
0
 public static FPSAnimator startFpsAnimator(int fps, GlimpseCanvas... canvases) {
   FPSAnimator animator = new FPSAnimator(fps);
   for (GlimpseCanvas canvas : canvases) {
     animator.add(canvas.getGLDrawable());
   }
   animator.start();
   return animator;
 }
Esempio n. 8
0
 public void setFrameRate(float fps) {
   if (animator != null) {
     animator.stop();
     animator.setFPS((int) fps);
     pgl.setFps(fps);
     animator.start();
   }
 }
Esempio n. 9
0
  @Override
  public void init(GLAutoDrawable drawable) {
    super.init(drawable);
    GL3 gl = drawable.getGL().getGL3();
    gl.glClearColor(1, 1, 1, 1); // Hintergrundfarbe (RGBA)

    fpsAnimator = new FPSAnimator(drawable, 60, true);
    fpsAnimator.start();
  }
 /**
  * Mouse pressed is called on mouse-down. Mouse released and mouse clicked are called on mouse-up.
  */
 @Override
 public void mousePressed(MouseEvent e) {
   // Zoom
   if (e.getButton() == MouseEvent.BUTTON1 && e.isMetaDown()) {
     selecting = true;
     selectionStart = gcodeRenderer.getMouseWorldLocation();
     selection.setStart(selectionStart);
   } else {
     animator.start();
   }
 }
 public FirstStepNewtLast() {
   GLCapabilities caps = new GLCapabilities(GLProfile.get(GLProfile.GL2));
   GLWindow glWindow = GLWindow.create(caps);
   glWindow.setTitle("First demo (Newt)");
   glWindow.setSize(300, 300);
   glWindow.addWindowListener(
       new WindowAdapter() {
         @Override
         public void windowDestroyed(WindowEvent arg0) {
           System.exit(0);
         }
       });
   glWindow.addGLEventListener(this);
   FPSAnimator animator = new FPSAnimator(10); // (2)
   animator.add(glWindow);
   animator.start();
   glWindow.setVisible(true);
 }
Esempio n. 12
0
  public static void main(String[] args) {
    GLProfile glp = GLProfile.getDefault();
    GLCapabilities caps = new GLCapabilities(glp);
    GLCanvas canvas = new GLCanvas(caps);
    cube unCube = new cube();
    canvas.addGLEventListener(unCube);
    Frame frame = new Frame("AWT Window Test");
    FPSAnimator anim = new FPSAnimator(canvas, 60);
    anim.start();
    frame.setSize(400, 400);
    frame.add(canvas);
    frame.setVisible(true);

    frame.addKeyListener(
        new KeyListener() {

          @Override
          public void keyPressed(KeyEvent e) {
            // TODO Auto-generated method stub
            int keyCode = e.getKeyCode();
            unCube.handleKeyPress(keyCode); // Here is the handleKeyPress function's call
            frame.add(canvas);
          }

          @Override
          public void keyReleased(KeyEvent e) {
            // TODO Auto-generated method stub

          }

          @Override
          public void keyTyped(KeyEvent e) {
            // TODO Auto-generated method stub

          }
        });

    frame.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            System.exit(0);
          }
        });
  }
Esempio n. 13
0
 public void startThread() {
   if (animator != null) {
     if (placedWindow) {
       window.setVisible(true);
       animator.start();
       requestedStart = false;
     } else {
       // The GL window is not visible until it has been placed, so we cannot
       // start the animator because it requires the window to be visible.
       requestedStart = true;
       // Need this assignment to bypass the while loop in runSketch, otherwise
       // the programs hangs waiting for defaultSize to be false, but it never
       // happens because the animation thread is not yet running to avoid showing
       // the window in the wrong place:
       // https://github.com/processing/processing/issues/3308
       //      sketch.defaultSize = false;
     }
   }
 }
 public CubeSample6InvalidNormal() {
   GLCapabilities caps = new GLCapabilities(GLProfile.get(GLProfile.GL2));
   glu = new GLU();
   GLWindow glWindow = GLWindow.create(caps);
   glWindow.setTitle("Cube demo (Newt)");
   glWindow.setSize(300, 300);
   glWindow.addWindowListener(
       new WindowAdapter() {
         @Override
         public void windowDestroyed(WindowEvent arg0) {
           System.exit(0);
         }
       });
   glWindow.addGLEventListener(this);
   glWindow.addMouseListener(this);
   animator = new FPSAnimator(30);
   animator.add(glWindow);
   animator.start();
   animator.pause();
   glWindow.setVisible(true);
 }
  private void initPanels(GLCapabilities caps) {
    // create a panel to draw on
    myPanels = new GLJPanel[1];
    myPanels[0] = new GLJPanel(caps);

    // create a panel of sliders
    JPanel panel = initSliders();

    setLayout(new GridLayout(1, 2));
    add(myPanels[0]);
    add(panel);

    TextureView view1 = new TextureView(this);
    myPanels[0].addGLEventListener(view1);
    myPanels[0].addMouseMotionListener(view1);
    myPanels[0].addKeyListener(this);
    myPanels[0].setFocusable(true);

    FPSAnimator animator = new FPSAnimator(60);
    animator.add(myPanels[0]);
    animator.start();
  }
Esempio n. 16
0
  public Engine(GLCanvas canvas) {
    frame = new Frame("TRIPPIN' BALLS");
    frame.add(canvas);
    frame.setSize(600, 600);
    if (fullscreen) frame.setUndecorated(true);
    frame.setVisible(true);

    if (fullscreen) {
      GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
      ge.getDefaultScreenDevice().setFullScreenWindow(frame);
    }

    input = new Input();
    frame.addWindowListener(input);
    canvas.addKeyListener(input);
    canvas.addMouseListener(input);
    canvas.addMouseWheelListener(input);
    canvas.addFocusListener(input);

    animator = new FPSAnimator(canvas, 60);
    animator.add(canvas);
    animator.start();
    animator.getTotalFrames();
  }
Esempio n. 17
0
  public void run() {

    // Create a animator that drives canvas' display() at the specified FPS.
    final FPSAnimator animator = new FPSAnimator(canvas, fPS, true);

    // Create the top-level container
    frame.addWindowListener(
        new WindowAdapter() {
          @Override
          public void windowClosing(WindowEvent e) {
            // Use a dedicate thread to run the stop() to ensure that the
            // animator stops before program exits.
            new Thread() {
              @Override
              public void run() {
                if (animator.isStarted()) animator.stop();
                System.exit(0);
              }
            }.start();
          }
        });
    frame.setVisible(true);
    animator.start();
  }
Esempio n. 18
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);
    }
  }
Esempio n. 19
0
  public static void main(String _args[]) {

    final NBodyKernel kernel =
        new NBodyKernel(Range.create(Integer.getInteger("bodies", 8192), 256));

    final JFrame frame = new JFrame("NBody");

    final JPanel panel = new JPanel(new BorderLayout());
    final JPanel controlPanel = new JPanel(new FlowLayout());
    panel.add(controlPanel, BorderLayout.SOUTH);

    final JButton startButton = new JButton("Start");

    startButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            running = true;
            startButton.setEnabled(false);
          }
        });
    controlPanel.add(startButton);
    controlPanel.add(new JLabel(kernel.getExecutionMode().toString()));

    controlPanel.add(new JLabel("   Particles"));
    controlPanel.add(new JTextField("" + kernel.range.getGlobalSize(0), 5));

    controlPanel.add(new JLabel("FPS"));
    final JTextField framesPerSecondTextField = new JTextField("0", 5);

    controlPanel.add(framesPerSecondTextField);
    controlPanel.add(new JLabel("Score("));
    final JLabel miniLabel =
        new JLabel("<html><small>calcs</small><hr/><small>&micro;sec</small></html>");

    controlPanel.add(miniLabel);
    controlPanel.add(new JLabel(")"));

    final JTextField positionUpdatesPerMicroSecondTextField = new JTextField("0", 5);

    controlPanel.add(positionUpdatesPerMicroSecondTextField);
    final GLCapabilities caps = new GLCapabilities(null);
    caps.setDoubleBuffered(true);
    caps.setHardwareAccelerated(true);
    final GLCanvas canvas = new GLCanvas(caps);
    final Dimension dimension =
        new Dimension(Integer.getInteger("width", 742), Integer.getInteger("height", 742));
    canvas.setPreferredSize(dimension);

    canvas.addGLEventListener(
        new GLEventListener() {
          private double ratio;

          private final float xeye = 0f;

          private final float yeye = 0f;

          private final float zeye = 100f;

          private final float xat = 0f;

          private final float yat = 0f;

          private final float zat = 0f;

          public final float zoomFactor = 1.0f;

          private int frames;

          private long last = System.currentTimeMillis();

          @Override
          public void dispose(GLAutoDrawable drawable) {}

          @Override
          public void display(GLAutoDrawable drawable) {

            final GL2 gl = drawable.getGL().getGL2();

            gl.glLoadIdentity();
            gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
            gl.glColor3f(1f, 1f, 1f);

            final GLU glu = new GLU();
            glu.gluPerspective(45f, ratio, 0f, 1000f);

            glu.gluLookAt(xeye, yeye, zeye * zoomFactor, xat, yat, zat, 0f, 1f, 0f);
            if (running) {
              kernel.execute(kernel.range);
              if (kernel.isExplicit()) {
                kernel.get(kernel.xyz);
              }
              final List<ProfileInfo> profileInfo = kernel.getProfileInfo();
              if ((profileInfo != null) && (profileInfo.size() > 0)) {
                for (final ProfileInfo p : profileInfo) {
                  System.out.print(
                      " "
                          + p.getType()
                          + " "
                          + p.getLabel()
                          + ((p.getEnd() - p.getStart()) / 1000)
                          + "us");
                }
                System.out.println();
              }
            }
            kernel.render(gl);

            final long now = System.currentTimeMillis();
            final long time = now - last;
            frames++;

            if (time > 1000) { // We update the frames/sec every second
              if (running) {
                final float framesPerSecond = (frames * 1000.0f) / time;
                final int updatesPerMicroSecond =
                    (int)
                        ((framesPerSecond
                                * kernel.range.getGlobalSize(0)
                                * kernel.range.getGlobalSize(0))
                            / 1000000);
                framesPerSecondTextField.setText(String.format("%5.2f", framesPerSecond));
                positionUpdatesPerMicroSecondTextField.setText(
                    String.format("%4d", updatesPerMicroSecond));
              }
              frames = 0;
              last = now;
            }
            gl.glFlush();
          }

          @Override
          public void init(GLAutoDrawable drawable) {
            final GL2 gl = drawable.getGL().getGL2();

            gl.glShadeModel(GLLightingFunc.GL_SMOOTH);
            gl.glEnable(GL.GL_BLEND);
            gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE);
            try {
              final InputStream textureStream = Local.class.getResourceAsStream("particle.jpg");
              final Texture texture = TextureIO.newTexture(textureStream, false, null);
              texture.enable(gl);
            } catch (final IOException e) {
              e.printStackTrace();
            } catch (final GLException e) {
              e.printStackTrace();
            }
          }

          @Override
          public void reshape(GLAutoDrawable drawable, int x, int y, int _width, int _height) {
            width = _width;
            height = _height;

            final GL2 gl = drawable.getGL().getGL2();
            gl.glViewport(0, 0, width, height);

            ratio = (double) width / (double) height;
          }
        });

    panel.add(canvas, BorderLayout.CENTER);
    frame.getContentPane().add(panel, BorderLayout.CENTER);

    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    frame.pack();
    frame.setVisible(true);

    final FPSAnimator animator = new FPSAnimator(canvas, 100);
    animator.start();
  }
Esempio n. 20
0
  protected void runTestGL(final GLCapabilities caps)
      throws AWTException, InterruptedException, InvocationTargetException {
    final JFrame frame = new JFrame("Swing GLJPanel");
    frame.setLocation(xpos, ypos);
    Assert.assertNotNull(frame);

    final FPSAnimator animator = useAnimator ? new FPSAnimator(60) : null;
    final SnapshotGLEventListener snap = new SnapshotGLEventListener();
    final GLJPanel glJPanel = newGLJPanel(frame, caps, animator, snap);
    if (null != animator) {
      animator.start();
      Assert.assertEquals(true, animator.isAnimating());
    }
    final Screen screen = NewtFactoryAWT.createScreen(glJPanel, true);
    screen.addReference(); // initial native creation - keep alive!
    System.err.println("GetPixelScale: AWT -> Screen: " + screen);

    final QuitAdapter quitAdapter = new QuitAdapter();
    new AWTKeyAdapter(new TraceKeyAdapter(quitAdapter), glJPanel).addTo(glJPanel);
    new AWTWindowAdapter(new TraceWindowAdapter(quitAdapter), glJPanel).addTo(frame);

    final JFrame[] frame2 = {null};
    final GLJPanel[] glJPanel2 = {null};

    final com.jogamp.newt.event.KeyListener kl =
        new com.jogamp.newt.event.KeyAdapter() {
          @Override
          public void keyPressed(final KeyEvent e) {
            if (e.isAutoRepeat()) {
              return;
            }
            if (e.getKeySymbol() == KeyEvent.VK_P) {
              System.err.println();
              {
                // Just for manual validation!
                final java.awt.Point los = glJPanel.getLocationOnScreen();
                final RectangleImmutable r =
                    new Rectangle(los.x, los.y, glJPanel.getWidth(), glJPanel.getHeight());
                System.err.printf("GetPixelScale: Panel Bounds: %s window-units%n", r.toString());
                System.err.printf(
                    "GetPixelScale: Panel Resolution: %d x %d pixel-units%n",
                    glJPanel.getSurfaceWidth(), glJPanel.getSurfaceHeight());
              }
              final MonitorDevice monitor = NewtFactoryAWT.getMonitorDevice(screen, glJPanel);
              System.err.printf("GetPixelScale: %s%n", monitor.toString());
              final float[] pixelPerMM;
              final boolean cached;
              if (e.isShiftDown()) {
                // SHIFT: query current mode!
                pixelPerMM = monitor.getPixelsPerMM(monitor.queryCurrentMode(), new float[2]);
                cached = false;
              } else {
                // Default: Use cached mode!
                pixelPerMM = monitor.getPixelsPerMM(new float[2]);
                cached = true;
              }
              System.err.println(
                  "  pixel/mm ["
                      + pixelPerMM[0]
                      + ", "
                      + pixelPerMM[1]
                      + "], cached-mode "
                      + cached);
              System.err.println(
                  "  pixel/in ["
                      + pixelPerMM[0] * 25.4f
                      + ", "
                      + pixelPerMM[1] * 25.4f
                      + "], cached-mode "
                      + cached);
              System.err.println();
            } else if (e.getKeyChar() == 'x') {
              final float[] hadSurfacePixelScale = glJPanel.getCurrentSurfaceScale(new float[2]);
              final float[] reqSurfacePixelScale;
              if (hadSurfacePixelScale[0] == ScalableSurface.IDENTITY_PIXELSCALE) {
                reqSurfacePixelScale =
                    new float[] {
                      ScalableSurface.AUTOMAX_PIXELSCALE, ScalableSurface.AUTOMAX_PIXELSCALE
                    };
              } else {
                reqSurfacePixelScale =
                    new float[] {
                      ScalableSurface.IDENTITY_PIXELSCALE, ScalableSurface.IDENTITY_PIXELSCALE
                    };
              }
              System.err.println(
                  "[set PixelScale pre]: had "
                      + hadSurfacePixelScale[0]
                      + "x"
                      + hadSurfacePixelScale[1]
                      + " -> req "
                      + reqSurfacePixelScale[0]
                      + "x"
                      + reqSurfacePixelScale[1]);
              glJPanel.setSurfaceScale(reqSurfacePixelScale);
              final float[] valReqSurfacePixelScale =
                  glJPanel.getRequestedSurfaceScale(new float[2]);
              final float[] hasSurfacePixelScale1 = glJPanel.getCurrentSurfaceScale(new float[2]);
              System.err.println(
                  "[set PixelScale post]: "
                      + hadSurfacePixelScale[0]
                      + "x"
                      + hadSurfacePixelScale[1]
                      + " (had) -> "
                      + reqSurfacePixelScale[0]
                      + "x"
                      + reqSurfacePixelScale[1]
                      + " (req) -> "
                      + valReqSurfacePixelScale[0]
                      + "x"
                      + valReqSurfacePixelScale[1]
                      + " (val) -> "
                      + hasSurfacePixelScale1[0]
                      + "x"
                      + hasSurfacePixelScale1[1]
                      + " (has)");
              setTitle(frame, glJPanel, caps);
            } else if (e.getKeyChar() == 'm') {
              final GLCapabilitiesImmutable capsPre = glJPanel.getChosenGLCapabilities();
              final GLCapabilities capsNew = new GLCapabilities(capsPre.getGLProfile());
              capsNew.copyFrom(capsPre);
              final boolean msaa;
              if (capsPre.getSampleBuffers()) {
                capsNew.setSampleBuffers(false);
                msaa = false;
              } else {
                capsNew.setSampleBuffers(true);
                capsNew.setNumSamples(4);
                msaa = true;
              }
              System.err.println("[set MSAA " + msaa + " Caps had]: " + capsPre);
              System.err.println("[set MSAA " + msaa + " Caps new]: " + capsNew);
              System.err.println("XXX-A1: " + animator.toString());
              glJPanel.setRequestedGLCapabilities(capsNew);
              System.err.println("XXX-A2: " + animator.toString());
              System.err.println("XXX: " + glJPanel.toString());
            } else if (e.getKeyChar() == 'n') {
              System.err.println("XXX: frame2: " + frame2[0]);
              if (null != frame2[0]) {
                System.err.println("XXX: frame2.isShowing: " + frame2[0].isShowing());
              }
              System.err.println("XXX: glJPanel2: " + glJPanel2[0]);
              if (null != frame2[0] && frame2[0].isShowing()) {
                destroy(frame2[0], glJPanel2[0]);
                frame2[0] = null;
                glJPanel2[0] = null;
              } else {
                frame2[0] = new JFrame("GLJPanel2");
                frame2[0].setLocation(frame.getX() + frame.getWidth() + 64, frame.getY());
                final FPSAnimator animator2 = useAnimator ? new FPSAnimator(60) : null;
                if (null != animator2) {
                  animator2.start();
                }
                final SnapshotGLEventListener snap2 = new SnapshotGLEventListener();
                try {
                  glJPanel2[0] = newGLJPanel(frame2[0], caps, animator2, snap2);
                } catch (final Exception e2) {
                  e2.printStackTrace();
                  destroy(frame2[0], glJPanel2[0]);
                  frame2[0] = null;
                  glJPanel2[0] = null;
                }
              }
            }
          }
        };
    new AWTKeyAdapter(kl, glJPanel).addTo(glJPanel);

    snap.setMakeSnapshot();

    if (null != rwsize) {
      Thread.sleep(500); // 500ms delay
      setFrameSize(frame, true, rwsize);
      System.err.println(
          "window resize pos/siz: "
              + glJPanel.getX()
              + "/"
              + glJPanel.getY()
              + " "
              + glJPanel.getSurfaceWidth()
              + "x"
              + glJPanel.getSurfaceHeight());
    }

    snap.setMakeSnapshot();

    final long t0 = System.currentTimeMillis();
    long t1 = t0;
    boolean triggerSnap = false;
    while (!quitAdapter.shouldQuit() && t1 - t0 < duration) {
      Thread.sleep(100);
      t1 = System.currentTimeMillis();
      snap.getDisplayCount();
      if (!triggerSnap && snap.getDisplayCount() > 1) {
        // Snapshot only after one frame has been rendered to suite FBO MSAA!
        snap.setMakeSnapshot();
        triggerSnap = true;
      }
    }

    Assert.assertNotNull(frame);
    Assert.assertNotNull(glJPanel);

    if (useAnimator) {
      Assert.assertNotNull(animator);
      animator.stop();
      Assert.assertEquals(false, animator.isAnimating());
    } else {
      Assert.assertNull(animator);
    }

    screen.removeReference(); // final native destroy
    destroy(frame, glJPanel);
    if (null != frame2[0]) {
      destroy(frame2[0], glJPanel2[0]);
    }
  }