@Override
  public void onCreate(Bundle savedInstanceState) {
    Log.d(TAG, "onCreate - 0");
    super.onCreate(savedInstanceState);

    // create GLWindow (-> incl. underlying NEWT Display, Screen & Window)
    GLCapabilities caps = new GLCapabilities(GLProfile.get(GLProfile.GLES2));
    Log.d(TAG, "req caps: " + caps);
    GLWindow glWindow = GLWindow.create(caps);
    glWindow.setFullscreen(true);
    setContentView(getWindow(), glWindow);

    glWindow.addGLEventListener(new ElektronenMultiplizierer());
    glWindow
        .getScreen()
        .addMonitorModeListener(
            new MonitorModeListener() {
              @Override
              public void monitorModeChangeNotify(MonitorEvent me) {}

              @Override
              public void monitorModeChanged(MonitorEvent me, boolean success) {
                System.err.println("MonitorMode Changed (success " + success + "): " + me);
              }
            });
    glWindow.setVisible(true);
    Animator animator = new Animator(glWindow);

    animator.setUpdateFPSFrames(60, System.err);
    animator.resetFPSCounter();
    glWindow.resetFPSCounter();

    Log.d(TAG, "onCreate - X");
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    Log.d(TAG, "onCreate - 0");
    super.onCreate(savedInstanceState);

    // create GLWindow (-> incl. underlying NEWT Display, Screen & Window)
    GLCapabilities caps = new GLCapabilities(GLProfile.get(GLProfile.GLES1));
    Log.d(TAG, "req caps: " + caps);
    GLWindow glWindow = GLWindow.create(caps);
    setContentView(getWindow(), glWindow);

    glWindow.addGLEventListener(new RedSquareES1(1));
    glWindow
        .getWindow()
        .getScreen()
        .addScreenModeListener(
            new ScreenModeListener() {
              public void screenModeChangeNotify(ScreenMode sm) {}

              public void screenModeChanged(ScreenMode sm, boolean success) {
                System.err.println("ScreenMode Changed: " + sm);
              }
            });
    glWindow.setVisible(true);
    Animator animator = new Animator(glWindow);
    animator.setUpdateFPSFrames(60, System.err);
    setAnimator(animator);

    Log.d(TAG, "onCreate - X");
  }
  private void testImpl(final GLCapabilities caps, final GLEventListener glel)
      throws InterruptedException {
    final GLWindow glWindow = GLWindow.create(caps);
    Assert.assertNotNull(glWindow);
    glWindow.setSize(800, 600);
    glWindow.setVisible(true);
    glWindow.setTitle("JOGL Tessellation Shader Test");
    Assert.assertTrue(glWindow.isNativeValid());

    final QuitAdapter quitAdapter = new QuitAdapter();
    glWindow.addKeyListener(quitAdapter);
    glWindow.addWindowListener(quitAdapter);
    glWindow.addGLEventListener(glel);

    final SnapshotGLEventListener snapshotGLEventListener = new SnapshotGLEventListener();
    glWindow.addGLEventListener(snapshotGLEventListener);

    final Animator animator = new Animator(glWindow);
    animator.start();

    animator.setUpdateFPSFrames(60, System.err);
    snapshotGLEventListener.setMakeSnapshot();

    while (!quitAdapter.shouldQuit()
        && animator.isAnimating()
        && animator.getTotalFPSDuration() < duration) {
      Thread.sleep(100);
    }

    animator.stop();
    glWindow.destroy();
  }
Exemple #4
0
  protected void runTestGL(final GLCapabilities caps, final boolean forceFFPEmu)
      throws InterruptedException {
    final GLWindow glWindow = GLWindow.create(caps);
    Assert.assertNotNull(glWindow);
    glWindow.setTitle("Gears NEWT Test");

    final GearsES1 demo = new GearsES1(swapInterval);
    demo.setForceFFPEmu(forceFFPEmu, forceFFPEmu, false, false);
    glWindow.addGLEventListener(demo);
    final SnapshotGLEventListener snap = new SnapshotGLEventListener();
    glWindow.addGLEventListener(snap);

    final Animator animator = new Animator(glWindow);
    final QuitAdapter quitAdapter = new QuitAdapter();

    // glWindow.addKeyListener(new TraceKeyAdapter(quitAdapter));
    // glWindow.addWindowListener(new TraceWindowAdapter(quitAdapter));
    glWindow.addKeyListener(quitAdapter);
    glWindow.addWindowListener(quitAdapter);

    final GLWindow f_glWindow = glWindow;
    glWindow.addKeyListener(
        new KeyAdapter() {
          public void keyReleased(final KeyEvent e) {
            if (!e.isPrintableKey() || e.isAutoRepeat()) {
              return;
            }
            if (e.getKeyChar() == 'f') {
              new Thread() {
                public void run() {
                  f_glWindow.setFullscreen(!f_glWindow.isFullscreen());
                }
              }.start();
            } else if (e.getKeyChar() == 'd') {
              new Thread() {
                public void run() {
                  f_glWindow.setUndecorated(!f_glWindow.isUndecorated());
                }
              }.start();
            }
          }
        });

    glWindow.setSize(width, height);
    glWindow.setVisible(true);
    animator.setUpdateFPSFrames(1, null);
    animator.start();
    snap.setMakeSnapshot();

    while (!quitAdapter.shouldQuit()
        && animator.isAnimating()
        && animator.getTotalFPSDuration() < duration) {
      Thread.sleep(100);
    }

    animator.stop();
    glWindow.destroy();
  }
Exemple #5
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    String[] urls0 =
        new String[] {
          System.getProperty("jnlp.media0_url2"),
          System.getProperty("jnlp.media0_url1"),
          System.getProperty("jnlp.media0_url0")
        };
    final URLConnection urlConnection0 = getResource(urls0, 0);
    if (null == urlConnection0) {
      throw new RuntimeException("no media reachable: " + Arrays.asList(urls0));
    }

    // also initializes JOGL
    final GLCapabilities capsMain = new GLCapabilities(GLProfile.getGL2ES2());
    capsMain.setBackgroundOpaque(false);

    // screen for layout params ..
    final com.jogamp.newt.Display dpy = NewtFactory.createDisplay(null);
    final com.jogamp.newt.Screen scrn = NewtFactory.createScreen(dpy, 0);
    scrn.addReference();

    try {
      final Animator animator = new Animator();

      // Main
      final MovieCube demoMain =
          new MovieCube(
              urlConnection0,
              GLMediaPlayer.STREAM_ID_AUTO,
              GLMediaPlayer.STREAM_ID_AUTO,
              -2.3f,
              0f,
              0f);
      final GLWindow glWindowMain = GLWindow.create(scrn, capsMain);
      glWindowMain.setFullscreen(true);
      setContentView(getWindow(), glWindowMain);
      glWindowMain.addMouseListener(showKeyboardMouseListener);
      glWindowMain.addGLEventListener(demoMain);
      animator.add(glWindowMain);
      glWindowMain.setVisible(true);

      // animator.setUpdateFPSFrames(60, System.err);
      animator.setUpdateFPSFrames(-1, null);
      animator.resetFPSCounter();
    } catch (IOException e) {
      e.printStackTrace();
    }

    scrn.removeReference();

    Log.d(TAG, "onCreate - X");
  }
Exemple #6
0
  public static void main(String[] args) {
    GLProfile glp = GLProfile.getGL2ES2();
    GLCapabilities caps = new GLCapabilities(glp);
    caps.setAlphaBits(4);
    caps.setSampleBuffers(true);
    caps.setNumSamples(4);
    System.out.println("Requested: " + caps);

    final GLWindow window = GLWindow.create(caps);
    window.setPosition(10, 10);
    window.setSize(800, 400);
    window.setTitle("GPU UI Newt Demo 01");
    RenderState rs = RenderState.createRenderState(new ShaderState(), SVertex.factory());
    UIGLListener01 uiGLListener = new UIGLListener01(rs, DEBUG, TRACE);
    uiGLListener.attachInputListenerTo(window);
    window.addGLEventListener(uiGLListener);

    window.setUpdateFPSFrames(FPSCounter.DEFAULT_FRAMES_PER_INTERVAL, System.err);
    window.setVisible(true);

    final Animator animator = new Animator();
    animator.setUpdateFPSFrames(FPSCounter.DEFAULT_FRAMES_PER_INTERVAL, System.err);
    animator.add(window);

    window.addKeyListener(
        new KeyAdapter() {
          public void keyPressed(KeyEvent arg0) {
            if (arg0.getKeyCode() == KeyEvent.VK_F4) {
              window.destroy();
            }
          }
        });
    window.addWindowListener(
        new WindowAdapter() {
          public void windowDestroyed(WindowEvent e) {
            animator.stop();
          }
        });

    animator.start();
  }
  public void testImpl(boolean useFFP, final InputStream istream)
      throws InterruptedException, IOException {
    final GLReadBufferUtil screenshot = new GLReadBufferUtil(true, false);
    GLProfile glp;
    if (useFFP && GLProfile.isAvailable(GLProfile.GL2)) {
      glp = GLProfile.getMaxFixedFunc(true);
    } else if (!useFFP && GLProfile.isAvailable(GLProfile.GL2ES2)) {
      glp = GLProfile.getGL2ES2();
    } else {
      System.err.println(getSimpleTestName(".") + ": GLProfile n/a, useFFP: " + useFFP);
      return;
    }
    final GLCapabilities caps = new GLCapabilities(glp);
    caps.setAlphaBits(1);

    final TextureData texData =
        TextureIO.newTextureData(glp, istream, false /* mipmap */, TextureIO.TGA);
    System.err.println("TextureData: " + texData);

    final GLWindow glad = GLWindow.create(caps);
    glad.setTitle("TestTGATextureGL2FromFileNEWT");
    // Size OpenGL to Video Surface
    glad.setSize(texData.getWidth(), texData.getHeight());

    // load texture from file inside current GL context to match the way
    // the bug submitter was doing it
    final GLEventListener gle =
        useFFP ? new TextureDraw01GL2Listener(texData) : new TextureDraw01ES2Listener(texData, 0);
    glad.addGLEventListener(gle);
    glad.addGLEventListener(
        new GLEventListener() {
          boolean shot = false;

          @Override
          public void init(GLAutoDrawable drawable) {}

          public void display(GLAutoDrawable drawable) {
            // 1 snapshot
            if (null != ((TextureDraw01Accessor) gle).getTexture() && !shot) {
              shot = true;
              snapshot(0, null, drawable.getGL(), screenshot, TextureIO.PNG, null);
            }
          }

          @Override
          public void dispose(GLAutoDrawable drawable) {}

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

    Animator animator = new Animator(glad);
    animator.setUpdateFPSFrames(60, showFPS ? System.err : null);
    QuitAdapter quitAdapter = new QuitAdapter();
    glad.addKeyListener(quitAdapter);
    glad.addWindowListener(quitAdapter);
    glad.setVisible(true);
    animator.start();

    while (!quitAdapter.shouldQuit()
        && animator.isAnimating()
        && animator.getTotalFPSDuration() < duration) {
      Thread.sleep(100);
    }

    animator.stop();
    glad.destroy();
  }
  public void testImpl(
      final int sceneMSAASamples, final int graphMSAASamples, final int graphVBAASamples)
      throws InterruptedException {
    GLProfile glp = GLProfile.get(GLProfile.GL2ES2);
    GLCapabilities caps = new GLCapabilities(glp);
    caps.setAlphaBits(4);
    if (0 < sceneMSAASamples) {
      caps.setSampleBuffers(true);
      caps.setNumSamples(sceneMSAASamples);
    }
    System.err.println(
        "Requested: "
            + caps
            + ", graph[msaaSamples "
            + graphMSAASamples
            + ", vbaaSamples "
            + graphVBAASamples
            + "]");

    GLWindow window =
        createWindow(
            "text-gvbaa"
                + graphVBAASamples
                + "-gmsaa"
                + graphMSAASamples
                + "-smsaa"
                + sceneMSAASamples,
            caps,
            1024,
            640);
    window.display();
    System.err.println("Chosen: " + window.getChosenGLCapabilities());
    if (WaitStartEnd) {
      UITestCase.waitForKey("Start");
    }

    final RenderState rs = RenderState.createRenderState(SVertex.factory());
    final int renderModes, sampleCount;
    if (graphVBAASamples > 0) {
      renderModes = Region.VBAA_RENDERING_BIT;
      sampleCount = graphVBAASamples;
    } else if (graphMSAASamples > 0) {
      renderModes = Region.MSAA_RENDERING_BIT;
      sampleCount = graphMSAASamples;
    } else {
      renderModes = 0;
      sampleCount = 0;
    }
    final TextRendererGLEL textGLListener = new TextRendererGLEL(rs, renderModes, sampleCount);
    System.err.println(textGLListener.getFontInfo());

    window.addGLEventListener(textGLListener);

    Animator anim = new Animator();
    anim.add(window);
    anim.start();
    anim.setUpdateFPSFrames(60, null);
    sleep();
    window.invoke(
        true,
        new GLRunnable() {
          @Override
          public boolean run(GLAutoDrawable drawable) {
            try {
              textGLListener.printScreen(
                  renderModes,
                  drawable,
                  "./",
                  "TestTextRendererNEWT00-snap" + screenshot_num,
                  false);
              screenshot_num++;
            } catch (Exception e) {
              e.printStackTrace();
            }
            return true;
          }
        });
    anim.stop();
    if (WaitStartEnd) {
      UITestCase.waitForKey("Stop");
    }
    destroyWindow(window);
  }
  @Test
  public void compileShader() throws InterruptedException {
    GLProfile glp = GLProfile.get(GLProfile.GL2GL3);
    GLCapabilities caps = new GLCapabilities(glp);
    // commenting out this line makes it work
    caps.setStencilBits(8);

    // commenting in this line also makes it work
    // caps.setSampleBuffers(true);

    final Frame frame = new Frame("Bug 459 shader compilation test");
    Assert.assertNotNull(frame);

    final GLCanvas glCanvas = new GLCanvas(caps);
    Assert.assertNotNull(glCanvas);
    frame.add(glCanvas);

    glCanvas.addGLEventListener(
        new GLEventListener() {
          /* @Override */
          public void init(GLAutoDrawable drawable) {
            String code = "void main(void){gl_Position = vec4(0,0,0,1);}";

            GL2GL3 gl = drawable.getGL().getGL2GL3();
            int id = gl.glCreateShader(GL2GL3.GL_VERTEX_SHADER);

            try {
              gl.glShaderSource(id, 1, new String[] {code}, (int[]) null, 0);
              gl.glCompileShader(id);

              int[] compiled = new int[1];
              gl.glGetShaderiv(id, GL2GL3.GL_COMPILE_STATUS, compiled, 0);
              if (compiled[0] == GL2GL3.GL_FALSE) {
                int[] logLength = new int[1];
                gl.glGetShaderiv(id, GL2GL3.GL_INFO_LOG_LENGTH, logLength, 0);

                byte[] log = new byte[logLength[0]];
                gl.glGetShaderInfoLog(id, logLength[0], (int[]) null, 0, log, 0);

                System.err.println("Error compiling the shader: " + new String(log));

                gl.glDeleteShader(id);
              } else {
                System.out.println("Shader compiled: id=" + id);
              }
            } catch (GLException e) {
              glexception = e;
            }
          }

          /* @Override */
          public void dispose(GLAutoDrawable drawable) {}

          /* @Override */
          public void display(GLAutoDrawable drawable) {}

          /* @Override */
          public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {}
        });

    Animator animator = new Animator(glCanvas);
    try {
      javax.swing.SwingUtilities.invokeAndWait(
          new Runnable() {
            public void run() {
              frame.setSize(512, 512);
              frame.setVisible(true);
            }
          });
    } catch (Exception ex) {
      throw new RuntimeException(ex);
    }
    animator.setUpdateFPSFrames(1, null);
    animator.start();

    while (animator.isAnimating() && animator.getTotalFPSDuration() < duration) {
      Thread.sleep(100);
    }

    Assert.assertTrue(glexception != null ? glexception.getMessage() : "", glexception == null);
    Assert.assertNotNull(frame);
    Assert.assertNotNull(glCanvas);
    Assert.assertNotNull(animator);

    animator.stop();
    Assert.assertEquals(false, animator.isAnimating());
    try {
      javax.swing.SwingUtilities.invokeAndWait(
          new Runnable() {
            public void run() {
              frame.setVisible(false);
              frame.remove(glCanvas);
              frame.dispose();
            }
          });
    } catch (Throwable throwable) {
      throwable.printStackTrace();
      Assume.assumeNoException(throwable);
    }
  }
  public void testImpl() throws InterruptedException {
    final JFrame frame = new JFrame(this.getSimpleTestName("."));

    //
    // GLDrawableFactory factory = GLDrawableFactory.getFactory(GLProfile.get(GLProfile.GL2));
    // GLContext sharedContext = factory.getOrCreateSharedContext(factory.getDefaultDevice());
    //
    final GLCapabilities glCapabilities = new GLCapabilities(GLProfile.get(GLProfile.GL2));
    glCapabilities.setSampleBuffers(true);
    glCapabilities.setNumSamples(4);

    final GearsES2 eventListener1 = new GearsES2(0);
    final GearsES2 eventListener2 = new GearsES2(1);

    final Component openGLComponent1;
    final Component openGLComponent2;
    final GLAutoDrawable openGLAutoDrawable1;
    final GLAutoDrawable openGLAutoDrawable2;

    final GLWindow glWindow1 = GLWindow.create(glCapabilities);
    final NewtCanvasAWT newtCanvasAWT1 = new NewtCanvasAWT(glWindow1);
    newtCanvasAWT1.setPreferredSize(new Dimension(640, 480));
    glWindow1.addGLEventListener(eventListener1);
    //
    final GLWindow glWindow2 = GLWindow.create(glCapabilities);
    final NewtCanvasAWT newtCanvasAWT2 = new NewtCanvasAWT(glWindow2);
    newtCanvasAWT2.setPreferredSize(new Dimension(640, 480));
    glWindow2.addGLEventListener(eventListener2);

    openGLComponent1 = newtCanvasAWT1;
    openGLComponent2 = newtCanvasAWT2;
    openGLAutoDrawable1 = glWindow1;
    openGLAutoDrawable2 = glWindow2;

    // group both OpenGL canvases / windows into a horizontal panel
    final JPanel openGLPanel = new JPanel();
    openGLPanel.setLayout(new BoxLayout(openGLPanel, BoxLayout.LINE_AXIS));
    openGLPanel.add(openGLComponent1);
    openGLPanel.add(Box.createHorizontalStrut(5));
    openGLPanel.add(openGLComponent2);

    final JPanel mainPanel = (JPanel) frame.getContentPane();
    mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.LINE_AXIS));
    mainPanel.add(Box.createHorizontalGlue());
    mainPanel.add(openGLPanel);
    mainPanel.add(Box.createHorizontalGlue());

    final Animator animator = new Animator(Thread.currentThread().getThreadGroup());
    animator.setUpdateFPSFrames(1, null);
    animator.add(openGLAutoDrawable1);
    animator.add(openGLAutoDrawable2);

    // make the window visible using the EDT
    SwingUtilities.invokeLater(
        new Runnable() {
          public void run() {
            frame.pack();
            frame.setVisible(true);
          }
        });

    Assert.assertEquals(true, AWTRobotUtil.waitForVisible(frame, true));
    Assert.assertEquals(true, AWTRobotUtil.waitForRealized(openGLComponent1, true));
    Assert.assertEquals(true, AWTRobotUtil.waitForRealized(openGLComponent2, true));

    animator.start();

    // sleep for test duration, then request the window to close, wait for the window to close,s and
    // stop the animation
    while (animator.isAnimating() && animator.getTotalFPSDuration() < durationPerTest) {
      Thread.sleep(100);
    }

    animator.stop();

    // ask the EDT to dispose of the frame;
    // if using newt, explicitly dispose of the canvases because otherwise it seems our destroy
    // methods are not called
    SwingUtilities.invokeLater(
        new Runnable() {
          public void run() {
            newtCanvasAWT1.destroy(); // removeNotify does not destroy GLWindow
            newtCanvasAWT2.destroy(); // removeNotify does not destroy GLWindow
            frame.dispose();
          }
        });
    Assert.assertEquals(true, AWTRobotUtil.waitForVisible(frame, false));
    Assert.assertEquals(true, AWTRobotUtil.waitForRealized(openGLComponent1, false));
    Assert.assertEquals(true, AWTRobotUtil.waitForRealized(openGLComponent2, false));
  }
Exemple #11
0
  public void init(ThreadGroup tg, final GLWindow glWindow) {
    isValid = false;
    this.glWindow = glWindow;
    this.glWindow.addWindowListener(
        new WindowAdapter() {
          // Closing action: back to parent!
          @Override
          public void windowDestroyNotify(WindowEvent e) {
            if (isValid()
                && WindowClosingMode.DO_NOTHING_ON_CLOSE == glWindow.getDefaultCloseOperation()) {
              if (null == glWindow.getParent()) {
                // we may be called directly by the native EDT
                new Thread(
                        new Runnable() {
                          @Override
                          public void run() {
                            if (glWindow.isNativeValid()) {
                              glWindow.reparentWindow(awtParent);
                            }
                          }
                        })
                    .start();
              }
            }
          }
        });

    glEventListener = createInstance(glEventListenerClazzName);
    if (null == glEventListener) {
      return;
    }

    try {
      if (!setField(glEventListener, "window", glWindow)) {
        setField(glEventListener, "glWindow", glWindow);
      }

      glWindow.addGLEventListener(this);
      glWindow.addGLEventListener(glEventListener);

      if (glEventListener instanceof WindowListener) {
        glWindow.addWindowListener((WindowListener) glEventListener);
      }

      if (glEventListener instanceof MouseListener) {
        glWindow.addMouseListener((MouseListener) glEventListener);
      }

      if (glEventListener instanceof KeyListener) {
        glWindow.addKeyListener((KeyListener) glEventListener);
      }

      if (!noDefaultKeyListener) {
        glWindow.addKeyListener(this);
      }

      glWindow.setUpdateFPSFrames(FPSCounter.DEFAULT_FRAMES_PER_INTERVAL, System.err);

      // glAnimator = new FPSAnimator(canvas, 60);
      glAnimator = new Animator();
      glAnimator.setModeBits(
          false, Animator.MODE_EXPECT_AWT_RENDERING_THREAD); // No AWT thread involved!
      glAnimator.setThreadGroup(tg);
      glAnimator.add(glWindow);
      glAnimator.setUpdateFPSFrames(FPSCounter.DEFAULT_FRAMES_PER_INTERVAL, null);

    } catch (Throwable t) {
      throw new RuntimeException(t);
    }
    isValid = true;
  }