/**
   * Implement stereo using the stereo-enabled graphics device. The mode has an effect only if the
   * display device implements stereo.
   *
   * @param dc the current draw context.
   */
  protected void doDrawToStereoDevice(DrawContext dc) {
    GL2 gl = dc.getGL().getGL2(); // GL initialization checks for GL2 compatibility.
    View dcView = dc.getView();

    // Draw the left eye
    if (this.isSwapEyes()) gl.glDrawBuffer(GL2.GL_BACK_RIGHT);
    else gl.glDrawBuffer(GL2.GL_BACK_LEFT);

    gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
    super.draw(dc);

    // Move the view to the right eye
    Angle viewHeading = dcView.getHeading();
    dcView.setHeading(dcView.getHeading().subtract(this.getFocusAngle()));
    dcView.apply(dc);

    // Draw the right eye
    try {
      if (this.isSwapEyes()) gl.glDrawBuffer(GL2.GL_BACK_LEFT);
      else gl.glDrawBuffer(GL2.GL_BACK_RIGHT);

      gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
      super.draw(dc);
    } finally {
      // Restore the original view heading
      dcView.setHeading(viewHeading);
      dcView.apply(dc);
    }
  }
  /**
   * Implement no stereo ("Mono") while using a stereo device.
   *
   * <p>Note that this method draws the image twice, once to each of the left and right eye buffers,
   * even when stereo is not in effect. This is to prevent the stereo device from drawing blurred
   * scenes.
   *
   * @param dc the current draw context.
   */
  protected void doDrawStereoNone(DrawContext dc) {
    // If running on a stereo device but want to draw a normal image, both buffers must be filled or
    // the
    // display will be blurry.

    GL2 gl = dc.getGL().getGL2(); // GL initialization checks for GL2 compatibility.

    gl.glDrawBuffer(GL2.GL_BACK_LEFT);
    gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
    super.draw(dc);

    gl.glDrawBuffer(GL2.GL_BACK_RIGHT);
    gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
    super.draw(dc);
  }
示例#3
0
文件: Test.java 项目: JibouLBF/Fablab
  @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;
  }
示例#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
  public void display(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();
    //
    gl.glClear(GL.GL_COLOR_BUFFER_BIT);

    if (derefMethod == DRAWARRAY) {
      gl.glDrawArrays(GL2.GL_TRIANGLES, 0, 6);
    } else if (derefMethod == ARRAYELEMENT) {
      gl.glBegin(GL2.GL_TRIANGLES);
      gl.glArrayElement(2);
      gl.glArrayElement(3);
      gl.glArrayElement(5);
      gl.glEnd();
    } else if (derefMethod == DRAWELEMENTS) {
      int indices[] = new int[] {0, 1, 3, 4};
      if (indicesBuf == null) {
        indicesBuf = GLBuffers.newDirectIntBuffer(indices.length);
        indicesBuf.put(indices);
      }
      indicesBuf.rewind();
      gl.glDrawElements(GL2.GL_POLYGON, 4, GL2.GL_UNSIGNED_INT, indicesBuf);
    }
    gl.glFlush();

    // gl calls from C example's mouse routine are moved here
    if (setupMethod == INTERLEAVED) setupInterleave(gl);
    else if (setupMethod == POINTER) setupPointers(gl);
  }
示例#6
0
  public void init(GLAutoDrawable drawable) {
    drawable.setGL(new DebugGL2(drawable.getGL().getGL2()));
    final GL2 gl = drawable.getGL().getGL2();
    // drawable.getGL().getGL2();
    gl.glViewport(0, 0, SCREENW, SCREENH);

    // Clear color buffer with black
    // gl.glClearColor(1.0f, 0.5f, 1.0f, 1.0f);
    gl.glClearColor(.0f, .0f, .0f, 1.0f);
    gl.glClearDepth(1.0f);
    gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
    gl.glEnable(GL2.GL_DEPTH_TEST);
    gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1);

    gl.glCreateShader(GL2GL3.GL_VERTEX_SHADER);
    shader.init(gl);
    int programName = shader.getID();
    gl.glBindAttribLocation(programName, Object3D.VERTEXPOSITION, "inposition");
    gl.glBindAttribLocation(programName, Object3D.VERTEXCOLOR, "incolor");
    gl.glBindAttribLocation(programName, Object3D.VERTEXNORMAL, "innormal");
    gl.glBindAttribLocation(programName, Object3D.VERTEXTEXCOORD0, "intexcoord0");
    shader.link(gl);
    uniformMat = gl.glGetUniformLocation(programName, "mat");
    uniformLight = gl.glGetUniformLocation(programName, "lightdir");
    gl.glUseProgram(programName);
    gl.glUniform3f(uniformLight, 0f, 10f, -10f);
    obj.init(gl, mats, programName);
    gl.glUseProgram(0);
  }
示例#7
0
 public void display(GLAutoDrawable drawable) {
   GL2 gl = drawable.getGL().getGL2();
   //
   gl.glClear(GL.GL_COLOR_BUFFER_BIT);
   gl.glColor3f(1.0f, 1.0f, 1.0f);
   gl.glCallList(startList);
   gl.glCallList(startList + 1);
   gl.glFlush();
 }
  /**
   * Implement stereo using the red-blue anaglyph technique.
   *
   * @param dc the current draw context.
   */
  protected void doDrawStereoRedBlue(DrawContext dc) {
    GL2 gl = dc.getGL().getGL2(); // GL initialization checks for GL2 compatibility.
    View dcView = dc.getView();

    // Draw the left eye
    if (this.isSwapEyes()) {
      if (this.isHardwareStereo()) gl.glDrawBuffer(GL2.GL_BACK_RIGHT);
      gl.glColorMask(false, true, true, true); // right eye in green/blue
    } else {
      if (this.isHardwareStereo()) gl.glDrawBuffer(GL2.GL_BACK_LEFT);
      gl.glColorMask(true, false, false, true); // left eye in red only
    }

    if (this.isHardwareStereo()) gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);

    super.draw(dc);

    // Move the view to the right eye
    Angle viewHeading = dcView.getHeading();
    dcView.setHeading(dcView.getHeading().subtract(this.getFocusAngle()));
    dcView.apply(dc);

    // Draw the right eye frame green and blue only
    try {
      gl.glClear(GL.GL_DEPTH_BUFFER_BIT);
      if (this.isSwapEyes()) {
        if (this.isHardwareStereo()) gl.glDrawBuffer(GL2.GL_BACK_RIGHT);
        gl.glColorMask(true, false, false, true); // right eye in red only
      } else {
        if (this.isHardwareStereo()) gl.glDrawBuffer(GL2.GL_BACK_LEFT);
        gl.glColorMask(false, true, true, true); // right eye in green/blue
      }

      if (this.isHardwareStereo()) gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
      super.draw(dc);
    } finally {
      // Restore the original view heading
      dcView.setHeading(viewHeading);
      dcView.apply(dc);
      gl.glColorMask(true, true, true, true);
    }
  }
示例#9
0
  @Override
  public void display(GLAutoDrawable glAutoDrawable) {
    gl = glAutoDrawable.getGL().getGL2();
    gl.glClear(GL.GL_COLOR_BUFFER_BIT);

    // Fonts draw selves at the current raster position
    gl.glRasterPos2f(right - (right + 2.0f), bottom + 1);
    caption = "Please wait... drawing frames";
    glut.glutBitmapString(GLUT.BITMAP_HELVETICA_18, caption);

    drawByLevel();

    gl.glFlush();
  }
示例#10
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(45.0f, 0.0f, 0.0f, 1.0f);

    gl.glTexGeni(GL2.GL_S, GL2.GL_TEXTURE_GEN_MODE, currentGenMode);
    gl.glTexGendv(GL2.GL_S, currentPlane, currentCoeff, 0);

    gl.glBindTexture(GL2.GL_TEXTURE_1D, texName[0]);
    glut.glutSolidTeapot(2.0f);
    gl.glPopMatrix();
    gl.glFlush();
  }
示例#11
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();
  }
示例#12
0
  public void display(GLAutoDrawable drawable) {
    final GL2 gl = drawable.getGL().getGL2();
    gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
    mats.glMatrixMode(GL2.GL_MODELVIEW);
    mats.glLoadIdentity();
    mats.glTranslatef(0f, 0f, -2.0f);
    // t = t+0.5f;
    t = 40f;
    mats.glRotatef(t, 0f, 1f, 0f);
    mats.glMatrixMode(GL2.GL_PROJECTION);
    mats.glLoadIdentity();
    mats.glFrustumf(-1f, 1f, -1f, 1f, 1f, 100f);
    mats.update();
    gl.glUseProgram(shader.getID());
    gl.glUniformMatrix4fv(uniformMat, 3, false, mats.glGetPMvMviMatrixf());

    obj.display(gl, mats);
    gl.glFlush();
    gl.glUseProgram(0);
  }
  public void draw() {
    // Clear GL state
    gl.glDisable(GL_LIGHTING);
    gl.glDisable(GL_DEPTH);
    gl.glMatrixMode(GL_MODELVIEW);
    gl.glPushMatrix();
    gl.glLoadIdentity();
    gl.glMatrixMode(GL_PROJECTION);
    gl.glPushMatrix();
    gl.glLoadIdentity();

    gl.glClearColor(0.8f, 0.2f, 0.2f, 1.0f);

    gl.glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);

    gl.glPointSize(1.0f);

    // Set the viewport
    glu.gluOrtho2D(xMin, xMax, yMin, yMax);

    gl.glBegin(GL_POINTS);

    for (int x = (int) (xMin); x < xMax; x++)
      for (int y = (int) (yMin); y < yMax; y++) {
        gl.glColor3d(viewPort[x][y].r, viewPort[x][y].g, viewPort[x][y].b);
        gl.glVertex2d(x + 0.5, y + 0.5);
      }

    gl.glEnd();

    // Restore state
    gl.glMatrixMode(GL_MODELVIEW);
    gl.glPopMatrix();
    gl.glMatrixMode(GL_PROJECTION);
    gl.glPopMatrix();

    gl.glEnable(GL_LIGHTING);
    gl.glEnable(GL_DEPTH);
  }
示例#14
0
  /*
   * display() draws a triangle at an angle.
   */
  public void display(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();
    //
    gl.glClear(GL.GL_COLOR_BUFFER_BIT);

    if (key != null)
      switch (key.getKeyChar()) {
        case 'c':
          gl.glFogi(GL2.GL_FOG_COORDINATE_SOURCE, GL2.GL_FRAGMENT_DEPTH);
          break;
        case 'C':
          gl.glFogi(GL2.GL_FOG_COORDINATE_SOURCE, GL2.GL_FOG_COORDINATE);
          break;

        case 'b':
          gl.glMatrixMode(GL2.GL_MODELVIEW);
          gl.glTranslatef(0.0f, 0.0f, -0.25f);
          break;
        case 'f':
          gl.glMatrixMode(GL2.GL_MODELVIEW);
          gl.glTranslatef(0.0f, 0.0f, 0.25f);
          break;
        default:
          break;
      }

    gl.glColor3f(1.0f, 0.75f, 0.0f);
    gl.glBegin(GL2.GL_TRIANGLES);
    gl.glFogCoordf(f1);
    gl.glVertex3f(2.0f, -2.0f, 0.0f);
    gl.glFogCoordf(f2);
    gl.glVertex3f(-2.0f, 0.0f, -5.0f);
    gl.glFogCoordf(f3);
    gl.glVertex3f(0.0f, 2.0f, -10.0f);
    gl.glEnd();

    gl.glFlush();
  }
示例#15
0
 protected void drawThis(GL2 gl) {
   gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
   configureGL(gl);
   tunnel.draw(gl, distortion);
   field.draw(gl);
 }
示例#16
0
  /** Called back by the animator to perform rendering. */
  @Override
  public void display(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2(); // get the OpenGL 2 graphics context
    gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear color and depth buffers

    for (int i = 0; i < stars.length; i++) {
      // Reset the view (x, y, z axes back to normal)
      gl.glLoadIdentity();
      gl.glTranslatef(0.0f, 0.0f, z);

      // The stars are texture quad square drawn on x-y plane and
      // distributed on on x-z plane around the y-axis

      // Initial 90 degree tile in the x-axis, y-axis pointing out of screen
      gl.glRotatef(tilt, 1.0f, 0.0f, 0.0f);
      // Rotate about y-axis (pointing out of screen), initial angle is 0
      gl.glRotatef(stars[i].angle, 0.0f, 1.0f, 0.0f);
      // Translate about the x-axis (pointing right) to its current distance
      gl.glTranslatef(stars[i].distance, 0.0f, 0.0f);

      // The stars have initial angle of 0, and initial distance linearly
      // distributed between 0 and 5.0f

      // Rotate the axes back, so that z-axis is again facing us, to ensure that
      // the quad (with texture) on x-y plane is facing us
      gl.glRotatef(-stars[i].angle, 0.0f, 1.0f, 0.0f);
      gl.glRotatef(-tilt, 1.0f, 0.0f, 0.0f);

      // Take note that without the two rotations and undo, there is only one
      // translation along the x-axis
      // Matrix operation is non-commutative. That is, AB != BA.
      // Hence, ABCB'A' != C

      // Draw the star, which spins on the z axis (pointing out of the screen)
      gl.glRotatef(starSpinAngle, 0.0f, 0.0f, 1.0f);
      // Set the star's color using bytes (why bytes? not float or int?)
      gl.glColor4ub(stars[i].r, stars[i].g, stars[i].b, (byte) 255);
      gl.glBegin(GL_QUADS);
      // draw a square on x-y plane
      gl.glTexCoord2f(textureCoordLeft, textureCoordBottom);
      gl.glVertex3f(-1.0f, -1.0f, 0.0f);
      gl.glTexCoord2f(textureCoordRight, textureCoordBottom);
      gl.glVertex3f(1.0f, -1.0f, 0.0f);
      gl.glTexCoord2f(textureCoordRight, textureCoordTop);
      gl.glVertex3f(1.0f, 1.0f, 0.0f);
      gl.glTexCoord2f(textureCoordLeft, textureCoordTop);
      gl.glVertex3f(-1.0f, 1.0f, 0.0f);
      gl.glEnd();

      // If twinkling, overlay with another drawing of an arbitrary color
      if (twinkleOn) {
        // Assign a color using bytes
        gl.glColor4ub(
            stars[(numStars - i) - 1].r,
            stars[(numStars - i) - 1].g,
            stars[(numStars - i) - 1].b,
            (byte) 255);
        gl.glBegin(GL_QUADS);
        // draw a square on x-y plane
        gl.glTexCoord2f(textureCoordLeft, textureCoordBottom);
        gl.glVertex3f(-1.0f, -1.0f, 0.0f);
        gl.glTexCoord2f(textureCoordRight, textureCoordBottom);
        gl.glVertex3f(1.0f, -1.0f, 0.0f);
        gl.glTexCoord2f(textureCoordRight, textureCoordTop);
        gl.glVertex3f(1.0f, 1.0f, 0.0f);
        gl.glTexCoord2f(textureCoordLeft, textureCoordTop);
        gl.glVertex3f(-1.0f, 1.0f, 0.0f);
        gl.glEnd();
      }

      // Update for the next refresh
      // The star spins about the z-axis (pointing out of the screen), and spiral
      // inwards and collapse towards the center, by increasing the angle on x-y
      // plane and reducing the distance.

      starSpinAngle += 0.01f; // used to spin the stars about the z-axis
      // spiral pattern
      stars[i].angle += (float) i / numStars; // changes the angle of a star
      // collapsing the star to the center
      stars[i].distance -= 0.01f; // changes the distance of a star
      // re-bone at the edge
      if (stars[i].distance < 0.0f) { // Is the star collapsed to the center?
        stars[i].distance += 5.0f; // move to the outer ring
        stars[i].setRandomRGB(); // choose a random color for the star
      }
    }
  }