Exemplo n.º 1
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);
          }
        });
  }
Exemplo n.º 2
0
  /**
   * Creates a {@code Component} that is also a {@code GLAutoDrawable}. This is where all the
   * drawing takes place. The advantage of a {@code GLCanvas} is that it is faster, but a {@code
   * GLJPanel} is more portable. The component should also be disabled so that it does not receive
   * events that should be sent to the {@code drawableComponent}. A {@code GLCanvas} is a
   * heavyweight component and on some platforms will not pass through mouse events even though it
   * is disabled. A {@code GLJPanel} supports this better.
   */
  protected GLAutoDrawable createGLComponent(
      GLCapabilitiesImmutable capabilities, GLContext shareWith) {
    GLCanvas canvas = new GLCanvas(capabilities);
    if (shareWith != null) {
      canvas.setSharedContext(shareWith);
    }

    canvas.setEnabled(false);
    chosenCapabilities = (GLCapabilitiesImmutable) capabilities.cloneMutable();
    return canvas;
  }
Exemplo n.º 3
0
 protected GLCanvas createGLCanvas(
     final Frame frame, final int x, final int y, final GearsES2 gears)
     throws InterruptedException {
   final GLCanvas glCanvas = new GLCanvas(caps);
   Assert.assertNotNull(glCanvas);
   glCanvas.addGLEventListener(gears);
   frame.add(glCanvas);
   frame.setLocation(x, y);
   frame.setSize(width, height);
   frame.setTitle("AWT GLCanvas Shared Gears Test: " + x + "/" + y + " shared true");
   return glCanvas;
 }
Exemplo n.º 4
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();
  }
Exemplo n.º 5
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);
          }
        });
  }
  public static void main(String[] args) {
    GLProfile glprofile = GLProfile.getDefault();
    GLCapabilities glcapabilities = new GLCapabilities(glprofile);
    final GLCanvas glcanvas = new GLCanvas(glcapabilities);

    glcanvas.addGLEventListener(
        new GLEventListener() {

          @Override
          public void reshape(GLAutoDrawable glautodrawable, int x, int y, int width, int height) {
            OneTriangle.setup(glautodrawable.getGL().getGL2(), width, height);
          }

          @Override
          public void init(GLAutoDrawable glautodrawable) {}

          @Override
          public void dispose(GLAutoDrawable glautodrawable) {}

          @Override
          public void display(GLAutoDrawable glautodrawable) {
            OneTriangle.render(
                glautodrawable.getGL().getGL2(),
                glautodrawable.getSurfaceWidth(),
                glautodrawable.getSurfaceHeight());
          }
        });

    // "One Triangle Swing GLCanvas JWindow"
    final JWindow jwindow = new JWindow();
    jwindow.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent windowevent) {
            jwindow.dispose();
            System.exit(0);
          }
        });

    jwindow.getContentPane().add(glcanvas, BorderLayout.CENTER);
    jwindow.setSize(640, 480);
    jwindow.setVisible(true);
  }
Exemplo n.º 7
0
  /**
   * Test of add method, of class AwtAbstractScene.
   *
   * @throws InterruptedException
   * @throws InvocationTargetException
   */
  @Test
  public void testAdd() throws InterruptedException, InvocationTargetException {
    final GLCanvas panel = (GLCanvas) scene.getComponent();
    // create listeners
    final KeyListener listener0 = new KeyAdapter() {};

    final MouseListener listener1 = new MouseAdapter() {};
    final MouseMotionListener listener2 = new MouseMotionAdapter() {};
    final MouseWheelListener listener3 =
        new MouseWheelListener() {
          @Override
          public void mouseWheelMoved(final MouseWheelEvent event) {
            // no operation
          }
        };
    final ComponentListener listener4 = new ComponentAdapter() {};
    final ContainerListener listener5 = new ContainerAdapter() {};
    final FocusListener listener6 = new FocusAdapter() {};
    // add all the listeners on the event thread
    SwingUtilities.invokeAndWait(
        new Runnable() {
          @Override
          public void run() {
            scene.add(listener0);
            scene.add(listener1);
            scene.add(listener2);
            scene.add(listener3);
            scene.add(listener4);
            scene.add(listener5);
            scene.add(listener6);
          }
        });
    // ensure they are all added to the panel
    Assert.assertTrue(containsValue(panel.getKeyListeners(), listener0));
    Assert.assertTrue(containsValue(panel.getMouseListeners(), listener1));
    Assert.assertTrue(containsValue(panel.getMouseMotionListeners(), listener2));
    Assert.assertTrue(containsValue(panel.getMouseWheelListeners(), listener3));
    Assert.assertTrue(containsValue(panel.getComponentListeners(), listener4));
    //        Assert.assertTrue(containsValue(panel.getContainerListeners(), listener5));
    Assert.assertTrue(containsValue(panel.getFocusListeners(), listener6));
  }
  protected void initGLCanvas() {
    loadNatives();

    device = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();

    // FIXME use the settings to know whether to use the max programmable profile
    // then call GLProfile.getMaxProgrammable(true);
    GLCapabilities caps = new GLCapabilities(GLProfile.getMaxFixedFunc(true));
    caps.setHardwareAccelerated(true);
    caps.setDoubleBuffered(true);
    caps.setStencilBits(settings.getStencilBits());
    caps.setDepthBits(settings.getDepthBits());

    if (settings.getSamples() > 1) {
      caps.setSampleBuffers(true);
      caps.setNumSamples(settings.getSamples());
    }

    canvas =
        new GLCanvas(caps) {
          @Override
          public void addNotify() {
            super.addNotify();
            onCanvasAdded();
          }

          @Override
          public void removeNotify() {
            onCanvasRemoved();
            super.removeNotify();
          }
        };
    canvas.invoke(
        false,
        new GLRunnable() {
          public boolean run(GLAutoDrawable glad) {
            canvas.getGL().setSwapInterval(settings.isVSync() ? 1 : 0);
            return true;
          }
        });
    canvas.setFocusable(true);
    canvas.requestFocus();
    canvas.setSize(settings.getWidth(), settings.getHeight());
    canvas.setIgnoreRepaint(true);
    canvas.addGLEventListener(this);

    // FIXME not sure it is the best place to do that
    renderable.set(true);

    // TODO remove this block once for all when the unified renderer is stable
    /*if (settings.getBoolean("GraphicsDebug")) {
        canvas.invoke(false, new GLRunnable() {
            public boolean run(GLAutoDrawable glad) {
                GL gl = glad.getGL();
                if (gl.isGLES()) {
                    if (gl.isGLES1()) {
                        glad.setGL(new DebugGLES1(gl.getGLES1()));
                    } else {
                        if (gl.isGLES2()) {
                            glad.setGL(new DebugGLES2(gl.getGLES2()));
                        } else {
                            if (gl.isGLES3()) {
                            	glad.setGL(new DebugGLES3(gl.getGLES3()));
                            }
                        }
                    }
                } else {
                    if (gl.isGL4bc()) {
                        glad.setGL(new DebugGL4bc(gl.getGL4bc()));
                    } else {
                        if (gl.isGL4()) {
                            glad.setGL(new DebugGL4(gl.getGL4()));
                        } else {
                            if (gl.isGL3bc()) {
                                glad.setGL(new DebugGL3bc(gl.getGL3bc()));
                            } else {
                                if (gl.isGL3()) {
                                    glad.setGL(new DebugGL3(gl.getGL3()));
                                } else {
                                    if (gl.isGL2()) {
                                        glad.setGL(new DebugGL2(gl.getGL2()));
                                    }
                                }
                            }
                        }
                    }
                }
                return true;
            }
        });
    }

    renderer = new JoglRenderer();

    canvas.invoke(false, new GLRunnable() {
        public boolean run(GLAutoDrawable glad) {
            renderer.setMainFrameBufferSrgb(settings.getGammaCorrection());
            return true;
        }
    });*/
  }
Exemplo n.º 9
0
  public void asyncEachOneAnimator(final boolean destroyCleanOrder)
      throws InterruptedException, InvocationTargetException {
    final Frame f1 = new Frame();
    final Animator a1 = new Animator();
    final GearsES2 g1 = new GearsES2(0);
    final GLCanvas c1 = createGLCanvas(f1, 0, 0, g1);
    a1.add(c1);
    a1.start();
    // f1.setVisible(true); // we do this post f2 .. to test pending creation!

    final Frame f2 = new Frame();
    final Animator a2 = new Animator();
    final GearsES2 g2 = new GearsES2(0);
    g2.setSharedGears(g1);
    final GLCanvas c2 = createGLCanvas(f2, f1.getX() + width, f1.getY() + 0, g2);
    c2.setSharedAutoDrawable(c1);
    a2.add(c2);
    a2.start();
    javax.swing.SwingUtilities.invokeAndWait(
        new Runnable() {
          public void run() {
            f2.setVisible(true);
          }
        });

    Thread.sleep(200); // wait a while ..

    javax.swing.SwingUtilities.invokeAndWait(
        new Runnable() {
          public void run() {
            f1.setVisible(true); // test pending creation of f2
          }
        });

    final Frame f3 = new Frame();
    final Animator a3 = new Animator();
    final GearsES2 g3 = new GearsES2(0);
    g3.setSharedGears(g1);
    final GLCanvas c3 = createGLCanvas(f3, f1.getX() + 0, f1.getY() + height, g3);
    c3.setSharedAutoDrawable(c1);
    a3.add(c3);
    a3.start();
    javax.swing.SwingUtilities.invokeAndWait(
        new Runnable() {
          public void run() {
            f3.setVisible(true);
          }
        });

    Thread.sleep(
        1000 / 60
            * 10); // wait ~10 frames giving a chance to create (blocking until master share is
    // valid)

    Assert.assertTrue(AWTRobotUtil.waitForRealized(c1, true));
    Assert.assertTrue(AWTRobotUtil.waitForVisible(c1, true));
    Assert.assertTrue(AWTRobotUtil.waitForContextCreated(c1, true));
    Assert.assertTrue("Gears1 not initialized", g1.waitForInit(true));

    Assert.assertTrue(AWTRobotUtil.waitForRealized(c2, true));
    Assert.assertTrue(AWTRobotUtil.waitForVisible(c2, true));
    Assert.assertTrue(AWTRobotUtil.waitForContextCreated(c2, true));
    Assert.assertTrue("Gears2 not initialized", g2.waitForInit(true));

    Assert.assertTrue(AWTRobotUtil.waitForRealized(c3, true));
    Assert.assertTrue(AWTRobotUtil.waitForVisible(c3, true));
    Assert.assertTrue(AWTRobotUtil.waitForContextCreated(c3, true));
    Assert.assertTrue("Gears3 not initialized", g3.waitForInit(true));

    final GLContext ctx1 = c1.getContext();
    final GLContext ctx2 = c2.getContext();
    final GLContext ctx3 = c3.getContext();
    {
      final List<GLContext> ctx1Shares = ctx1.getCreatedShares();
      final List<GLContext> ctx2Shares = ctx2.getCreatedShares();
      final List<GLContext> ctx3Shares = ctx3.getCreatedShares();
      MiscUtils.dumpSharedGLContext("XXX-C-3.1", ctx1);
      MiscUtils.dumpSharedGLContext("XXX-C-3.2", ctx2);
      MiscUtils.dumpSharedGLContext("XXX-C-3.3", ctx3);

      Assert.assertTrue("Ctx1 is not shared", ctx1.isShared());
      Assert.assertTrue("Ctx2 is not shared", ctx2.isShared());
      Assert.assertTrue("Ctx3 is not shared", ctx3.isShared());
      Assert.assertEquals("Ctx1 has unexpected number of created shares", 2, ctx1Shares.size());
      Assert.assertEquals("Ctx2 has unexpected number of created shares", 2, ctx2Shares.size());
      Assert.assertEquals("Ctx3 has unexpected number of created shares", 2, ctx3Shares.size());
    }

    Assert.assertTrue("Gears1 is shared", !g1.usesSharedGears());
    Assert.assertTrue("Gears2 is not shared", g2.usesSharedGears());
    Assert.assertTrue("Gears3 is not shared", g3.usesSharedGears());

    try {
      Thread.sleep(duration);
    } catch (final Exception e) {
      e.printStackTrace();
    }
    // Stopped animator allows native windowing system 'repaint' event
    // to trigger GLAD 'display'
    a1.stop();
    Assert.assertEquals(false, a1.isAnimating());
    a2.stop();
    Assert.assertEquals(false, a2.isAnimating());
    a3.stop();
    Assert.assertEquals(false, a3.isAnimating());

    if (destroyCleanOrder) {
      System.err.println("XXX Destroy in clean order NOW");
    } else {
      System.err.println(
          "XXX Destroy in creation order NOW - Driver Impl. Ma trigger driver Bug i.e. not postponing GL ctx destruction after releasing all refs.");
    }
    javax.swing.SwingUtilities.invokeAndWait(
        new Runnable() {
          public void run() {
            try {
              if (destroyCleanOrder) {
                f3.dispose();
              } else {
                f1.dispose();
              }
            } catch (final Throwable t) {
              throw new RuntimeException(t);
            }
          }
        });

    javax.swing.SwingUtilities.invokeAndWait(
        new Runnable() {
          public void run() {
            try {
              f2.dispose();
            } catch (final Throwable t) {
              throw new RuntimeException(t);
            }
          }
        });

    javax.swing.SwingUtilities.invokeAndWait(
        new Runnable() {
          public void run() {
            try {
              if (destroyCleanOrder) {
                f1.dispose();
              } else {
                f3.dispose();
              }
            } catch (final Throwable t) {
              throw new RuntimeException(t);
            }
          }
        });

    Assert.assertTrue(AWTRobotUtil.waitForRealized(c1, false));
    Assert.assertTrue(AWTRobotUtil.waitForRealized(c2, false));
    Assert.assertTrue(AWTRobotUtil.waitForRealized(c3, false));
  }