コード例 #1
0
  /**
   * 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();
    }
  }
コード例 #2
0
  /**
   * 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 fill The fill to apply
   */
  public static final void fill(final Shape shape, final ShapeFill fill) {
    if (!validFill(shape)) {
      return;
    }

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

    final float center[] = shape.getCenter();
    fill(
        shape,
        new PointCallback() {
          public float[] preRenderPoint(Shape shape, float x, float y) {
            fill.colorAt(shape, x, y).bind();
            Vector2f offset = fill.getOffsetAt(shape, x, y);

            return new float[] {offset.x + x, offset.y + y};
          }
        });

    if (t == null) {
      TextureImpl.bindNone();
    } else {
      t.bind();
    }
  }
コード例 #3
0
  /**
   * Draw the the given shape filled in with a texture. Only the vertices are set. The colour has to
   * be set independently of this method.
   *
   * @param shape The shape to texture.
   * @param image The image to tile across the shape
   * @param scaleX The scale to apply on the x axis for texturing
   * @param scaleY The scale to apply on the y axis for texturing
   */
  public static final void texture(
      Shape shape, final Image image, final float scaleX, final float scaleY) {
    if (!validFill(shape)) {
      return;
    }

    final Texture t = TextureImpl.getLastBind();
    image.getTexture().bind();

    fill(
        shape,
        new PointCallback() {
          public float[] preRenderPoint(Shape shape, float x, float y) {
            float tx = x * scaleX;
            float ty = y * scaleY;

            tx = image.getTextureOffsetX() + (image.getTextureWidth() * tx);
            ty = image.getTextureOffsetY() + (image.getTextureHeight() * ty);

            GL.glTexCoord2f(tx, ty);
            return null;
          }
        });

    float points[] = shape.getPoints();

    if (t == null) {
      TextureImpl.bindNone();
    } else {
      t.bind();
    }
  }
コード例 #4
0
  /**
   * Draw the the given shape filled in with a texture. Only the vertices are set. The colour has to
   * be set independently of this method.
   *
   * @param shape The shape to texture.
   * @param image The image to tile across the shape
   * @param scaleX The scale to apply on the x axis for texturing
   * @param scaleY The scale to apply on the y axis for texturing
   * @param fill The fill to apply
   */
  public static final void texture(
      final Shape shape,
      final Image image,
      final float scaleX,
      final float scaleY,
      final ShapeFill fill) {
    if (!validFill(shape)) {
      return;
    }

    Texture t = TextureImpl.getLastBind();
    image.getTexture().bind();

    final float center[] = shape.getCenter();
    fill(
        shape,
        new PointCallback() {
          public float[] preRenderPoint(Shape shape, float x, float y) {
            fill.colorAt(shape, x - center[0], y - center[1]).bind();
            Vector2f offset = fill.getOffsetAt(shape, x, y);

            x += offset.x;
            y += offset.y;

            float tx = x * scaleX;
            float ty = y * scaleY;

            tx = image.getTextureOffsetX() + (image.getTextureWidth() * tx);
            ty = image.getTextureOffsetY() + (image.getTextureHeight() * ty);

            GL.glTexCoord2f(tx, ty);

            return new float[] {offset.x + x, offset.y + y};
          }
        });

    if (t == null) {
      TextureImpl.bindNone();
    } else {
      t.bind();
    }
  }
コード例 #5
0
  /**
   * Draw the the given shape filled in with a texture. Only the vertices are set. The colour has to
   * be set independently of this method.
   *
   * @param shape The shape to texture.
   * @param image The image to tile across the shape
   * @param gen The texture coordinate generator to create coordiantes for the shape
   */
  public static final void texture(final Shape shape, Image image, final TexCoordGenerator gen) {
    Texture t = TextureImpl.getLastBind();

    image.getTexture().bind();

    final float center[] = shape.getCenter();
    fill(
        shape,
        new PointCallback() {
          public float[] preRenderPoint(Shape shape, float x, float y) {
            Vector2f tex = gen.getCoordFor(x, y);
            GL.glTexCoord2f(tex.x, tex.y);

            return new float[] {x, y};
          }
        });

    if (t == null) {
      TextureImpl.bindNone();
    } else {
      t.bind();
    }
  }
コード例 #6
0
  /**
   * 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.
   */
  public static final void draw(Shape shape) {
    Texture t = TextureImpl.getLastBind();
    TextureImpl.bindNone();

    float points[] = shape.getPoints();

    LSR.start();
    for (int i = 0; i < points.length; i += 2) {
      LSR.vertex(points[i], points[i + 1]);
    }

    if (shape.closed()) {
      LSR.vertex(points[0], points[1]);
    }

    LSR.end();

    if (t == null) {
      TextureImpl.bindNone();
    } else {
      t.bind();
    }
  }
コード例 #7
0
  /**
   * 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.
   */
  public static final void fill(Shape shape) {
    if (!validFill(shape)) {
      return;
    }

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

    fill(
        shape,
        new PointCallback() {
          public float[] preRenderPoint(Shape shape, float x, float y) {
            // do nothing, we're just filling the shape this time
            return null;
          }
        });

    if (t == null) {
      TextureImpl.bindNone();
    } else {
      t.bind();
    }
  }
コード例 #8
0
ファイル: GraphicsHelper.java プロジェクト: Shockah/EasySlick
  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);
    }
  }
コード例 #9
0
ファイル: GraphicsHelper.java プロジェクト: Shockah/EasySlick
  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);
    }
  }
コード例 #10
0
ファイル: ParticleSystem.java プロジェクト: pgfarley/lamport
  /**
   * Render the particles in the system
   *
   * @param x The x coordinate to render the particle system at (in the current coordinate space)
   * @param y The y coordinate to render the particle system at (in the current coordiante space)
   */
  public void render(float x, float y) {
    if ((sprite == null) && (defaultImageName != null)) {
      loadSystemParticleImage();
    }

    if (!visible) {
      return;
    }

    GL.glTranslatef(x, y, 0);

    if (blendingMode == BLEND_ADDITIVE) {
      GL.glBlendFunc(SGL.GL_SRC_ALPHA, SGL.GL_ONE);
    }
    if (usePoints()) {
      GL.glEnable(SGL.GL_POINT_SMOOTH);
      TextureImpl.bindNone();
    }

    // iterate over all emitters
    for (int emitterIdx = 0; emitterIdx < emitters.size(); emitterIdx++) {
      // get emitter
      ParticleEmitter emitter = (ParticleEmitter) emitters.get(emitterIdx);

      // check for additive override and enable when set
      if (emitter.useAdditive()) {
        GL.glBlendFunc(SGL.GL_SRC_ALPHA, SGL.GL_ONE);
      }

      // now get the particle pool for this emitter and render all particles that are in use
      ParticlePool pool = (ParticlePool) particlesByEmitter.get(emitter);
      Image image = emitter.getImage();
      if (image == null) {
        image = this.sprite;
      }

      if (!emitter.isOriented() && !emitter.usePoints(this)) {
        image.startUse();
      }

      for (int i = 0; i < pool.particles.length; i++) {
        if (pool.particles[i].inUse()) pool.particles[i].render();
      }

      if (!emitter.isOriented() && !emitter.usePoints(this)) {
        image.endUse();
      }

      // reset additive blend mode
      if (emitter.useAdditive()) {
        GL.glBlendFunc(SGL.GL_SRC_ALPHA, SGL.GL_ONE_MINUS_SRC_ALPHA);
      }
    }

    if (usePoints()) {
      GL.glDisable(SGL.GL_POINT_SMOOTH);
    }
    if (blendingMode == BLEND_ADDITIVE) {
      GL.glBlendFunc(SGL.GL_SRC_ALPHA, SGL.GL_ONE_MINUS_SRC_ALPHA);
    }

    Color.white.bind();
    GL.glTranslatef(-x, -y, 0);
  }
コード例 #11
0
  /**
   * Load a texture into OpenGL from a BufferedImage
   *
   * @param resourceName The location of the resource to load
   * @param resourceimage The BufferedImage we are converting
   * @param target The GL target to load the texture against
   * @param dstPixelFormat The pixel format of the screen
   * @param minFilter The minimising filter
   * @param magFilter The magnification filter
   * @return The loaded texture
   * @throws IOException Indicates a failure to access the resource
   */
  public static Texture getTexture(
      String resourceName,
      BufferedImage resourceimage,
      int target,
      int dstPixelFormat,
      int minFilter,
      int magFilter)
      throws IOException {
    ImageIOImageData data = new ImageIOImageData();
    int srcPixelFormat = 0;

    // create the texture ID for this texture
    int textureID = InternalTextureLoader.createTextureID();
    TextureImpl texture = new TextureImpl(resourceName, target, textureID);

    // Enable texturing
    Renderer.get().glEnable(SGL.GL_TEXTURE_2D);

    // bind this texture
    Renderer.get().glBindTexture(target, textureID);

    BufferedImage bufferedImage = resourceimage;
    texture.setWidth(bufferedImage.getWidth());
    texture.setHeight(bufferedImage.getHeight());

    if (bufferedImage.getColorModel().hasAlpha()) {
      srcPixelFormat = SGL.GL_RGBA;
    } else {
      srcPixelFormat = SGL.GL_RGB;
    }

    // convert that image into a byte buffer of texture data
    ByteBuffer textureBuffer = data.imageToByteBuffer(bufferedImage, false, false, null);
    texture.setTextureHeight(data.getTexHeight());
    texture.setTextureWidth(data.getTexWidth());
    texture.setAlpha(data.getDepth() == 32);

    if (target == SGL.GL_TEXTURE_2D) {
      Renderer.get().glTexParameteri(target, SGL.GL_TEXTURE_MIN_FILTER, minFilter);
      Renderer.get().glTexParameteri(target, SGL.GL_TEXTURE_MAG_FILTER, magFilter);

      if (Renderer.get().canTextureMirrorClamp()) {
        Renderer.get()
            .glTexParameteri(
                SGL.GL_TEXTURE_2D, SGL.GL_TEXTURE_WRAP_S, SGL.GL_MIRROR_CLAMP_TO_EDGE_EXT);
        Renderer.get()
            .glTexParameteri(
                SGL.GL_TEXTURE_2D, SGL.GL_TEXTURE_WRAP_T, SGL.GL_MIRROR_CLAMP_TO_EDGE_EXT);
      } else {
        Renderer.get().glTexParameteri(SGL.GL_TEXTURE_2D, SGL.GL_TEXTURE_WRAP_S, SGL.GL_CLAMP);
        Renderer.get().glTexParameteri(SGL.GL_TEXTURE_2D, SGL.GL_TEXTURE_WRAP_T, SGL.GL_CLAMP);
      }
    }

    Renderer.get()
        .glTexImage2D(
            target,
            0,
            dstPixelFormat,
            texture.getTextureWidth(),
            texture.getTextureHeight(),
            0,
            srcPixelFormat,
            SGL.GL_UNSIGNED_BYTE,
            textureBuffer);

    return texture;
  }