Exemplo n.º 1
0
 @Override
 protected GLJPanel createDrawable() {
   GLCapabilities caps = new GLCapabilities(null);
   //
   GLJPanel panel = new GLJPanel(caps);
   panel.addGLEventListener(this);
   panel.addKeyListener(this);
   return panel;
 }
Exemplo n.º 2
0
  protected GLJPanel newGLJPanel(
      final JFrame frame,
      final GLCapabilities caps,
      final FPSAnimator animator,
      final SnapshotGLEventListener snap)
      throws AWTException, InterruptedException, InvocationTargetException {
    final GLJPanel glJPanel = new GLJPanel(caps);
    Assert.assertNotNull(glJPanel);
    glJPanel.setSkipGLOrientationVerticalFlip(skipGLOrientationVerticalFlip);
    glJPanel.setMinimumSize(wsize);
    glJPanel.setPreferredSize(wsize);
    glJPanel.setSize(wsize);
    glJPanel.setSurfaceScale(reqSurfacePixelScale);
    {
      final GLEventListener demo = createDemo(caps);
      if (null != demo) {
        glJPanel.addGLEventListener(demo);
      }
    }
    if (null != snap) {
      glJPanel.addGLEventListener(snap);
    }
    glJPanel.addGLEventListener(
        new GLEventListener() {
          @Override
          public void init(final GLAutoDrawable drawable) {}

          @Override
          public void dispose(final GLAutoDrawable drawable) {}

          @Override
          public void display(final GLAutoDrawable drawable) {}

          @Override
          public void reshape(
              final GLAutoDrawable drawable,
              final int x,
              final int y,
              final int width,
              final int height) {
            setTitle(frame, glJPanel, caps);
          }
        });
    setTitle(frame, glJPanel, caps);

    frame.addComponentListener(
        new ComponentListener() {
          @Override
          public void componentResized(final ComponentEvent e) {
            setTitle(frame, glJPanel, caps);
          }

          @Override
          public void componentMoved(final ComponentEvent e) {
            setTitle(frame, glJPanel, caps);
          }

          @Override
          public void componentShown(final ComponentEvent e) {}

          @Override
          public void componentHidden(final ComponentEvent e) {}
        });

    if (SwingUtilities.isEventDispatchThread()) {
      frame.getContentPane().add(glJPanel, BorderLayout.CENTER);
      frame.getContentPane().validate();
      frame.pack();
      frame.setVisible(true);
    } else {
      SwingUtilities.invokeAndWait(
          new Runnable() {
            public void run() {
              frame.getContentPane().add(glJPanel, BorderLayout.CENTER);
              frame.getContentPane().validate();
              frame.pack();
              frame.setVisible(true);
            }
          });
      Assert.assertEquals(true, AWTRobotUtil.waitForVisible(frame, true));
      Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glJPanel, true));

      final float[] minSurfacePixelScale = glJPanel.getMinimumSurfaceScale(new float[2]);
      final float[] maxSurfacePixelScale = glJPanel.getMaximumSurfaceScale(new float[2]);
      final float[] valReqSurfacePixelScale = glJPanel.getRequestedSurfaceScale(new float[2]);
      final float[] hasSurfacePixelScale = glJPanel.getCurrentSurfaceScale(new float[2]);
      System.err.println(
          "HiDPI PixelScale: min "
              + minSurfacePixelScale[0]
              + "x"
              + minSurfacePixelScale[1]
              + ", max "
              + maxSurfacePixelScale[0]
              + "x"
              + maxSurfacePixelScale[1]
              + ", req "
              + reqSurfacePixelScale[0]
              + "x"
              + reqSurfacePixelScale[1]
              + " -> val "
              + valReqSurfacePixelScale[0]
              + "x"
              + valReqSurfacePixelScale[1]
              + " -> has "
              + hasSurfacePixelScale[0]
              + "x"
              + hasSurfacePixelScale[1]);
      setTitle(frame, glJPanel, caps);
    }

    if (null != animator) {
      animator.add(glJPanel);
      animator.setUpdateFPSFrames(60, System.err);
    }
    return glJPanel;
  }