Пример #1
0
 @Override
 protected GLJPanel createDrawable() {
   GLCapabilities caps = new GLCapabilities(null);
   //
   GLJPanel panel = new GLJPanel(caps);
   panel.addGLEventListener(this);
   panel.addKeyListener(this);
   return panel;
 }
Пример #2
0
 @Override
 protected GLJPanel createDrawable() {
   GLCapabilities caps = new GLCapabilities(null);
   caps.setSampleBuffers(true); // enable sample buffers for aliasing
   caps.setNumSamples(2);
   //
   GLJPanel panel = new GLJPanel(caps);
   panel.addGLEventListener(this);
   panel.addKeyListener(this);
   return panel;
 }
Пример #3
0
 public static void main(String[] args) {
   // cria o painel e adiciona um ouvinte GL
   GLJPanel panel = new GLJPanel();
   TransfGeom3D pp = new TransfGeom3D(panel);
   panel.addGLEventListener(pp);
   // cria uma janela e adiciona o painel
   JFrame frame = new JFrame("Aplicação JOGL Simples");
   frame.addKeyListener(pp);
   frame.add(panel);
   frame.setSize(400, 400);
   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   frame.setLocationRelativeTo(null);
   frame.setVisible(true);
 }
Пример #4
0
 @Override
 protected GLJPanel createDrawable() {
   GLCapabilities caps = new GLCapabilities(null);
   // Be certain you request an accumulation buffer.
   caps.setAccumBlueBits(16);
   caps.setAccumGreenBits(16);
   caps.setAccumRedBits(16);
   caps.setAccumAlphaBits(16);
   //
   GLJPanel panel = new GLJPanel(caps);
   panel.addGLEventListener(this);
   panel.addKeyListener(this);
   return panel;
 }
Пример #5
0
  public static void main(String[] args) {
    GLProfile glprofile = GLProfile.getDefault();
    GLCapabilities glcapabilities = new GLCapabilities(glprofile);
    GLJPanel glcanvas = new GLJPanel(glcapabilities);
    glcanvas.addGLEventListener(new ExampleWorld());

    JFrame jframe = new JFrame("JOGL Demo");
    // Catch window closing events and quit
    jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    jframe.add(glcanvas);
    jframe.setSize(480, 480);
    jframe.setVisible(true);
  }
Пример #6
0
 @Override
 public void keyPressed(KeyEvent e) {
   switch (e.getKeyCode()) {
     case KeyEvent.VK_PAGE_UP: // faz zoom..in
       delta = delta * 1.1f;
       break;
     case KeyEvent.VK_PAGE_DOWN: // faz zoom..out
       delta = delta * 0.809f;
       break;
     case KeyEvent.VK_UP: // gira sobre o eixo..x
       alpha = alpha - 1;
       break;
     case KeyEvent.VK_DOWN: // gira sobre o eixo..x
       alpha = alpha + 1;
       break;
     case KeyEvent.VK_LEFT: // gira sobre o eixo..y
       beta = beta + 1;
       break;
     case KeyEvent.VK_RIGHT: // gira sobre o eixo..y
       beta = beta - 1;
       break;
   }
   // força o redesenho da tela
   panel.repaint();
 }
Пример #7
0
  public DrawByLevelFractal() {
    baseDir = "CS371/assignments/assignment02/ifs/";

    ifsFiles = new ArrayList<String>();
    ifsFiles.add("carpet.ifs");
    ifsFiles.add("chaos.ifs");
    ifsFiles.add("coral.ifs");
    ifsFiles.add("curl.ifs");
    ifsFiles.add("four.ifs");
    ifsFiles.add("galaxy.ifs");
    ifsFiles.add("dragon.ifs");
    ifsFiles.add("leady.ifs");
    ifsFiles.add("koch.ifs");
    ifsFiles.add("mouse.ifs");
    ifsFiles.add("leaf.ifs");
    ifsFiles.add("seven.ifs");
    ifsFiles.add("three.ifs");
    ifsFiles.add("tri.ifs");

    pointsToDraw = 80000;
    left = -7;
    right = 7;
    bottom = -7;
    top = 11;
    xOrigin = 0;
    yOrigin = 0;

    rotate_scale_xx = new double[maximumTransitions];
    rotate_scale_xy = new double[maximumTransitions];
    rotate_scale_yx = new double[maximumTransitions];
    rotate_scale_yy = new double[maximumTransitions];
    trans_x = new double[maximumTransitions];
    trans_y = new double[maximumTransitions];
    prob = new double[maximumTransitions];

    caps = new GLCapabilities(GLProfile.getGL2GL3());
    caps.setDoubleBuffered(true); // request double buffer display mode
    caps.setHardwareAccelerated(true);
    canvas = new GLJPanel();
    // canvas.setOpaque(true);
    canvas.addGLEventListener(this);
    canvas.addKeyListener(this);
    animator = new FPSAnimator(canvas, 60);

    getContentPane().add(canvas);
  }
  public static void main(String[] args) {
    // initialisation
    GLProfile glp = GLProfile.getDefault();
    GLCapabilities caps = new GLCapabilities(glp);

    // create a panel to draw on
    GLJPanel panel = new GLJPanel(caps);

    // put it in a JFrame
    final JFrame jframe = new JFrame("My First 3D Example");
    jframe.setSize(300, 300);
    jframe.add(panel);
    jframe.setVisible(true);

    jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    panel.addGLEventListener(new TransparencyExample());
  }
Пример #9
0
 /** handle button events. */
 public void actionPerformed(ActionEvent e) {
   String cmd = e.getActionCommand();
   if (cmd.equals("run")) {
     if (animator.isAnimating()) stop();
     else start();
   } else if (cmd.equals("transparancy")) {
     if (drawable != null) drawable.setOpaque(!checkBox.isSelected());
   }
 }
Пример #10
0
  /** Run the game. */
  public void run() {
    GLProfile glProfile = GLProfile.getDefault();
    GLCapabilities glCapabilities = new GLCapabilities(glProfile);
    glCapabilities.setSampleBuffers(true);
    glCapabilities.setNumSamples(4);

    GLJPanel gamePanel = new GLJPanel(glCapabilities);
    JFrame gameFrame = new JFrame("3D Game");

    GameEngine gameEngine = new GameEngine(myTerrain, gamePanel);

    gameEngine.start();

    gameFrame.getContentPane().add(gamePanel, BorderLayout.CENTER);
    gameFrame.setSize(1024, 768);
    gameFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    gameFrame.setVisible(true);

    gamePanel.requestFocusInWindow();
  }
  public void testImpl(final boolean keepTextureBound, final int texUnit)
      throws InterruptedException, IOException {
    final GLReadBufferUtil screenshot = new GLReadBufferUtil(true, false);
    GLProfile glp;
    if (GLProfile.isAvailable(GLProfile.GL2ES2)) {
      glp = GLProfile.getGL2ES2();
    } else {
      System.err.println(getSimpleTestName(".") + ": GLProfile n/a");
      return;
    }
    final GLCapabilities caps = new GLCapabilities(glp);

    final GLJPanel glc = new GLJPanel(caps);
    // final GLCanvas glc = new GLCanvas(caps);
    final Dimension glc_sz = new Dimension(640, 480);
    final Dimension glc_sz2 = new Dimension(800, 400);
    glc.setMinimumSize(glc_sz);
    glc.setPreferredSize(glc_sz);
    final JFrame frame = new JFrame("TestGLJPanelTextureStateAWT");
    Assert.assertNotNull(frame);
    frame.getContentPane().add(glc);

    final GLEventListener gle0;
    {
      final GearsES2 gle0sub = new GearsES2(0);
      // gle1sub.setClearBuffers(false);
      final TextureDraw02ES2ListenerFBO demo = new TextureDraw02ES2ListenerFBO(gle0sub, 1, texUnit);
      demo.setKeepTextureBound(keepTextureBound);
      demo.setClearBuffers(false);
      gle0 = demo;
    }

    final GLEventListener gle1;
    {
      final RedSquareES2 demo = new RedSquareES2(1);
      demo.setClearBuffers(false);
      gle1 = demo;
    }

    final boolean[] glelError = {false};

    glc.addGLEventListener(
        new GLEventListener() {
          int gle0X, gle0Y, gle0W, gle0H;
          int gle1X, gle1Y, gle1W, gle1H;
          int tX, tY, tW, tH;
          int shot = 0;

          void setupTex(GL gl) {
            // Note: FBObject uses diff defaults, i.e.: GL_NEAREST and GL_CLAMP_TO_EDGE
            if (keepTextureBound) {
              gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);
              gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR);
              gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_REPEAT);
              gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_REPEAT);
            }
          }

          @Override
          public void init(GLAutoDrawable drawable) {
            // Initialize w/ arbitrary values !
            GL2ES2 gl = drawable.getGL().getGL2ES2();
            gl.glActiveTexture(GL.GL_TEXTURE0 + 1);
            gl.glBindTexture(GL.GL_TEXTURE_2D, 0);
            gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);
            gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST);
            gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_REPEAT);
            gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_REPEAT);
            gl.glActiveTexture(GL.GL_TEXTURE0 + 0);
            gl.glBindTexture(GL.GL_TEXTURE_2D, 0);
            gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);
            gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST);
            gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_REPEAT);
            gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_REPEAT);

            gle0.init(drawable);
            gle1.init(drawable);
            setupTex(gl);
          }

          @Override
          public void dispose(GLAutoDrawable drawable) {
            gle0.dispose(drawable);
            gle1.dispose(drawable);
          }

          @Override
          public void display(GLAutoDrawable drawable) {
            GL2ES2 gl = drawable.getGL().getGL2ES2();

            gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
            gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);

            // test viewport
            {
              final int[] viewport = new int[] {0, 0, 0, 0};
              gl.glGetIntegerv(GL.GL_VIEWPORT, viewport, 0);
              if (gle1X != viewport[0]
                  || gle1Y != viewport[1]
                  || gle1W != viewport[2]
                  || gle1H != viewport[3]) {
                final String msg =
                    "Expected "
                        + gle1X
                        + "/"
                        + gle1Y
                        + " "
                        + gle1W
                        + "x"
                        + gle1H
                        + ", actual "
                        + viewport[0]
                        + "/"
                        + viewport[1]
                        + " "
                        + viewport[2]
                        + "x"
                        + viewport[3];
                Assert.assertTrue("Viewport not restored: " + msg, false);
                glelError[0] = true;
              }
            }

            gl.glViewport(gle0X, gle0Y, gle0W, gle0H);
            gle0.display(drawable);

            gl.glViewport(gle1X, gle1Y, gle1W, gle1H);
            gle1.display(drawable);

            shot++;
            if (4 == shot) {
              gl.glViewport(tX, tY, tW, tH);
              snapshot(0, null, drawable.getGL(), screenshot, TextureIO.PNG, null);
              gl.glViewport(gle1X, gle1Y, gle1W, gle1H); // restore viewport test
            }

            final TextureState ts =
                new TextureState(drawable.getGL(), GL.GL_TEXTURE_2D); // as set via gle0!
            // System.err.println("XXX: "+ts);
            Assert.assertEquals("Texture unit changed", GL.GL_TEXTURE0 + texUnit, ts.getUnit());
            if (keepTextureBound) {
              Assert.assertEquals(
                  "Texture mag-filter changed: " + ts, GL.GL_LINEAR, ts.getMagFilter());
              Assert.assertEquals(
                  "Texture mag-filter changed: " + ts, GL.GL_LINEAR, ts.getMinFilter());
              Assert.assertEquals("Texture wrap-s changed: " + ts, GL.GL_REPEAT, ts.getWrapS());
              Assert.assertEquals("Texture wrap-t changed: " + ts, GL.GL_REPEAT, ts.getWrapT());
              glelError[0] =
                  GL.GL_LINEAR != ts.getMagFilter()
                      || GL.GL_LINEAR != ts.getMinFilter()
                      || GL.GL_REPEAT != ts.getWrapS()
                      || GL.GL_REPEAT != ts.getWrapT();
            }
          }

          final int border = 5;

          @Override
          public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
            gle0X = x + border;
            gle0Y = y;
            gle0W = width / 2 - 2 * border;
            gle0H = height;
            // System.err.println("GLEL0 "+gle0X+"/"+gle0Y+" "+gle0W+"x"+gle0H);

            gle1X = gle0X + gle0W + 2 * border;
            gle1Y = y;
            gle1W = width / 2 - 2 * border;
            gle1H = height;
            // System.err.println("GLEL1 "+gle1X+"/"+gle1Y+" "+gle1W+"x"+gle1H);

            tX = x;
            tY = y;
            tW = width;
            tH = height;
            // System.err.println("Total "+tX+"/"+tY+" "+tW+"x"+tH);

            GL2ES2 gl = drawable.getGL().getGL2ES2();
            gl.glViewport(gle0X, gle0Y, gle0W, gle0H);
            gle0.reshape(drawable, 0, 0, gle0W, gle0H); // don't 'skip' about gle0X/gle0Y

            gl.glViewport(gle1X, gle1Y, gle1W, gle1H);
            gle1.reshape(drawable, 0, 0, gle1W, gle1H); // don't 'skip' about gle0X/gle0Y

            if (keepTextureBound) {
              setupTex(gl);
            }
          }
        });

    final QuitAdapter quitAdapter = new QuitAdapter();
    new com.jogamp.newt.event.awt.AWTKeyAdapter(quitAdapter, glc).addTo(glc);
    new com.jogamp.newt.event.awt.AWTWindowAdapter(quitAdapter, glc).addTo(glc);
    try {
      javax.swing.SwingUtilities.invokeAndWait(
          new Runnable() {
            public void run() {
              frame.pack();
              frame.setVisible(true);
            }
          });
    } catch (Throwable throwable) {
      throwable.printStackTrace();
      Assume.assumeNoException(throwable);
    }
    Assert.assertTrue("Component didn't become visible", AWTRobotUtil.waitForVisible(glc, true));
    Assert.assertTrue("Component didn't become realized", AWTRobotUtil.waitForRealized(glc, true));
    Thread.sleep(100);
    setFrameSize(frame, true, glc_sz2);
    System.err.println(
        "window resize pos/siz: "
            + glc.getX()
            + "/"
            + glc.getY()
            + " "
            + glc.getSurfaceWidth()
            + "x"
            + glc.getSurfaceHeight());
    Thread.sleep(100);

    final long t0 = System.currentTimeMillis();
    while (!quitAdapter.shouldQuit() && System.currentTimeMillis() - t0 < duration) {
      glc.display();
      Thread.sleep(100);
    }

    try {
      javax.swing.SwingUtilities.invokeAndWait(
          new Runnable() {
            public void run() {
              frame.setVisible(false);
              frame.remove(glc);
              frame.dispose();
            }
          });
    } catch (Throwable throwable) {
      throwable.printStackTrace();
      Assume.assumeNoException(throwable);
    }
    Assume.assumeFalse("Error occured in GLEL .. see log file above", glelError[0]);
  }