コード例 #1
0
ファイル: GraphicsHelper.java プロジェクト: Shockah/EasySlick
  public void setBlendMode(int mode) {
    oldBlendMode = blendMode;
    blendMode = mode;

    GL14.glBlendEquation(GL14.GL_FUNC_ADD);
    if (mode < 100) {
      g.setDrawMode(mode);
      return;
    }

    try {
      Reflection.invokePrivateMethod(mPredraw, g);
    } catch (Exception e) {
      App.getApp().handle(e);
    }
    gl.glEnable(SGL.GL_BLEND);
    gl.glColorMask(true, true, true, true);

    if (mode == BM_ADD || mode == BM_SUBTRACT) {
      gl.glBlendFunc(SGL.GL_SRC_ALPHA, SGL.GL_ONE);
      if (mode == BM_SUBTRACT) {
        GL14.glBlendEquation(GL14.GL_FUNC_SUBTRACT);
        GL14.glBlendEquation(GL14.GL_FUNC_REVERSE_SUBTRACT);
      }
    }

    try {
      Reflection.invokePrivateMethod(mPostdraw, g);
    } catch (Exception e) {
      App.getApp().handle(e);
    }
  }
コード例 #2
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);
  }