Exemplo n.º 1
0
  /** @see Font#drawString(float, float, String, Color, int, int) */
  public void drawString(float x, float y, String text, Color col, int startIndex, int endIndex) {
    fontImage.bind();
    col.bind();

    GL.glTranslatef(x, y, 0);
    if (displayListCaching && startIndex == 0 && endIndex == text.length() - 1) {
      DisplayList displayList =
          (DisplayList) displayLists.get(text + "" + startIndex + "" + endIndex);
      if (displayList != null) {
        GL.glCallList(displayList.id);
      } else {
        // Compile a new display list.
        displayList = new DisplayList();
        displayList.text = text;
        int displayListCount = displayLists.size();
        if (displayListCount < DISPLAY_LIST_CACHE_SIZE) {
          displayList.id = baseDisplayListID + displayListCount;
        } else {
          displayList.id = eldestDisplayListID;
          displayLists.remove(eldestDisplayList.text);
        }

        displayLists.put(text + "" + startIndex + "" + endIndex, displayList);

        GL.glNewList(displayList.id, SGL.GL_COMPILE_AND_EXECUTE);
        render(text, startIndex, endIndex);
        GL.glEndList();
      }
    } else {
      render(text, startIndex, endIndex);
    }
    GL.glTranslatef(-x, -y, 0);
  }
Exemplo n.º 2
0
  /**
   * @see org.newdawn.slick.Game#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
   */
  public final void render(GameContainer container, Graphics g) throws SlickException {
    int yoffset = 0;
    int xoffset = 0;

    if (targetHeight < container.getHeight()) {
      yoffset = (container.getHeight() - targetHeight) / 2;
    }
    if (targetWidth < container.getWidth()) {
      xoffset = (container.getWidth() - targetWidth) / 2;
    }

    SlickCallable.enterSafeBlock();
    g.setClip(xoffset, yoffset, targetWidth, targetHeight);
    GL.glTranslatef(xoffset, yoffset, 0);
    g.scale(targetWidth / normalWidth, targetHeight / normalHeight);
    GL.glPushMatrix();
    held.render(container, g);
    GL.glPopMatrix();
    g.clearClip();
    SlickCallable.leaveSafeBlock();

    renderOverlay(container, g);
  }
Exemplo n.º 3
0
  /**
   * 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);
  }