/**
   * if the fill colour is non-null, fill the polygon with this colour if the line colour is
   * non-null, draw the outline with this colour
   *
   * @see ass1.spec.GameObject#drawSelf(javax.media.opengl.GL2)
   */
  @Override
  public void drawSelf(GL2 gl) {

    // First draw the filling by using a polygon and looping
    if (myFillColour != null) {
      gl.glColor4d(myFillColour[0], myFillColour[1], myFillColour[2], myFillColour[3]);
      gl.glBegin(GL2.GL_POLYGON);
      int numPoints = myPoints.length / 2;
      for (int i = 0; i < numPoints; i++) {
        gl.glVertex2d(myPoints[i * 2], myPoints[i * 2 + 1]);
      }
      gl.glEnd();
    }

    // Now draw the outline by using a line loop
    if (myLineColour != null) {
      gl.glColor4d(myLineColour[0], myLineColour[1], myLineColour[2], myLineColour[3]);
      gl.glBegin(GL2.GL_LINE_LOOP);
      int numPoints = myPoints.length / 2;
      for (int i = 0; i < numPoints; i++) {
        gl.glVertex2d(myPoints[i * 2], myPoints[i * 2 + 1]);
      }
      gl.glEnd();
    }
  }
예제 #2
0
 protected void setBlendingFunction(DrawContext dc) {
   GL2 gl = dc.getGL().getGL2();
   double alpha = this.getOpacity();
   gl.glColor4d(alpha, alpha, alpha, alpha);
   gl.glEnable(GL2.GL_BLEND);
   gl.glBlendFunc(GL2.GL_SRC_ALPHA, GL2.GL_ONE_MINUS_SRC_ALPHA);
 }
예제 #3
0
  @Override
  protected void doRender(DrawContext dc) {
    if (!loaded) {
      loaded = true;
      loadAttempts++;
      downloadData();
    }

    if (lastVerticalExaggeration != dc.getVerticalExaggeration() || lastGlobe != dc.getGlobe()) {
      lastVerticalExaggeration = dc.getVerticalExaggeration();
      lastGlobe = dc.getGlobe();
      recalculateVertices(lastGlobe, lastVerticalExaggeration);
      recalculateColors();
    }

    GL2 gl = dc.getGL().getGL2();

    int push = GL2.GL_CLIENT_VERTEX_ARRAY_BIT;
    if (colors != null) {
      push |= GL2.GL_COLOR_BUFFER_BIT;
    }
    if (getOpacity() < 1.0) {
      push |= GL2.GL_CURRENT_BIT;
    }
    gl.glPushClientAttrib(push);

    if (colors != null) {
      gl.glEnableClientState(GL2.GL_COLOR_ARRAY);
      gl.glColorPointer(4, GL2.GL_DOUBLE, 0, colors.rewind());
    }
    if (getOpacity() < 1.0) {
      setBlendingFunction(dc);
    }

    gl.glEnableClientState(GL2.GL_VERTEX_ARRAY);
    gl.glVertexPointer(3, GL2.GL_DOUBLE, 0, vertices.rewind());

    gl.glDrawElements(
        GL2.GL_TRIANGLE_STRIP, indices.limit(), GL2.GL_UNSIGNED_INT, indices.rewind());

    gl.glColor4d(1, 1, 1, 1);
    gl.glPopClientAttrib();
  }
예제 #4
0
 public void renderSelection(GL2 g) {
   if ((Globals.tab == Tab.labels || Globals.tab == Tab.height)) {
     g.glDisable(GL2.GL_ALPHA_TEST);
     g.glEnable(GL2.GL_BLEND);
     g.glBlendFunc(GL2.GL_SRC_ALPHA, GL2.GL_ONE_MINUS_SRC_ALPHA);
     double color = System.currentTimeMillis();
     color %= 2000d;
     color -= 1000d;
     color = Math.abs(color);
     color /= 1000d;
     g.glColor4d(1, 1, 0, 0.1d + 0.2d * color);
     g.glBegin(GL2.GL_QUADS);
     g.glVertex2f(0, 0);
     g.glVertex2f(0, 4);
     g.glVertex2f(4, 4);
     g.glVertex2f(4, 0);
     g.glEnd();
     g.glColor4f(1, 1, 1, 1);
     g.glDisable(GL2.GL_BLEND);
     g.glEnable(GL2.GL_ALPHA_TEST);
   }
 }
예제 #5
0
 public void renderObj(GL2 gl) {
   gl.glPushMatrix();
   gl.glEnable(GL2.GL_TEXTURE_2D);
   gl.glTexParameterf(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_MAG_FILTER, GL2.GL_NEAREST);
   gl.glTexParameterf(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_MIN_FILTER, GL2.GL_NEAREST);
   texture.enable(gl);
   texture.bind(gl);
   gl.glDisable(GL2.GL_DEPTH_TEST);
   gl.glColor4d(1, 1, 1, transparancy);
   gl.glScalef(canvas.orthoCoordWidth / 2, canvas.orthoCoordWidth / 2 / canvas.aspectRatio, 1);
   gl.glBegin(GL2.GL_QUADS);
   gl.glTexCoord2f(0, 0);
   gl.glVertex2f(-1, -1);
   gl.glTexCoord2f(1, 0);
   gl.glVertex2f(1, -1);
   gl.glTexCoord2f(1, 1);
   gl.glVertex2f(1, 1);
   gl.glTexCoord2f(0, 1);
   gl.glVertex2f(-1, 1);
   gl.glEnd();
   gl.glEnable(GL2.GL_DEPTH_TEST);
   gl.glDisable(GL2.GL_TEXTURE_2D);
   gl.glPopMatrix();
 }