/**
   * Draw the outline of the given shape. Only the vertices are set. The colour has to be set
   * independently of this method.
   *
   * @param shape The shape to draw.
   * @param fill The fill to apply
   */
  public static final void draw(Shape shape, ShapeFill fill) {
    float points[] = shape.getPoints();

    Texture t = TextureImpl.getLastBind();
    TextureImpl.bindNone();

    float center[] = shape.getCenter();
    GL.glBegin(SGL.GL_LINE_STRIP);
    for (int i = 0; i < points.length; i += 2) {
      fill.colorAt(shape, points[i], points[i + 1]).bind();
      Vector2f offset = fill.getOffsetAt(shape, points[i], points[i + 1]);
      GL.glVertex2f(points[i] + offset.x, points[i + 1] + offset.y);
    }

    if (shape.closed()) {
      fill.colorAt(shape, points[0], points[1]).bind();
      Vector2f offset = fill.getOffsetAt(shape, points[0], points[1]);
      GL.glVertex2f(points[0] + offset.x, points[1] + offset.y);
    }
    GL.glEnd();

    if (t == null) {
      TextureImpl.bindNone();
    } else {
      t.bind();
    }
  }
  /**
   * Draw the the given shape filled in. Only the vertices are set. The colour has to be set
   * independently of this method.
   *
   * @param shape The shape to fill.
   * @param callback The callback that will be invoked for each shape point
   */
  private static final void fill(Shape shape, PointCallback callback) {
    Triangulator tris = shape.getTriangles();

    GL.glBegin(SGL.GL_TRIANGLES);
    for (int i = 0; i < tris.getTriangleCount(); i++) {
      for (int p = 0; p < 3; p++) {
        float[] pt = tris.getTrianglePoint(i, p);
        float[] np = callback.preRenderPoint(shape, pt[0], pt[1]);

        if (np == null) {
          GL.glVertex2f(pt[0], pt[1]);
        } else {
          GL.glVertex2f(np[0], np[1]);
        }
      }
    }
    GL.glEnd();
  }
Example #3
0
  public void drawRectangleGradient(
      Vector2f p1,
      Vector2f p2,
      Color topLeft,
      Color topRight,
      Color bottomLeft,
      Color bottomRight) {
    getPrivates();

    try {
      Reflection.invokePrivateMethod(mPredraw, g);
    } catch (Exception e) {
      App.getApp().handle(e);
    }
    TextureImpl.bindNone();
    Color.white.bind();
    GL11.glBegin(GL11.GL_POLYGON);
    Color c;
    c = topLeft;
    gl.glColor4f(c.r, c.g, c.b, c.a);
    gl.glVertex2f(p1.x, p1.y);
    c = topRight;
    gl.glColor4f(c.r, c.g, c.b, c.a);
    gl.glVertex2f(p2.x, p1.y);
    c = bottomRight;
    gl.glColor4f(c.r, c.g, c.b, c.a);
    gl.glVertex2f(p2.x, p2.y);
    c = bottomLeft;
    gl.glColor4f(c.r, c.g, c.b, c.a);
    gl.glVertex2f(p1.x, p2.y);
    gl.glEnd();
    try {
      Reflection.invokePrivateMethod(mPostdraw, g);
    } catch (Exception e) {
      App.getApp().handle(e);
    }
  }
Example #4
0
  public void drawTriangle(Vector2f p1, Vector2f p2, Vector2f p3, Color c1, Color c2, Color c3) {
    getPrivates();

    try {
      Reflection.invokePrivateMethod(mPredraw, g);
    } catch (Exception e) {
      App.getApp().handle(e);
    }
    TextureImpl.bindNone();
    Color.white.bind();
    gl.glBegin(SGL.GL_TRIANGLES);
    gl.glColor4f(c1.r, c1.g, c1.b, c1.a);
    gl.glVertex2f(p1.x, p1.y);
    gl.glColor4f(c2.r, c2.g, c2.b, c2.a);
    gl.glVertex2f(p2.x, p2.y);
    gl.glColor4f(c3.r, c3.g, c3.b, c3.a);
    gl.glVertex2f(p3.x, p3.y);
    gl.glEnd();
    try {
      Reflection.invokePrivateMethod(mPostdraw, g);
    } catch (Exception e) {
      App.getApp().handle(e);
    }
  }