Exemple #1
0
  private void setupPointers(GL2 gl) {
    int vertices[] = new int[] {25, 25, 100, 325, 175, 25, 175, 325, 250, 25, 325, 325};
    float colors[] =
        new float[] {
          1.0f, 0.2f, 0.2f, 0.2f, 0.2f, 1.0f, 0.8f, 1.0f, 0.2f, 0.75f, 0.75f, 0.75f, 0.35f, 0.35f,
          0.35f, 0.5f, 0.5f, 0.5f
        };

    if (verticesBuf == null) { // IntBuffer tmpVerticesBuf
      verticesBuf = GLBuffers.newDirectIntBuffer(vertices.length);
      verticesBuf.put(vertices);
    }
    if (colorsBuf == null) {
      colorsBuf = GLBuffers.newDirectFloatBuffer(colors.length);
      colorsBuf.put(colors);
    }
    verticesBuf.rewind();
    colorsBuf.rewind();
    //
    gl.glEnableClientState(GL2.GL_VERTEX_ARRAY);
    gl.glEnableClientState(GL2.GL_COLOR_ARRAY);
    //
    gl.glVertexPointer(2, GL2.GL_INT, 0, verticesBuf);
    gl.glColorPointer(3, GL.GL_FLOAT, 0, colorsBuf);
  }
  protected void drawToolTip(
      DrawContext dc,
      java.awt.Rectangle viewport,
      String text,
      int x,
      int y,
      ToolTipAttributes attributes) {
    java.awt.geom.Rectangle2D textBounds = this.computeTextBounds(dc, text, attributes.getFont());
    java.awt.geom.Rectangle2D bgBounds =
        this.computeBackgroundBounds(
            dc, textBounds.getWidth(), textBounds.getHeight(), attributes.getInsets());

    java.awt.Point screenPoint = this.adjustDrawPointToViewport(x, y, bgBounds, viewport);
    java.awt.geom.Point2D textTranslation =
        this.computeTextTranslation(dc, textBounds, attributes.getInsets());

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

    stackHandler.pushModelview(gl);
    try {
      gl.glTranslated(
          screenPoint.getX() + bgBounds.getX(), screenPoint.getY() + bgBounds.getY(), 0);
      this.drawToolTipInterior(dc, bgBounds.getWidth(), bgBounds.getHeight(), attributes);
      this.drawToolTipOutline(dc, bgBounds.getWidth(), bgBounds.getHeight(), attributes);

      gl.glTranslated(textTranslation.getX(), textTranslation.getY(), 0);
      this.drawToolTipText(dc, text, 0, 0, attributes);
    } finally {
      stackHandler.pop(gl);
    }
  }
Exemple #3
0
 public void init(GLAutoDrawable drawable) {
   GL2 gl = drawable.getGL().getGL2();
   glu = new GLU();
   //
   gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
   gl.glShadeModel(GL2.GL_SMOOTH);
   setupPointers(gl);
 }
Exemple #4
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();
   glu.gluOrtho2D(0.0, (double) w, 0.0, (double) h);
 }
Exemple #5
0
 public void vertex(Object vertexData) {
   double[] pointer;
   if (vertexData instanceof double[]) {
     pointer = (double[]) vertexData;
     if (pointer.length == 6) gl.glColor3dv(pointer, 3);
     gl.glVertex3dv(pointer, 0);
   }
 }
  protected void drawToolTipInterior(
      DrawContext dc, double width, double height, ToolTipAttributes attributes) {
    GL2 gl = dc.getGL().getGL2(); // GL initialization checks for GL2 compatibility.

    this.applyColor(dc, attributes.getInteriorColor(), attributes.getInteriorOpacity());

    // Draw a filled rectangle with the background dimensions.
    gl.glRectd(0, 0, width, height);
  }
Exemple #7
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);
  }
  protected void transformBackgroundImageCoordsToAnnotationCoords(
      DrawContext dc, int width, int height, WWTexture texture) {
    GL2 gl = dc.getGL().getGL2(); // GL initialization checks for GL2 compatibility.

    // Scale background image coordinates to fit the Annotation's dimensions.
    java.awt.Dimension size = this.getImageSize(dc);
    if (size != null) {
      gl.glScaled(size.getWidth() / (double) width, size.getHeight() / (double) height, 1d);
    }

    super.transformBackgroundImageCoordsToAnnotationCoords(dc, width, height, texture);
  }
Exemple #9
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();
 }
  @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();
  }
  /**
   * 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);
  }
Exemple #12
0
  protected void endDrawIcons(DrawContext dc) {
    if (dc.isPickingMode()) this.pickSupport.endPicking(dc);

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

    if (dc.isPickingMode()) {
      gl.glTexEnvf(GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, OGLUtil.DEFAULT_TEX_ENV_MODE);
      gl.glTexEnvf(GL2.GL_TEXTURE_ENV, GL2.GL_SRC0_RGB, OGLUtil.DEFAULT_SRC0_RGB);
      gl.glTexEnvf(GL2.GL_TEXTURE_ENV, GL2.GL_COMBINE_RGB, OGLUtil.DEFAULT_COMBINE_RGB);
    }

    gl.glBindTexture(GL.GL_TEXTURE_2D, 0);

    this.oglStackHandler.pop(gl);
  }
  /**
   * Called back immediately after the OpenGL context is initialized. Can be used to perform
   * one-time initialization. Run only once.
   */
  @Override
  public void init(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2(); // get the OpenGL graphics context
    glu = new GLU(); // get GL Utilities
    gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // set background (clear) color
    gl.glClearDepth(1.0f); // set clear depth value to farthest
    // Do not enable depth test
    //      gl.glEnable(GL_DEPTH_TEST); // enables depth testing
    //      gl.glDepthFunc(GL_LEQUAL);  // the type of depth test to do
    gl.glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // best perspective correction
    gl.glShadeModel(GL_SMOOTH); // blends colors nicely, and smoothes out lighting

    // Load the texture image
    try {
      // Use URL so that can read from JAR and disk file.
      BufferedImage image = ImageIO.read(this.getClass().getResource(textureFileName));

      // Create a OpenGL Texture object
      texture = AWTTextureIO.newTexture(GLProfile.getDefault(), image, false);
      // Use linear filter if image is larger than the original texture
      gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
      // Use linear filter if image is smaller than the original texture
      gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

    } catch (GLException | IOException e) {
      e.printStackTrace();
    }

    // Texture image flips vertically. Shall use TextureCoords class to retrieve
    // the top, bottom, left and right coordinates, instead of using 0.0f and 1.0f.
    TextureCoords textureCoords = texture.getImageTexCoords();
    textureCoordTop = textureCoords.top();
    textureCoordBottom = textureCoords.bottom();
    textureCoordLeft = textureCoords.left();
    textureCoordRight = textureCoords.right();

    // Enable the texture
    texture.enable(gl);
    texture.bind(gl);
    // gl.glEnable(GL_TEXTURE_2D);

    // Enable blending
    gl.glEnable(GL_BLEND);
    gl.glBlendFunc(GL_SRC_ALPHA, GL_ONE);

    // Allocate the stars
    for (int i = 0; i < stars.length; i++) {
      stars[i] = new Star();
      // Linearly distributed according to the star number
      stars[i].distance = ((float) i / numStars) * 5.0f;
    }
  }
  /**
   * 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);
    }
  }
Exemple #15
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();
  }
Exemple #16
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);
 }
  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();

    glu.gluPerspective(45.0, 1.0, 0.25, 25.0);
    gl.glMatrixMode(GL2.GL_MODELVIEW);
    gl.glLoadIdentity();
    gl.glTranslatef(0.0f, 0.0f, -5.0f);
  }
Exemple #18
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);
 }
  private void recursiveDraw(
      int level, double x1, double y1, double x2, double y2, double x3, double y3) {
    if (level < 1) {
      return;
    }

    gl.glBegin(GL2.GL_LINE_LOOP);
    gl.glVertex2d(x1, y1);
    gl.glVertex2d(x2, y2);
    gl.glVertex2d(x3, y3);
    gl.glEnd();

    for (int i = 0; i < transitions; i += 1) {
      x1 = rotate_scale_xx[i] * x1 + rotate_scale_xy[i] * y1 + trans_x[i];
      y1 = rotate_scale_yx[i] * x1 + rotate_scale_yy[i] * y1 + trans_y[i];
      x2 = rotate_scale_xx[i] * x2 + rotate_scale_xy[i] * y2 + trans_x[i];
      y2 = rotate_scale_yx[i] * x2 + rotate_scale_yy[i] * y2 + trans_y[i];
      x3 = rotate_scale_xx[i] * x3 + rotate_scale_xy[i] * y3 + trans_x[i];
      y3 = rotate_scale_yx[i] * x3 + rotate_scale_yy[i] * y3 + trans_y[i];

      recursiveDraw(level - 1, x1, y1, x2, y2, x3, y3);
    }
  }
Exemple #20
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();
 }
Exemple #21
0
  @Override
  public void init(GLAutoDrawable drawable) {
    GL2 gl = (GL2) drawable.getGL();
    GLUgl2 glu = new GLUgl2();

    if (!gl.isExtensionAvailable("GL_ARB_vertex_buffer_object"))
      System.out.println("Error: VBO support is missing");

    gl.glShadeModel(GL2.GL_SMOOTH);
    gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    gl.glClearDepth(1.0f);
    gl.glEnable(GL2.GL_DEPTH_TEST);
    gl.glDepthFunc(GL2.GL_LEQUAL);
    gl.glHint(GL2.GL_PERSPECTIVE_CORRECTION_HINT, GL2.GL_NICEST);

    game = new Game(gl, glu, input);
  }
  /*
   * Initialize fog
   */
  public void init(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();
    glu = new GLU();
    //
    float fogColor[] = {0.0f, 0.25f, 0.25f, 1.0f};
    f1 = 1.0f;
    f2 = 5.0f;
    f3 = 10.0f;

    gl.glEnable(GL2.GL_FOG);
    gl.glFogi(GL2.GL_FOG_MODE, GL2.GL_EXP);
    gl.glFogfv(GL2.GL_FOG_COLOR, fogColor, 0);
    gl.glFogf(GL2.GL_FOG_DENSITY, 0.25f);
    gl.glHint(GL2.GL_FOG_HINT, GL.GL_DONT_CARE);
    gl.glFogi(GL2.GL_FOG_COORDINATE_SOURCE, GL2.GL_FOG_COORDINATE);
    gl.glClearColor(0.0f, 0.25f, 0.25f, 1.0f); /* fog color */
  }
Exemple #23
0
  private void setupInterleave(GL2 gl) {
    float intertwined[] =
        new float[] {
          1.0f, 0.2f, 1.0f, 100.0f, 100.0f, 0.0f, 1.0f, 0.2f, 0.2f, 0.0f, 200.0f, 0.0f, 1.0f, 1.0f,
          0.2f, 100.0f, 300.0f, 0.0f, 0.2f, 1.0f, 0.2f, 200.0f, 300.0f, 0.0f, 0.2f, 1.0f, 1.0f,
          300.0f, 200.0f, 0.0f, 0.2f, 0.2f, 1.0f, 200.0f, 100.0f, 0.0f
        };
    if (intertwinedBuf == null) {
      intertwinedBuf = GLBuffers.newDirectFloatBuffer(intertwined.length);
      intertwinedBuf.put(intertwined);
    }

    intertwinedBuf.rewind();
    gl.glInterleavedArrays(GL2.GL_C3F_V3F, 0, intertwinedBuf);
  }
  protected void drawToolTipOutline(
      DrawContext dc, double width, double height, ToolTipAttributes attributes) {
    GL2 gl = dc.getGL().getGL2(); // GL initialization checks for GL2 compatibility.

    this.applyColor(dc, attributes.getOutlineColor(), attributes.getOutlineOpacity());
    gl.glLineWidth((float) getOutlineWidth());

    // Draw a line loop around the background rectangle. Inset the lines slightly to compensate for
    // OpenGL's line
    // rasterization algorithm. We want the line to straddle the rectangle pixels.
    double inset = 0.5;
    gl.glBegin(GL2.GL_LINE_LOOP);
    gl.glVertex2d(inset, inset);
    gl.glVertex2d(width - inset, inset);
    gl.glVertex2d(width - inset, height - inset);
    gl.glVertex2d(inset, height - inset);
    gl.glEnd();
  }
Exemple #25
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);
  }
Exemple #26
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();
 }
  protected void beginRendering(DrawContext dc, OGLStackHandler stackHandler) {
    if (dc == null) {
      String message = Logging.getMessage("nullValue.DrawContextIsNull");
      Logging.logger().fine(message);
      throw new IllegalArgumentException(message);
    }

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

    int attribMask =
        GL2.GL_COLOR_BUFFER_BIT // for alpha test func and ref, blend func
            | GL2.GL_CURRENT_BIT // for current color
            | GL2.GL_ENABLE_BIT // for enable/disable
            | GL2.GL_LINE_BIT // for line width
            | GL2.GL_TRANSFORM_BIT; // for matrix mode
    stackHandler.pushAttrib(gl, attribMask);

    stackHandler.pushTextureIdentity(gl);
    stackHandler.pushProjectionIdentity(gl);
    java.awt.Rectangle viewport = dc.getView().getViewport();
    gl.glOrtho(
        viewport.x, viewport.x + viewport.width, viewport.y, viewport.y + viewport.height, -1, 1);
    stackHandler.pushModelviewIdentity(gl);

    // Enable the alpha test.
    gl.glEnable(GL2.GL_ALPHA_TEST);
    gl.glAlphaFunc(GL2.GL_GREATER, 0.0f);

    // Enable blending in premultiplied color mode.
    gl.glEnable(GL.GL_BLEND);
    OGLUtil.applyBlending(gl, true);

    gl.glDisable(GL.GL_CULL_FACE);
    gl.glDisable(GL.GL_DEPTH_TEST);
    gl.glDisable(GL2.GL_LIGHTING);
    gl.glDisable(GL.GL_TEXTURE_2D);
  }
  @Override
  public void init(GLAutoDrawable glAutoDrawable) {
    gl = glAutoDrawable.getGL().getGL2();
    glu = new GLU();
    glut = new GLUT();

    gl.glClearColor(0.549f, 0.675f, 0.227f, 0.0f);
    gl.glMatrixMode(GL2.GL_PROJECTION);
    gl.glLoadIdentity();
    glu.gluOrtho2D(left, right, bottom, top);
    gl.glViewport((int) bottom, (int) left, (int) top, (int) right);
    gl.glMatrixMode(GL2.GL_MODELVIEW);
    gl.glColor3f(.357f, .184f, .478f);

    maxFrames = 50 * ifsFiles.size() + 1000;
    base = gl.glGenLists(maxFrames);
    currentDrawList = base;

    ifsfile = "CS371/assignments/assignment02/tri.ifs";
    loadifs();
  }
Exemple #29
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();
  }
Exemple #30
0
  private void renderRedTeapot(GL2 gl, float x, float y, float z) {
    float mat[] = new float[4];

    gl.glPushMatrix();
    gl.glTranslatef(x, y, z);
    mat[0] = 0.1745f;
    mat[1] = 0.01175f;
    mat[2] = 0.01175f;
    mat[3] = 1.0f;
    gl.glMaterialfv(GL.GL_FRONT, GL2.GL_SPECULAR, mat, 0);
    mat[0] = 0.61424f;
    mat[1] = 0.04136f;
    mat[2] = 0.04136f;
    gl.glMaterialfv(GL.GL_FRONT, GL2.GL_DIFFUSE, mat, 0);
    mat[0] = 0.727811f;
    mat[1] = 0.626959f;
    mat[2] = 0.626959f;
    gl.glMaterialfv(GL.GL_FRONT, GL2.GL_SPECULAR, mat, 0);
    gl.glMaterialf(GL.GL_FRONT, GL2.GL_SHININESS, 0.6f * 128.0f);
    glut.glutSolidTeapot(1.0);
    gl.glPopMatrix();
  }