Пример #1
0
  // ------------------------------------------------------------
  // GLEventListener
  public void init(GLAutoDrawable drawable) {
    if (debugging) drawable.setGL(new DebugGL(drawable.getGL()));

    try {
      // Specify new projection for this window
      init(drawable.getGL());
    } catch (GLException e) {
      e.printStackTrace();
    }
  }
Пример #2
0
  /*
   * Initialize z-buffer, projection matrix, light source, and lighting model.
   * Do not specify a material property here.
   */
  public void init(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();
    glut = new GLUT();
    //
    float position[] = {0.0f, 3.0f, 3.0f, 0.0f};
    float local_view[] = {0.0f};

    gl.glEnable(GL.GL_DEPTH_TEST);
    gl.glDepthFunc(GL.GL_LESS);

    gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_POSITION, position, 0);
    gl.glLightModelfv(GL2.GL_LIGHT_MODEL_LOCAL_VIEWER, local_view, 0);

    gl.glFrontFace(GL.GL_CW);
    gl.glEnable(GL2.GL_LIGHTING);
    gl.glEnable(GL2.GL_LIGHT0);
    gl.glEnable(GL2.GL_AUTO_NORMAL);
    gl.glEnable(GL2.GL_NORMALIZE);
    gl.glEnable(GL2.GL_FOG);
    {
      float fogColor[] = {0.5f, 0.5f, 0.5f, 1.0f};

      fogMode = GL2.GL_EXP;
      gl.glFogi(GL2.GL_FOG_MODE, fogMode);
      gl.glFogfv(GL2.GL_FOG_COLOR, fogColor, 0);
      gl.glFogf(GL2.GL_FOG_DENSITY, 0.35f);
      gl.glHint(GL2.GL_FOG_HINT, GL.GL_DONT_CARE);

      gl.glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
    }
  }
 public void display(GLAutoDrawable drawable) {
   GL gl = drawable.getGL();
   synchronized (this._camera) {
     try {
       gl.glClear(
           GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); // Clear the buffers for new frame.
       NyARGLDrawUtil.drawBackGround(gl, this._camera.getSourceImage(), 1.0);
       this._nyar.update(this._camera);
       if (this._nyar.isExistMarker(this.ids[0])) {
         gl.glMatrixMode(GL.GL_MODELVIEW);
         gl.glPushMatrix();
         gl.glLoadMatrixd(this._nyar.getGlMarkerMatrix(this.ids[0]), 0);
         NyARGLDrawUtil.drawColorCube(gl, 40);
         gl.glPopMatrix();
       }
       if (this._nyar.isExistMarker(this.ids[1])) {
         gl.glMatrixMode(GL.GL_MODELVIEW);
         gl.glPushMatrix();
         gl.glLoadMatrixd(this._nyar.getGlMarkerMatrix(this.ids[1]), 0);
         NyARGLDrawUtil.drawColorCube(gl, 40);
         gl.glPopMatrix();
       }
       Thread.sleep(1);
     } catch (Exception e) {
       e.printStackTrace();
     }
   }
 }
Пример #4
0
  public void display(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();
    //
    gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
    gl.glPushMatrix();
    gl.glRotatef(20.0f, 1.0f, 0.0f, 0.0f);

    gl.glPushMatrix();
    gl.glTranslatef(-0.75f, 0.5f, 0.0f);
    gl.glRotatef(90.0f, 1.0f, 0.0f, 0.0f);

    glut.glutSolidTorus(0.275f, 0.85f, 20, 20);
    gl.glPopMatrix();

    gl.glPushMatrix();
    gl.glTranslatef(-0.75f, -0.5f, 0.0f);
    gl.glRotatef(270.0f, 1.0f, 0.0f, 0.0f);
    glut.glutSolidCone(1.0f, 2.0f, 20, 20);
    gl.glPopMatrix();

    gl.glPushMatrix();
    gl.glTranslatef(0.75f, 0.0f, -1.0f);
    glut.glutSolidSphere(1.0f, 20, 20);
    gl.glPopMatrix();

    gl.glPopMatrix();
    gl.glFlush();
  }
Пример #5
0
  @Override
  public void display(GLAutoDrawable gLDrawable) {
    final GL2 gl = gLDrawable.getGL().getGL2();
    gl.glClear(GL.GL_COLOR_BUFFER_BIT);
    gl.glClear(GL.GL_DEPTH_BUFFER_BIT);
    gl.glLoadIdentity();
    gl.glTranslatef(0.0f, 0.0f, -5.0f);

    // rotate about the three axes
    gl.glRotatef(rotateT, 1.0f, 0.0f, 0.0f);
    gl.glRotatef(rotateT, 0.0f, 1.0f, 0.0f);
    gl.glRotatef(rotateT, 0.0f, 0.0f, 1.0f);

    // Draw A Quad
    gl.glBegin(GL2.GL_QUADS);
    gl.glColor3f(0.0f, 1.0f, 1.0f); // set the color of the quad
    gl.glVertex3f(-1.0f, 1.0f, 0.0f); // Top Left
    gl.glVertex3f(1.0f, 1.0f, 0.0f); // Top Right
    gl.glVertex3f(1.0f, -1.0f, 0.0f); // Bottom Right
    gl.glVertex3f(-1.0f, -1.0f, 0.0f); // Bottom Left
    // Done Drawing The Quad
    gl.glEnd();

    // increasing rotation for the next iteration
    rotateT += 0.2f;
  }
Пример #6
0
 public void reshape(GLAutoDrawable drawable, int x, int y, int w, int h) {
   GL2 gl = drawable.getGL().getGL2();
   //
   gl.glViewport(0, 0, w, h);
   gl.glMatrixMode(GL2.GL_PROJECTION);
   gl.glLoadIdentity();
   if (w <= (h * 3))
     gl.glOrtho(
         -6.0,
         6.0,
         -2.0 * ((float) h * 3) / (float) w,
         2.0 * ((float) h * 3) / (float) w,
         0.0,
         10.0);
   else
     gl.glOrtho(
         -6.0 * (float) w / ((float) h * 3), //
         6.0 * (float) w / ((float) h * 3),
         -2.0,
         2.0,
         0.0,
         10.0);
   gl.glMatrixMode(GL2.GL_MODELVIEW);
   gl.glLoadIdentity();
 }
Пример #7
0
 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
   try {
     // Specify new projection for this window
     projection(drawable.getGL(), width, height);
   } catch (GLException e) {
     e.printStackTrace();
   }
 }
Пример #8
0
 public void display(GLAutoDrawable drawable) {
   try {
     // Draw the contents of the window (abstract method)
     draw(drawable.getGL());
   } catch (GLException e) {
     e.printStackTrace();
   }
 }
Пример #9
0
  public void reshape(GLAutoDrawable drawable, int x, int y, int w, int h) {
    GL gl = drawable.getGL();

    gl.glViewport(0, 0, w, h);
    gl.glMatrixMode(GL.GL_PROJECTION);
    gl.glLoadIdentity();
    gl.glOrtho(0, w, 0, h, -1.0, 1.0);
    gl.glMatrixMode(GL.GL_MODELVIEW);
  }
Пример #10
0
 @Override
 public void init(GLAutoDrawable glDrawable) {
   GL2 gl = glDrawable.getGL().getGL2();
   gl.glShadeModel(GLLightingFunc.GL_SMOOTH);
   gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
   gl.glClearDepth(1.0f);
   gl.glEnable(GL.GL_DEPTH_TEST);
   gl.glDepthFunc(GL.GL_LEQUAL);
   gl.glHint(GL2ES1.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);
 }
Пример #11
0
 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;
 }
Пример #12
0
 @Override
 public void reshape(GLAutoDrawable gLDrawable, int x, int y, int width, int height) {
   GL2 gl = gLDrawable.getGL().getGL2();
   final float aspect = (float) width / (float) height;
   gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
   gl.glLoadIdentity();
   final float fh = 0.5f;
   final float fw = fh * aspect;
   gl.glFrustumf(-fw, fw, -fh, fh, 1.0f, 1000.0f);
   gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
   gl.glLoadIdentity();
 }
Пример #13
0
 public void reshape(GLAutoDrawable drawable, int x, int y, int w, int h) {
   GL2 gl = drawable.getGL().getGL2();
   //
   gl.glViewport(0, 0, w, h);
   gl.glMatrixMode(GL2.GL_PROJECTION);
   gl.glLoadIdentity();
   if (w <= h)
     gl.glOrtho(-2.5, 2.5, -2.5 * (float) h / (float) w, 2.5 * (float) h / (float) w, -10.0, 10.0);
   else
     gl.glOrtho(-2.5 * (float) w / (float) h, 2.5 * (float) w / (float) h, -2.5, 2.5, -10.0, 10.0);
   gl.glMatrixMode(GL2.GL_MODELVIEW);
 }
Пример #14
0
  public void display(GLAutoDrawable drawable) {
    GL gl = drawable.getGL();

    gl.glClear(GL.GL_COLOR_BUFFER_BIT);

    gl.glRasterPos2i(1, 1);
    gl.glDrawPixels(
        dim.width,
        dim.height, //
        GL.GL_RGB,
        GL.GL_UNSIGNED_BYTE,
        pixels);

    gl.glFlush();
  }
Пример #15
0
  /*
   * display() draws 5 teapots at different z positions.
   */
  public void display(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();
    //
    gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
    //
    if (fogMode == GL2.GL_EXP2) {
      gl.glFogf(GL2.GL_FOG_START, 1.0f);
      gl.glFogf(GL2.GL_FOG_END, 5.0f);
    }
    gl.glFogi(GL2.GL_FOG_MODE, fogMode);

    renderRedTeapot(gl, -4.0f, -0.5f, -1.0f);
    renderRedTeapot(gl, -2.0f, -0.5f, -2.0f);
    renderRedTeapot(gl, 0.0f, -0.5f, -3.0f);
    renderRedTeapot(gl, 2.0f, -0.5f, -4.0f);
    renderRedTeapot(gl, 4.0f, -0.5f, -5.0f);
    gl.glFlush();
  }
Пример #16
0
  /*
   * Initialize material property and light source.
   */
  public void init(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();
    //
    float light_ambient[] = {0.0f, 0.0f, 0.0f, 1.0f};
    float light_diffuse[] = {1.0f, 0.0f, 1.0f, 1.0f};
    float light_specular[] = {1.0f, 0.0f, 1.0f, 1.0f};
    /* light_position is NOT default value */
    float light_position[] = {1.0f, 1.0f, 1.0f, 0.0f};

    gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_SPECULAR, light_ambient, 0);
    gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_DIFFUSE, light_diffuse, 0);
    gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_SPECULAR, light_specular, 0);
    gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_POSITION, light_position, 0);

    gl.glEnable(GL2.GL_LIGHTING);
    gl.glEnable(GL2.GL_LIGHT0);
    gl.glDepthFunc(GL.GL_LESS);
    gl.glEnable(GL.GL_DEPTH_TEST);
  }
Пример #17
0
  public void init(GLAutoDrawable drawable) {
    GL gl = drawable.getGL();

    float m[] = {
      0.0f, 1.0f, 0.0f, 0.0f, //
      0.0f, 0.0f, 1.0f, 0.0f, //
      1.0f, 0.0f, 0.0f, 0.0f, //
      0.0f, 0.0f, 0.0f, 1.0f
    };

    pixels = readImage("Data/leeds.bin", dim);
    System.out.println(pixels.toString());

    gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1);
    gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

    gl.glMatrixMode(GL.GL_COLOR);
    gl.glLoadMatrixf(m, 0);
    gl.glMatrixMode(GL.GL_MODELVIEW);
  }
Пример #18
0
  public void init(GLAutoDrawable drawable) {
    this._gl = drawable.getGL();
    this._gl.glEnable(GL.GL_DEPTH_TEST);
    NyARGLDrawUtil.setFontStyle("SansSerif", Font.BOLD, 36);
    NyARGLDrawUtil.setFontColor(Color.RED);
    this._gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    // NyARToolkitの準備
    try {
      // プロセッサの準備
      this._processor =
          new MarkerProcessor(this._ar_param, this._cap_image.getBufferType(), this._glnya);
      this._processor.setARCodeTable(_code_table, 16, 80.0);

      // カメラパラメータの計算
      NyARGLUtil.toCameraFrustumRH(this._ar_param, 1.0, 10, 10000, this._camera_projection);
      // キャプチャ開始
      this._capture.start();
    } catch (Exception e) {
      e.printStackTrace();
    }
    this._animator = new Animator(drawable);
    this._animator.start();
    return;
  }
Пример #19
0
 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
   GL gl = drawable.getGL();
   gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
   gl.glViewport(0, 0, width, height);
   return;
 }
 public void display(GLAutoDrawable glAutoDrawable) {
   glAutoDrawable.getGL().glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
 }
    public void init(GLAutoDrawable glAutoDrawable) {
      StringBuilder sb = new StringBuilder();

      sb.append(gov.nasa.worldwind.Version.getVersion() + "\n");

      sb.append("\nSystem Properties\n");
      sb.append("Processors: " + Runtime.getRuntime().availableProcessors() + "\n");
      sb.append("Free memory: " + Runtime.getRuntime().freeMemory() + " bytes\n");
      sb.append("Max memory: " + Runtime.getRuntime().maxMemory() + " bytes\n");
      sb.append("Total memory: " + Runtime.getRuntime().totalMemory() + " bytes\n");

      for (Map.Entry prop : System.getProperties().entrySet()) {
        sb.append(prop.getKey() + " = " + prop.getValue() + "\n");
      }

      GL gl = glAutoDrawable.getGL();

      sb.append("\nOpenGL Values\n");

      String oglVersion = gl.glGetString(GL.GL_VERSION);
      sb.append("OpenGL version: " + oglVersion + "\n");

      String oglVendor = gl.glGetString(GL.GL_VENDOR);
      sb.append("OpenGL vendor: " + oglVendor + "\n");

      String oglRenderer = gl.glGetString(GL.GL_RENDERER);
      sb.append("OpenGL renderer: " + oglRenderer + "\n");

      int[] intVals = new int[2];
      for (Attr attr : attrs) {
        sb.append(attr.name).append(": ");

        if (attr.attr instanceof Integer) {
          gl.glGetIntegerv((Integer) attr.attr, intVals, 0);
          sb.append(intVals[0]).append(intVals[1] > 0 ? ", " + intVals[1] : "");
        }

        sb.append("\n");
      }

      String extensionString = gl.glGetString(GL.GL_EXTENSIONS);
      String[] extensions = extensionString.split(" ");
      sb.append("Extensions\n");
      for (String ext : extensions) {
        sb.append("    " + ext + "\n");
      }

      sb.append("\nJOGL Values\n");
      String pkgName = "javax.media.opengl";
      try {
        getClass().getClassLoader().loadClass(pkgName + ".GL");

        Package p = Package.getPackage(pkgName);
        if (p == null) {
          sb.append("WARNING: Package.getPackage(" + pkgName + ") is null\n");
        } else {
          sb.append(p + "\n");
          sb.append("Specification Title = " + p.getSpecificationTitle() + "\n");
          sb.append("Specification Vendor = " + p.getSpecificationVendor() + "\n");
          sb.append("Specification Version = " + p.getSpecificationVersion() + "\n");
          sb.append("Implementation Vendor = " + p.getImplementationVendor() + "\n");
          sb.append("Implementation Version = " + p.getImplementationVersion() + "\n");
        }
      } catch (ClassNotFoundException e) {
        sb.append("Unable to load " + pkgName + "\n");
      }

      this.outputArea.setText(sb.toString());
    }