예제 #1
0
 public boolean isStopped() {
   if (animator != null) {
     return !animator.isAnimating();
   } else {
     return true;
   }
 }
  @Override
  public void display(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();
    gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // GL_DEPTH_BUFFER_BITを追加
    gl.glLoadIdentity();

    // 視点位置と視線方向
    glu.gluLookAt(3.0f, 4.0f, 5.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);

    // 光源の位置設定
    //		gl.glLightfv(GL_LIGHT0, GL_POSITION, light0pos, 0);
    //		gl.glLightfv(GL_LIGHT1, GL_POSITION, light1pos, 0);

    // 図形の回転
    gl.glTranslatef(0.5f, 0.5f, 0.5f);
    gl.glRotatef(r, 0.0f, 1.0f, 0.0f);
    gl.glTranslatef(-0.5f, -0.5f, -0.5f);
    // 図形の色 (赤)
    //		gl.glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, red, 0);//追加
    //		gl.glColor3f(0.0f, 0.0f, 0.0f);

    // 図形の描画
    gl.glBegin(GL_QUADS);
    for (int j = 0; j < 6; ++j) {
      //			gl.glColor3fv(color[j], 0); //追加
      //			gl.glNormal3fv(normal[j], 0);
      for (int i = 0; i < 4; ++i) {
        gl.glNormal3fv(vertex[face[j][i]], 0);
        gl.glVertex3fv(vertex[face[j][i]], 0);
      }
    }
    gl.glEnd();

    // 一周回ったら回転角を 0 に戻す
    if (r++ >= 360.0f) r = 0;
    System.out.println("anim:" + animator.isAnimating() + ", r:" + r);
    if (willAnimatorPause) {
      animator.pause();
      System.out.println("animoator paused:");
      willAnimatorPause = false;
    }
  }
예제 #3
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]);
    }
  }