示例#1
0
  /**
   * Draw the sprite at the specified location
   *
   * @param x The x location at which to draw this sprite
   * @param y The y location at which to draw this sprite
   */
  public void draw(float x, float y) {
    // store the current model matrix
    glPushMatrix();

    // bind to the appropriate texture for this sprite
    texture.bind();

    // translate to the right location and prepare to draw
    glTranslatef(x, y, 0);
    // draw a quad textured to match the sprite
    glBegin(GL_QUADS);
    {
      glTexCoord2f(0, 0);
      glVertex2f(0, height);

      glTexCoord2f(texture.getWidth(), 0);
      glVertex2f(width, height);

      glTexCoord2f(texture.getWidth(), texture.getHeight());
      glVertex2f(width, 0);

      glTexCoord2f(0, texture.getHeight());
      glVertex2f(0, 0);
    }
    glEnd();

    // restore the model view matrix to prevent contamination
    glPopMatrix();
  }
示例#2
0
  public void draw(float x, float y, float size) {
    glPushMatrix();
    texture.bind();
    glTranslatef(x, y, 0);
    glBegin(GL_QUADS);
    {
      glTexCoord2f(0, 0);
      glVertex2f(0, height * size);

      glTexCoord2f(texture.getWidth(), 0);
      glVertex2f(width * size, height * size);

      glTexCoord2f(texture.getWidth(), texture.getHeight());
      glVertex2f(width * size, 0);

      glTexCoord2f(0, texture.getHeight());
      glVertex2f(0, 0);
    }
    glEnd();
    glPopMatrix();
  }