Beispiel #1
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);
  }
 private GLCanvas createGLCanvas(final GLCapabilitiesImmutable caps, final Dimension size) {
   final GLCanvas canvas = new GLCanvas(caps);
   canvas.setSize(size);
   canvas.setPreferredSize(size);
   canvas.setMinimumSize(size);
   return canvas;
 }
  private void initGL() {
    GLProfile profile = GLProfile.getDefault();

    GLCapabilities capabilities = new GLCapabilities(profile);

    canvas = new GLCanvas(capabilities);

    canvas.setSize(imageWidth, imageHeight);

    canvas.addGLEventListener(this);
  }
  @Override
  public GLAutoDrawable createGLAutoDrawable(
      final QuitAdapter quitAdapter,
      final GLCapabilitiesImmutable caps,
      final int width,
      final int height)
      throws InterruptedException, InvocationTargetException {
    final GLAutoDrawable glad;
    if (caps.isOnscreen()) {
      final Frame frame = new Frame("Gears AWT Test");
      Assert.assertNotNull(frame);

      final GLCanvas glCanvas = new GLCanvas(caps);
      Assert.assertNotNull(glCanvas);
      final Dimension glc_sz = new Dimension(width, height);
      glCanvas.setMinimumSize(glc_sz);
      glCanvas.setPreferredSize(glc_sz);
      glCanvas.setSize(glc_sz);
      glad = glCanvas;

      new AWTWindowAdapter(new TraceWindowAdapter(quitAdapter), glCanvas).addTo(frame);

      frame.setLayout(new BorderLayout());
      frame.add(glCanvas, BorderLayout.CENTER);
      javax.swing.SwingUtilities.invokeAndWait(
          new Runnable() {
            public void run() {
              frame.pack();
              frame.setVisible(true);
            }
          });
    } else {
      final GLDrawableFactory factory = GLDrawableFactory.getFactory(caps.getGLProfile());
      glad = factory.createOffscreenAutoDrawable(null, caps, null, width, height);
      Assert.assertNotNull(glad);
    }
    return glad;
  }