public static void main(final String[] argv) {
    final Frame frame = new Frame("Cg demo (runtime_ogl_vertex_fragment)");
    final GLCanvas canvas = new GLCanvas();
    canvas.addGLEventListener(new runtime_ogl_vertex_fragment());

    frame.add(canvas);
    frame.setSize(512, 512);
    final Animator animator = new Animator(canvas);
    frame.addWindowListener(
        new WindowAdapter() {
          @Override
          public void windowClosing(@SuppressWarnings("unused") final 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();

    // and all the rest happens in the display function...
  }
Example #2
0
  /**
   * launches the OpenGL window
   *
   * @param GuessesToLoad
   */
  public OpenGLView(GuessModel[] GuessesToLoad) {
    frame = new JFrame("Lesson01");
    GLJPanel gljpanel = new GLJPanel();

    GLlistener = new OpenGLViewListener(GuessesToLoad);

    gljpanel.addGLEventListener(GLlistener);
    frame.add(gljpanel);
    frame.setSize(800, 600);
    final Animator animator = new Animator(gljpanel);
    frame.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            new Thread(
                    new Runnable() {
                      public void run() {
                        animator.stop();
                        System.exit(0);
                      }
                    })
                .start();
          }
        });
    frame.setVisible(true);
    animator.start();
  }
Example #3
0
  public static void main(String[] args) {
    Frame frame = new Frame("Simple JOGL Application");
    GLCanvas canvas = new GLCanvas();

    canvas.addGLEventListener(new Project1());
    frame.add(canvas);
    frame.setSize(600, 600);
    final Animator animator = new Animator(canvas);
    frame.addWindowListener(
        new WindowAdapter() {

          @Override
          public void windowClosing(WindowEvent e) {
            new Thread(
                    new Runnable() {

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

    frame.setVisible(true);
    animator.start();
  }
 public void init(GLAutoDrawable drawable) {
   GL gl = drawable.getGL();
   gl.glMatrixMode(GL.GL_PROJECTION);
   gl.glLoadMatrixd(this._nyar.getGlProjectionMatrix(), 0);
   gl.glEnable(GL.GL_DEPTH_TEST);
   gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
   Animator animator = new Animator(drawable);
   animator.start();
   return;
 }
  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();
  }
Example #6
0
  public void buildFrame() {

    final JTextField text = new JTextField("http://www.botnode.com");

    final BoxLayout layout = new BoxLayout(getContentPane(), BoxLayout.Y_AXIS);
    this.getContentPane().setLayout(layout);
    this.add(text);

    final Gravity gl = new Gravity();
    final GLCanvas canvas = gl.buildCanvas();
    final Animator animator = new Animator(canvas);

    this.add(canvas);
    this.setLocation(400, 400);
    this.setSize(600, 500);
    this.setResizable(false);

    /////////////////////
    this.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();
          }
        });
    animator.start();
  }
Example #7
0
  // Constructora
  public Principal() {

    // Titulo de la ventana y tamaño
    setTitle("Práctica 4");
    setSize(new Dimension(425, 500));
    super.setResizable(false);

    // Contenedor del editor
    panel = this.getContentPane();
    panel.setBackground(Color.blue);
    panel.setLayout(new BorderLayout());

    // Generamos el menu
    menu = new JMenuBar();
    archivo = new JMenu("Archivo");
    nuevo = new JMenuItem("Nuevo");
    salir = new JMenuItem("Salir");
    sobre = new JMenu("Sobre..");
    autores = new JMenuItem("Autores");

    menu.add(archivo);
    archivo.add(nuevo);
    archivo.add(salir);

    menu.add(sobre);
    sobre.add(autores);

    setJMenuBar(menu);

    // Creamos los botones
    this.panelBotones = new JPanel();
    panelBotones.setLayout(new GridLayout(3, 3));
    panel.add(panelBotones, BorderLayout.SOUTH);

    botonDefinirPuntos = new JButton("Definir Perfil");
    botonDefinirPuntos.setVisible(true);
    panelBotones.add(botonDefinirPuntos);

    botonAplicarSplines = new JButton("BSplines");
    botonAplicarSplines.setVisible(true);
    panelBotones.add(botonAplicarSplines);

    botonGenerarMallaRevolucion = new JButton("Revolución");
    botonGenerarMallaRevolucion.setVisible(true);
    panelBotones.add(botonGenerarMallaRevolucion);

    botonGenerarMallaExtrusion = new JButton("Extrusión");
    botonGenerarMallaExtrusion.setVisible(true);
    panelBotones.add(botonGenerarMallaExtrusion);

    botonCambiarModo = new JButton("Cambiar Modo");
    botonCambiarModo.setVisible(true);
    panelBotones.add(botonCambiarModo);

    botonDibujarNormales = new JButton("Activa Normales");
    botonDibujarNormales.setVisible(true);
    panelBotones.add(botonDibujarNormales);

    // Definimos el tipo de malla actual a representar
    this.tipoMalla = 0;

    // Definimos un perfil por defecto
    this.perfil = new ArrayList<PuntoVector3D>();
    this.perfil.add(new PuntoVector3D(250, 330, 0, 1));
    this.perfil.add(new PuntoVector3D(250, 300, 0, 1));
    this.perfil.add(new PuntoVector3D(230, 270, 0, 1));
    this.perfil.add(new PuntoVector3D(200, 240, 0, 1));
    this.perfil.add(new PuntoVector3D(200, 210, 0, 1));
    this.perfil.add(new PuntoVector3D(200, 180, 0, 1));
    this.perfil.add(new PuntoVector3D(200, 150, 0, 1));
    this.perfil.add(new PuntoVector3D(230, 120, 0, 1));

    // Creamos el canvas de dibujo
    canvas = new GLJPanel();
    escena = new GL3D(425, 425);
    canvas.addGLEventListener(escena);
    canvas.addMouseListener(new ManejadorRaton());
    panel.add(canvas, BorderLayout.CENTER);

    // Transformamos el perfil a coordenadas de la escena
    this.perfil = escena.transformarPerfil(this.perfil);
    escena.setPerfil(this.perfil);

    // Animación de la escena
    animacion = new Animator(canvas);
    animacion.start();

    // Entrada de datos desactivada
    entradaDatos = false;

    // Acción por defecto al cerrar la ventana
    this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

    // Evento Oyente para la barra de menu "nuevo"
    nuevo.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent e) {
            perfil = new ArrayList<PuntoVector3D>();
            escena.actualizarPerfil(tipoMalla, perfil);
          }
        });

    // Evento Oyente para la barra de menu "Autores"
    autores.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent e) {
            JOptionPane.showMessageDialog(
                null, "Iván Romero\nPedro Sánchez", "Autores", JOptionPane.INFORMATION_MESSAGE);
          }
        });

    // Evento Oyente para el boton "Definir Perfil"
    botonDefinirPuntos.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent e) {
            perfil = new ArrayList<PuntoVector3D>();
            escena.setPerfil(perfil);
            entradaDatos = true;
          }
        });

    // Evento Oyente para el boton "Aplicar Splines"
    botonAplicarSplines.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent e) {

            String dato =
                JOptionPane.showInputDialog(
                    null,
                    "Numero de puntos de control. Rango[" + perfil.size() + "...N]",
                    "Datos de Entrada",
                    1);
            if (dato != null) {
              int num = Integer.parseInt(dato);
              perfil = new Calculos().calculaPuntosBSplines(perfil, num);
              if (perfil.size() > num) {
                ArrayList<PuntoVector3D> perfilAux = new ArrayList<PuntoVector3D>();
                for (int i = 0; i < num - 2; i++) {
                  perfilAux.add(perfil.get(i));
                }
                perfil = (ArrayList<PuntoVector3D>) perfilAux.clone();
              }
              escena.setPerfil(perfil);
              entradaDatos = false;
            }
          }
        });

    // Evento Oyente para el boton "Malla Revolución"
    botonGenerarMallaRevolucion.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent e) {

            // String datoNumVertices = "4";
            String datoAng = JOptionPane.showInputDialog("Ángulo de rotación: ", "0.15");
            if (datoAng != null) {

              Object[] opciones = {"3", "4"};
              int eleccion =
                  JOptionPane.showOptionDialog(
                      null,
                      "Número de Vértices de la cara: ",
                      "Datos de Entrada",
                      JOptionPane.DEFAULT_OPTION,
                      JOptionPane.WARNING_MESSAGE,
                      null,
                      opciones,
                      opciones[0]);

              int numVerticesCara = Integer.parseInt((String) opciones[eleccion]);
              double anguloRadianes = Double.parseDouble(datoAng);

              mallaActual = new MallaPorRevolucion(perfil, numVerticesCara, anguloRadianes);
              //  mallaRevolucion = new MallaPorRevolucion(perfil, numVerticesCara, anguloRadianes);

              //  escena.actualizarMallaRev(2, mallaRevolucion);
              escena.actualizarMalla(2, mallaActual);
              escena.setGenerado(true);
              entradaDatos = false;
            }
          }
        });

    // Evento Oyente para el boton "Malla Extrusión"
    botonGenerarMallaExtrusion.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent e) {

            String SnP =
                JOptionPane.showInputDialog(
                    "Número de lados que aproximan la sección del toroide", "10");
            String SnQ = JOptionPane.showInputDialog("Número de capas del toroide", "50");
            String Sr1 = JOptionPane.showInputDialog("Radio del toro", "150");
            String Sr2 = JOptionPane.showInputDialog("Radio de la sección del toro", "20");

            int nP = Integer.parseInt(SnP);
            int nQ = Integer.parseInt(SnQ);
            float r1 = Float.parseFloat(Sr1);
            float r2 = Float.parseFloat(Sr2);

            mallaActual = new Toro(nP, nQ, r1, r2);
            escena.actualizarMalla(3, mallaActual);

            escena.setGenerado(true);
            entradaDatos = false;
          }
        });

    // Evento Oyente para el botón "Cambiar Modo"
    botonCambiarModo.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent e) {

            Object[] opciones = {"Puntos", "Líneas", "Sólidos"};
            int eleccion =
                JOptionPane.showOptionDialog(
                    null,
                    "Cambiar Modo de Representación a: ",
                    "Datos de Entrada",
                    JOptionPane.DEFAULT_OPTION,
                    JOptionPane.WARNING_MESSAGE,
                    null,
                    opciones,
                    opciones[0]);

            mallaActual.setTipoMalla(eleccion);
          }
        });

    // Evento Oyente para el botón "Dibujar Normales"
    botonDibujarNormales.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent e) {

            if (botonDibujarNormales.getText().equals("Activa Normales")) {
              botonDibujarNormales.setText("DesactivaNormales");
              mallaActual.setNormales(true);
            } else {
              botonDibujarNormales.setText("Activa Normales");
              mallaActual.setNormales(false);
            }
          }
        });

    // Añadimos un evento para la acción de salida
    addWindowListener(
        new WindowAdapter() {

          @Override
          public void windowClosing(WindowEvent e) {
            new Thread(
                    new Runnable() {

                      public void run() {
                        animacion.stop();
                        System.exit(0);
                      }
                    })
                .start();
          }
        });
  }
Example #8
0
 // Start/stop animation
 public void setAnimation(boolean on) {
   if (on) animator.start();
   else animator.stop();
 }
Example #9
0
 // Check if animation is proceeding
 public boolean isAnimated() {
   return animator.isAnimating();
 }