コード例 #1
0
ファイル: DrawPanel.java プロジェクト: moskvin/rubiks-cube-2
	public void start() throws IOException {
		
		canvas.addGLEventListener(new DrawPanel());
		setSize(800,600);
		animator.start();
		canvas.requestFocus();
		}
コード例 #2
0
ファイル: JOGL2Nehe11Flag.java プロジェクト: ElDombrovan/java
  /** The entry main() method */
  public static void main(String[] args) {
    // Create the OpenGL rendering canvas
    GLCanvas canvas = new GLCanvas(); // heavy-weight GLCanvas
    canvas.setPreferredSize(new Dimension(CANVAS_WIDTH, CANVAS_HEIGHT));
    canvas.addGLEventListener(new JOGL2Nehe11Flag());

    // Create a animator that drives canvas' display() at the specified FPS.
    final FPSAnimator animator = new FPSAnimator(canvas, FPS, true);

    // Create the top-level container frame
    final JFrame frame = new JFrame(); // Swing's JFrame or AWT's Frame
    frame.getContentPane().add(canvas);
    frame.addWindowListener(
        new WindowAdapter() {
          @Override
          public void windowClosing(WindowEvent e) {
            // Use a dedicate thread to run the stop() to ensure that the
            // animator stops before program exits.
            new Thread() {
              @Override
              public void run() {
                animator.stop(); // stop the animator loop
                System.exit(0);
              }
            }.start();
          }
        });
    frame.setTitle(TITLE);
    frame.pack();
    frame.setVisible(true);
    animator.start(); // start the animation loop
  }
コード例 #3
0
  @BeforeClass
  public static void beforeClass() throws Exception {

    final GLCanvas canvas = new GLCanvas();
    canvas.addGLEventListener(new RedSquareES2());
    new AWTMouseAdapter(_testMouseListener, canvas).addTo(canvas);

    _testFrame = new JFrame("Event Modifier Test AWTCanvas");
    _testFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

    SwingUtilities.invokeAndWait(
        new Runnable() {
          public void run() {
            _testFrame.getContentPane().add(canvas);
            _testFrame.setBounds(TEST_FRAME_X, TEST_FRAME_Y, TEST_FRAME_WIDTH, TEST_FRAME_HEIGHT);
            _testFrame.setVisible(true);
          }
        });
    Assert.assertEquals(true, AWTRobotUtil.waitForVisible(_testFrame, true));
    Assert.assertTrue(AWTRobotUtil.waitForVisible(canvas, true));
    Assert.assertTrue(AWTRobotUtil.waitForRealized(canvas, true));

    AWTRobotUtil.assertRequestFocusAndWait(null, canvas, canvas, null, null); // programmatic
    Assert.assertNotNull(_robot);
    AWTRobotUtil.requestFocus(
        _robot, canvas,
        false); // within unit framework, prev. tests (TestFocus02SwingAWTRobot) 'confuses' Windows
                // keyboard input
  }
コード例 #4
0
  public static void main(String[] args) {
    // 1. Configuración de OpenGL Version 2
    GLProfile profile = GLProfile.get(GLProfile.GL2);
    GLCapabilities capabilities = new GLCapabilities(profile);

    // 2. Canvas es el aplicativo gráfico que se empotra en un JFrame - Ventana
    GLCanvas glcanvas = new GLCanvas(capabilities);
    glcanvas.addGLEventListener(new Renderer_Circulo());

    glcanvas.setSize(600, 600);

    // 3. Crear la ventana para mostrar la aplicación de dibujo
    JFrame frame = new JFrame("Aplicación de OpenGL");
    frame.getContentPane().add(glcanvas);
    // 4. Añadir el evento para cerrar la ventana
    frame.addWindowListener(
        new WindowAdapter() {
          @Override
          public void windowClosing(WindowEvent ev) {
            System.exit(0);
          }
        });
    // 5. Cambiar el tamaño de la ventana y visualizarla
    frame.setSize(frame.getContentPane().getPreferredSize());
    frame.setVisible(true);
  }
コード例 #5
0
  public static void main(String[] args) {
    // Initialization
    // Setting up GL
    GLProfile.initSingleton();
    GLProfile glp = GLProfile.getDefault();
    GLCapabilities caps = new GLCapabilities(glp);
    GLCanvas canvas = new GLCanvas(caps);

    // Making the AWT frame window
    Frame frame = new Frame("Assignment 1");
    frame.setSize(800, 600);
    frame.add(canvas);
    frame.setVisible(true);

    // Adding a render listener
    canvas.addGLEventListener(new Assignment1());

    // Fixes so the exit button exits the program
    frame.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            System.exit(0);
          }
        });
  }
コード例 #6
0
 @Override
 protected GLCanvas createDrawable() {
   GLCapabilities caps = new GLCapabilities(null);
   caps.setSampleBuffers(true);
   //
   GLCanvas panel = new GLCanvas(caps);
   panel.addGLEventListener(this);
   panel.addKeyListener(this);
   return panel;
 }
コード例 #7
0
  private void initGL() {
    GLProfile profile = GLProfile.getDefault();

    GLCapabilities capabilities = new GLCapabilities(profile);

    canvas = new GLCanvas(capabilities);

    canvas.setSize(imageWidth, imageHeight);

    canvas.addGLEventListener(this);
  }
コード例 #8
0
 GLFrame(JTextArea outputArea) {
   this.outputArea = outputArea;
   GLCapabilities caps = new GLCapabilities(Configuration.getMaxCompatibleGLProfile());
   caps.setAlphaBits(8);
   caps.setRedBits(8);
   caps.setGreenBits(8);
   caps.setBlueBits(8);
   GLCanvas glCanvas = new GLCanvas(caps);
   glCanvas.addGLEventListener(this);
   this.add(glCanvas);
   this.setSize(200, 200);
 }
コード例 #9
0
ファイル: PickSquare.java プロジェクト: kdridi/jogl-samples
  public PickSquare() {
    super("picksquare");

    GLProfile profile = GLProfile.get(GLProfile.GL2);

    caps = new GLCapabilities(profile);
    canvas = new GLCanvas(caps);
    canvas.addGLEventListener(this);
    canvas.addKeyListener(this);
    canvas.addMouseListener(this);

    getContentPane().add(canvas);
  }
コード例 #10
0
ファイル: Issue326Test1.java プロジェクト: snmvaughan/jogl
  public Issue326Test1() {
    super("TextTest");
    this.setSize(800, 800);
    canvas = new GLCanvas();
    canvas.addGLEventListener(this);
    add(canvas);

    setVisible(true);
    addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            System.exit(0);
          }
        });
  }
コード例 #11
0
ファイル: PrintExt.java プロジェクト: JavaPosseRoundup/jzy3d
  public static void main(String[] args) {
    // set argument 'NotFirstUIActionOnProcess' in the JNLP's application-desc tag for example
    // <application-desc main-class="demos.j2d.TextCube"/>
    //   <argument>NotFirstUIActionOnProcess</argument>
    // </application-desc>
    boolean firstUIActionOnProcess =
        0 == args.length || !args[0].equals("NotFirstUIActionOnProcess");
    GLProfile.initSingleton();

    Frame frame = new Frame();
    GLCanvas canvas = new GLCanvas();
    canvas.addGLEventListener(new Listener());
    frame.setUndecorated(true);
    frame.add(canvas);
    frame.setSize(1, 1);
    frame.setVisible(true);
  }
コード例 #12
0
  public static void main(String[] args) {

    Frame frame = new Frame("Simple JOGL Application");

    // use GL2 profile since we only use the old OpenGL 2.x fixed function pipeline
    GLCapabilities capabilities = new GLCapabilities(GLProfile.get(GLProfile.GL2));

    // try to enable 2x anti aliasing - should be supported on most hardware
    //        capabilities.setNumSamples(2);
    //        capabilities.setSampleBuffers(true);

    GLCanvas canvas = new GLCanvas(capabilities);

    canvas.addGLEventListener(new SimpleJOGL());
    frame.add(canvas);

    // use JOGL's Animator utility for rendering
    final Animator animator = new Animator(canvas);

    // stop the Animator when we receive a window closing event
    frame.addWindowListener(
        new WindowAdapter() {

          @Override
          public void windowClosing(WindowEvent e) {
            // Run this on another thread than the AWT event queue to
            // make sure the call to Animator.stop() completes before
            // exiting
            new Thread(
                    new Runnable() {

                      public void run() {
                        animator.stop();
                        System.exit(0);
                      }
                    })
                .start();
          }
        });

    // Center frame, set its size and start rendering
    frame.setSize(640, 480);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
    animator.start();
  }
コード例 #13
0
ファイル: ModelSnip.java プロジェクト: vitalytravin/Jnano
  public static void main(String[] args) {
    GLProfile glprofile = GLProfile.getDefault();
    GLCapabilities glcapabilities = new GLCapabilities(glprofile);
    final GLCanvas glcanvas = new GLCanvas(glcapabilities);

    glcanvas.addGLEventListener(new ModelSnip());

    glcanvas.setIgnoreRepaint(true);

    Animator anim = new Animator(glcanvas);
    anim.start();

    JFrame jframe = new JFrame("Model GLEventListener");
    jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    jframe.getContentPane().add(glcanvas, BorderLayout.CENTER);
    jframe.setSize(640, 480);
    jframe.setVisible(true);
  }
コード例 #14
0
ファイル: Main.java プロジェクト: rsantina/jogl-demos
  public static void main(String[] args) {
    // set argument 'NotFirstUIActionOnProcess' in the JNLP's application-desc tag for example
    // <application-desc main-class="demos.j2d.TextCube"/>
    //   <argument>NotFirstUIActionOnProcess</argument>
    // </application-desc>
    boolean firstUIActionOnProcess =
        0 == args.length || !args[0].equals("NotFirstUIActionOnProcess");
    GLProfile.initSingleton(firstUIActionOnProcess);

    GLCapabilities caps = new GLCapabilities(null);
    GLCanvas canvas = new GLCanvas(caps);

    FBCubes cubes = new FBCubes();
    canvas.addMouseListener(cubes);
    canvas.addMouseMotionListener(cubes);
    canvas.addGLEventListener(cubes);

    Frame frame = new Frame("FBCubes Demo ES 1.1");
    frame.add(canvas);
    frame.setSize(800, 480);

    final GLAnimatorControl animator = new FPSAnimator(canvas, 60);
    frame.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            // Run this on another thread than the AWT event queue to
            // make sure the call to Animator.stop() completes before
            // exiting
            new Thread(
                    new Runnable() {
                      public void run() {
                        animator.stop();
                        System.exit(0);
                      }
                    })
                .start();
          }
        });

    frame.setVisible(true);
    animator.start();
  }
コード例 #15
0
ファイル: Test.java プロジェクト: JibouLBF/Fablab
 public static void main(String[] args) {
   final GLCanvas canvas = new GLCanvas();
   final Frame frame = new Frame("Jogl Quad drawing");
   final Animator animator = new Animator(canvas);
   canvas.addGLEventListener(new Test());
   frame.add(canvas);
   frame.setSize(640, 480);
   frame.setResizable(false);
   frame.addWindowListener(
       new WindowAdapter() {
         public void windowClosing(WindowEvent e) {
           animator.stop();
           frame.dispose();
           System.exit(0);
         }
       });
   frame.setVisible(true);
   animator.start();
   canvas.requestFocus();
 }
コード例 #16
0
ファイル: Local.java プロジェクト: Vineg/aparapi
  public static void main(String _args[]) {

    final NBodyKernel kernel =
        new NBodyKernel(Range.create(Integer.getInteger("bodies", 8192), 256));

    final JFrame frame = new JFrame("NBody");

    final JPanel panel = new JPanel(new BorderLayout());
    final JPanel controlPanel = new JPanel(new FlowLayout());
    panel.add(controlPanel, BorderLayout.SOUTH);

    final JButton startButton = new JButton("Start");

    startButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            running = true;
            startButton.setEnabled(false);
          }
        });
    controlPanel.add(startButton);
    controlPanel.add(new JLabel(kernel.getExecutionMode().toString()));

    controlPanel.add(new JLabel("   Particles"));
    controlPanel.add(new JTextField("" + kernel.range.getGlobalSize(0), 5));

    controlPanel.add(new JLabel("FPS"));
    final JTextField framesPerSecondTextField = new JTextField("0", 5);

    controlPanel.add(framesPerSecondTextField);
    controlPanel.add(new JLabel("Score("));
    final JLabel miniLabel =
        new JLabel("<html><small>calcs</small><hr/><small>&micro;sec</small></html>");

    controlPanel.add(miniLabel);
    controlPanel.add(new JLabel(")"));

    final JTextField positionUpdatesPerMicroSecondTextField = new JTextField("0", 5);

    controlPanel.add(positionUpdatesPerMicroSecondTextField);
    final GLCapabilities caps = new GLCapabilities(null);
    caps.setDoubleBuffered(true);
    caps.setHardwareAccelerated(true);
    final GLCanvas canvas = new GLCanvas(caps);
    final Dimension dimension =
        new Dimension(Integer.getInteger("width", 742), Integer.getInteger("height", 742));
    canvas.setPreferredSize(dimension);

    canvas.addGLEventListener(
        new GLEventListener() {
          private double ratio;

          private final float xeye = 0f;

          private final float yeye = 0f;

          private final float zeye = 100f;

          private final float xat = 0f;

          private final float yat = 0f;

          private final float zat = 0f;

          public final float zoomFactor = 1.0f;

          private int frames;

          private long last = System.currentTimeMillis();

          @Override
          public void dispose(GLAutoDrawable drawable) {}

          @Override
          public void display(GLAutoDrawable drawable) {

            final GL2 gl = drawable.getGL().getGL2();

            gl.glLoadIdentity();
            gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
            gl.glColor3f(1f, 1f, 1f);

            final GLU glu = new GLU();
            glu.gluPerspective(45f, ratio, 0f, 1000f);

            glu.gluLookAt(xeye, yeye, zeye * zoomFactor, xat, yat, zat, 0f, 1f, 0f);
            if (running) {
              kernel.execute(kernel.range);
              if (kernel.isExplicit()) {
                kernel.get(kernel.xyz);
              }
              final List<ProfileInfo> profileInfo = kernel.getProfileInfo();
              if ((profileInfo != null) && (profileInfo.size() > 0)) {
                for (final ProfileInfo p : profileInfo) {
                  System.out.print(
                      " "
                          + p.getType()
                          + " "
                          + p.getLabel()
                          + ((p.getEnd() - p.getStart()) / 1000)
                          + "us");
                }
                System.out.println();
              }
            }
            kernel.render(gl);

            final long now = System.currentTimeMillis();
            final long time = now - last;
            frames++;

            if (time > 1000) { // We update the frames/sec every second
              if (running) {
                final float framesPerSecond = (frames * 1000.0f) / time;
                final int updatesPerMicroSecond =
                    (int)
                        ((framesPerSecond
                                * kernel.range.getGlobalSize(0)
                                * kernel.range.getGlobalSize(0))
                            / 1000000);
                framesPerSecondTextField.setText(String.format("%5.2f", framesPerSecond));
                positionUpdatesPerMicroSecondTextField.setText(
                    String.format("%4d", updatesPerMicroSecond));
              }
              frames = 0;
              last = now;
            }
            gl.glFlush();
          }

          @Override
          public void init(GLAutoDrawable drawable) {
            final GL2 gl = drawable.getGL().getGL2();

            gl.glShadeModel(GLLightingFunc.GL_SMOOTH);
            gl.glEnable(GL.GL_BLEND);
            gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE);
            try {
              final InputStream textureStream = Local.class.getResourceAsStream("particle.jpg");
              final Texture texture = TextureIO.newTexture(textureStream, false, null);
              texture.enable(gl);
            } catch (final IOException e) {
              e.printStackTrace();
            } catch (final GLException e) {
              e.printStackTrace();
            }
          }

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

            final GL2 gl = drawable.getGL().getGL2();
            gl.glViewport(0, 0, width, height);

            ratio = (double) width / (double) height;
          }
        });

    panel.add(canvas, BorderLayout.CENTER);
    frame.getContentPane().add(panel, BorderLayout.CENTER);

    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    frame.pack();
    frame.setVisible(true);

    final FPSAnimator animator = new FPSAnimator(canvas, 100);
    animator.start();
  }
コード例 #17
0
ファイル: Sculptnect.java プロジェクト: rools/Sculptnect
  public Sculptnect() {
    // Set up Kinect
    kinectContext = Freenect.createContext();
    if (kinectContext.numDevices() > 0) {
      kinect = kinectContext.openDevice(0);
    } else {
      System.err.println("Error, no Kinect detected.");
    }

    GLProfile.initSingleton();
    GLProfile glp = GLProfile.getDefault();

    // Set the OpenGL canvas creation parameters
    GLCapabilities caps = new GLCapabilities(glp);
    caps.setRedBits(8);
    caps.setGreenBits(8);
    caps.setBlueBits(8);
    caps.setDepthBits(32);

    final SculptScene scene = new SculptScene();

    final Frame frame = new Frame();
    final GLCanvas canvas = new GLCanvas(caps);
    canvas.addGLEventListener(scene);

    // Add and start a display link
    final FPSAnimator animator = new FPSAnimator(canvas, 60, true);

    frame.add(canvas);
    frame.setSize(800, 800);

    GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice device = environment.getDefaultScreenDevice();
    frame.setUndecorated(true);
    device.setFullScreenWindow(frame);
    frame.setVisible(true);
    canvas.requestFocus();
    animator.start();

    // Add listener to respond to window closing
    frame.addWindowListener(
        new WindowAdapter() {
          @Override
          public void windowClosing(WindowEvent e) {
            super.windowClosing(e);
            exit(0);
          }
        });

    // Add key listener
    canvas.addKeyListener(
        new KeyAdapter() {
          @Override
          public void keyPressed(KeyEvent event) {
            switch (event.getKeyCode()) {
              case KeyEvent.VK_ESCAPE:
                exit(0);
                break;
              case KeyEvent.VK_SPACE:
                dump = true;
                break;
              case 'R':
                if (depthRecord == null) {
                  try {
                    String file = new Date().getTime() + ".raw.gz";
                    depthRecord = new KinectDepthRecord(file);
                    System.out.println("Recording started to " + file);
                  } catch (Exception e) {
                    e.printStackTrace();
                  }
                } else {
                  depthRecord.close();
                  depthRecord = null;
                  System.out.println("Recording stopped");
                }
                break;
              case KeyEvent.VK_LEFT:
                scene.modifyModelRotationY(-1.0f);
                break;
              case KeyEvent.VK_RIGHT:
                scene.modifyModelRotationY(1.0f);
                break;
              case KeyEvent.VK_UP:
                scene.modifyModelRotationX(1.0f);
                break;
              case KeyEvent.VK_DOWN:
                scene.modifyModelRotationX(-1.0f);
                break;
              case 'O':
                scene.removeRandomSphere();
                break;
              case 'K':
                scene.resetModel();
                break;
              case 'F':
                GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment();
                GraphicsDevice device = environment.getDefaultScreenDevice();
                if (device.getFullScreenWindow() != null) {
                  device.setFullScreenWindow(null);
                  frame.dispose();
                  frame.setUndecorated(false);
                  frame.setVisible(true);
                } else {
                  frame.dispose();
                  frame.setUndecorated(true);
                  device.setFullScreenWindow(frame);
                }
                canvas.requestFocus();
                break;
              case 'T':
                scene.toggleTurningMode();
                break;
              case 'I':
                insertKinectPlaceholder(scene);
                break;
              case 'M':
                scene.toggleRenderMode();
                break;
              case 'D':
                scene.dumpMesh();
                break;
            }
          }
        });

    // Create mouse listener
    MouseAdapter mouseAdapter =
        new MouseAdapter() {
          int prevX, prevY;

          @Override
          public void mousePressed(MouseEvent e) {
            prevX = e.getX();
            prevY = e.getY();
          }

          @Override
          public void mouseDragged(MouseEvent e) {
            scene.mouseDragged(prevX, prevY, e.getX(), e.getY());
            prevX = e.getX();
            prevY = e.getY();
          }
        };

    // Add the mouse listener
    canvas.addMouseMotionListener(mouseAdapter);
    canvas.addMouseListener(mouseAdapter);

    if (kinect != null) {
      kinect.setDepthFormat(DepthFormat.D10BIT);
      kinect.startDepth(
          new DepthHandler() {
            @Override
            public void onFrameReceived(FrameMode arg0, ByteBuffer arg1, int arg2) {
              if (dump) {
                // Dump a raw depth image
                arg1.rewind();
                FileOutputStream fos = null;
                try {
                  fos = new FileOutputStream(new Date().getTime() + ".raw");
                  while (arg1.remaining() > 0) {
                    fos.write(arg1.get());
                  }
                  fos.close();
                } catch (Exception e) {
                  e.printStackTrace();
                }
                dump = false;
              }

              scene.updateKinect(arg1);

              if (depthRecord != null) {
                try {
                  depthRecord.addFrame(arg1);
                } catch (Exception e) {
                  e.printStackTrace();
                }
              }
            }
          });
    } else {
      insertKinectPlaceholder(scene);
    }

    // Set up Playstation 2 controller
    Joystick joystick = JoystickManager.getJoystick(Controller.Type.STICK);
    if (joystick != null) {
      joystick.setJoystickListener(scene);
    }
  }
コード例 #18
0
ファイル: Engine.java プロジェクト: JacobNorlin/TRIPPN-BALLS
 public static void main(String[] args) {
   GLCanvas canvas = new GLCanvas();
   canvas.addGLEventListener(new Engine(canvas));
 }
コード例 #19
0
  protected void runTestGL(
      final GLCapabilities caps,
      final FrameLayout frameLayout,
      final boolean twoCanvas,
      final boolean resizeByComp)
      throws InterruptedException, InvocationTargetException {
    final JFrame frame = new JFrame("Bug816: " + this.getTestMethodName());
    Assert.assertNotNull(frame);
    final Container framePane = frame.getContentPane();

    final GLCanvas glCanvas1 = new GLCanvas(caps);
    Assert.assertNotNull(glCanvas1);
    final GLCanvas glCanvas2;
    if (twoCanvas) {
      glCanvas2 = new GLCanvas(caps);
      Assert.assertNotNull(glCanvas2);
    } else {
      glCanvas2 = null;
    }

    final Dimension glcDim = new Dimension(width / 2, height);
    final Dimension frameDim = new Dimension(twoCanvas ? width + 64 : width / 2 + 64, height + 64);

    setComponentSize(null, glCanvas1, glcDim, glCanvas2, glcDim);

    switch (frameLayout) {
      case None:
        {
          framePane.add(glCanvas1);
        }
        break;
      case Flow:
        {
          final Container c = new Container();
          c.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
          c.add(glCanvas1);
          if (twoCanvas) {
            c.add(glCanvas2);
          }
          framePane.add(c);
        }
        break;
      case DoubleBorderCenterSurrounded:
        {
          final Container c = new Container();
          c.setLayout(new BorderLayout());
          c.add(new Button("north"), BorderLayout.NORTH);
          c.add(new Button("south"), BorderLayout.SOUTH);
          c.add(new Button("east"), BorderLayout.EAST);
          c.add(new Button("west"), BorderLayout.WEST);
          if (twoCanvas) {
            final Container c2 = new Container();
            c2.setLayout(new GridLayout(1, 2));
            c2.add(glCanvas1);
            c2.add(glCanvas2);
            c.add(c2, BorderLayout.CENTER);
          } else {
            c.add(glCanvas1, BorderLayout.CENTER);
          }
          framePane.setLayout(new BorderLayout());
          framePane.add(new Button("NORTH"), BorderLayout.NORTH);
          framePane.add(new Button("SOUTH"), BorderLayout.SOUTH);
          framePane.add(new Button("EAST"), BorderLayout.EAST);
          framePane.add(new Button("WEST"), BorderLayout.WEST);
          framePane.add(c, BorderLayout.CENTER);
        }
        break;
      case Box:
        {
          final Container c = new Container();
          c.setLayout(new BoxLayout(c, BoxLayout.X_AXIS));
          c.add(glCanvas1);
          if (twoCanvas) {
            c.add(glCanvas2);
          }
          framePane.add(c);
        }
        break;
      case Split:
        {
          final Dimension sbDim = new Dimension(16, 16);
          final JScrollPane vsp =
              new JScrollPane(
                  ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
                  ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
          {
            final JScrollBar vsb = vsp.getVerticalScrollBar();
            vsb.setPreferredSize(sbDim);
            final BoundedRangeModel model = vsb.getModel();
            model.setMinimum(0);
            model.setMaximum(100);
            model.setValue(50);
            model.setExtent(1);
            vsb.setEnabled(true);
          }
          final JScrollPane hsp =
              new JScrollPane(
                  ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER,
                  ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
          {
            final JScrollBar hsb = hsp.getHorizontalScrollBar();
            hsb.setPreferredSize(sbDim);
            final BoundedRangeModel model = hsb.getModel();
            model.setMinimum(0);
            model.setMaximum(100);
            model.setValue(50);
            model.setExtent(1);
            hsb.setEnabled(true);
          }
          final JSplitPane horizontalSplitPane =
              new JSplitPane(
                  JSplitPane.HORIZONTAL_SPLIT, true, twoCanvas ? glCanvas2 : vsp, glCanvas1);
          horizontalSplitPane.setResizeWeight(0.5);
          final JSplitPane verticalSplitPane =
              new JSplitPane(JSplitPane.VERTICAL_SPLIT, true, horizontalSplitPane, hsp);
          verticalSplitPane.setResizeWeight(0.5);
          framePane.add(verticalSplitPane);
        }
        break;
    }
    final GearsES2 demo1 = new GearsES2(swapInterval);
    glCanvas1.addGLEventListener(demo1);
    if (twoCanvas) {
      final RedSquareES2 demo2 = new RedSquareES2(swapInterval);
      glCanvas2.addGLEventListener(demo2);
    }

    final Animator animator = new Animator();
    animator.add(glCanvas1);
    if (twoCanvas) {
      animator.add(glCanvas2);
    }
    final QuitAdapter quitAdapter = new QuitAdapter();
    new AWTWindowAdapter(new TraceWindowAdapter(quitAdapter), glCanvas1).addTo(frame);

    javax.swing.SwingUtilities.invokeAndWait(
        new Runnable() {
          public void run() {
            if (resizeByComp) {
              frame.pack();
            } else {
              setFrameSize(frame, true, frameDim);
            }
            frame.setVisible(true);
          }
        });
    Assert.assertEquals(true, AWTRobotUtil.waitForVisible(frame, true));
    Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glCanvas1, true));
    if (twoCanvas) {
      Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glCanvas2, true));
    }

    animator.start();
    Assert.assertTrue(animator.isStarted());
    Assert.assertTrue(animator.isAnimating());

    System.err.println(
        "canvas1 pos/siz: "
            + glCanvas1.getX()
            + "/"
            + glCanvas1.getY()
            + " "
            + glCanvas1.getSurfaceWidth()
            + "x"
            + glCanvas1.getSurfaceHeight());
    if (twoCanvas) {
      System.err.println(
          "canvas2 pos/siz: "
              + glCanvas2.getX()
              + "/"
              + glCanvas2.getY()
              + " "
              + glCanvas2.getSurfaceWidth()
              + "x"
              + glCanvas2.getSurfaceHeight());
    }

    Thread.sleep(Math.max(1000, duration / 2));
    if (null != rwsize) {
      final Dimension compRSizeHalf = new Dimension(rwsize.width / 2, rwsize.height);
      final Dimension frameRSizeHalf =
          new Dimension(twoCanvas ? rwsize.width + 64 : rwsize.width / 2 + 64, rwsize.height + 64);
      if (resizeByComp) {
        setComponentSize(frame, glCanvas1, compRSizeHalf, glCanvas2, compRSizeHalf);
      } else {
        setFrameSize(frame, true, frameRSizeHalf);
      }
      System.err.println(
          "resize canvas1 pos/siz: "
              + glCanvas1.getX()
              + "/"
              + glCanvas1.getY()
              + " "
              + glCanvas1.getSurfaceWidth()
              + "x"
              + glCanvas1.getSurfaceHeight());
      if (twoCanvas) {
        System.err.println(
            "resize canvas2 pos/siz: "
                + glCanvas2.getX()
                + "/"
                + glCanvas2.getY()
                + " "
                + glCanvas2.getSurfaceWidth()
                + "x"
                + glCanvas2.getSurfaceHeight());
      }
    }

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

    Assert.assertNotNull(frame);
    Assert.assertNotNull(glCanvas1);
    if (twoCanvas) {
      Assert.assertNotNull(glCanvas2);
    } else {
      Assert.assertNull(glCanvas2);
    }

    Assert.assertNotNull(animator);
    animator.stop();
    Assert.assertFalse(animator.isAnimating());
    Assert.assertFalse(animator.isStarted());

    javax.swing.SwingUtilities.invokeAndWait(
        new Runnable() {
          public void run() {
            frame.setVisible(false);
          }
        });
    Assert.assertEquals(false, frame.isVisible());
    javax.swing.SwingUtilities.invokeAndWait(
        new Runnable() {
          public void run() {
            frame.remove(glCanvas1);
            if (twoCanvas) {
              frame.remove(glCanvas2);
            }
            frame.dispose();
          }
        });
  }
コード例 #20
0
 /** Set the renderer to provide animation. */
 public void setRenderer(GLEventListener renderer) {
   if (_renderer != null) _canvas.removeGLEventListener(_renderer);
   _renderer = renderer;
   if (_renderer != null) _canvas.addGLEventListener(_renderer);
 }
コード例 #21
0
  @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);
    }
  }
コード例 #22
0
ファイル: GLRenderPanel.java プロジェクト: zombiecalypse/CG
  public GLRenderPanel() {
    canvas = new GLCanvas();

    GLEventListener eventListener = new GLRenderContextEventListener(this);
    canvas.addGLEventListener(eventListener);
  }