Beispiel #1
0
  /**
   * Method called by the World Class to render the Tile.
   *
   * @param x : location to where the Tile is going to be rendered.
   * @param y : location to where the Tile is going to be rendered.
   * @param w : instance of the World Class
   * @param ent : List of entities that emit light.
   */
  public void render(int x, int y, World w, ArrayList<Entity> ent) {
    // Binding the Uniforms to make the light effects.
    bindUniforms(w, ent);

    // Setting up OpenGL for render
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ZERO);

    // Updating the Tile coordinates.
    this.x = x;
    this.y = y;
    glTranslatef(x, y, 0);
    // Activating and Binding the Tile Texture.
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, this.tex);
    // Sending the texture to the shader.
    glUniform1i(glGetUniformLocation(shade.getShader(), "texture"), 0);

    // Drawing the QUAD.
    glBegin(GL_QUADS);
    {
      glTexCoord2f(0, 0);
      glVertex2f(0, 0);

      glTexCoord2f(0, 1);
      glVertex2f(0, this.height);

      glTexCoord2f(1, 1);
      glVertex2f(this.width, this.height);

      glTexCoord2f(1, 0);
      glVertex2f(this.width, 0);
    }
    glEnd();
    // Releasing the Texture.
    glBindTexture(GL_TEXTURE_2D, 0);
    // Getting the location back to the inicial coordinates.
    glTranslatef(-x, -y, 0);

    // Disabling BLEND and releasing shader for next render.
    glDisable(GL_BLEND);
    shade.release();
    glClear(GL_STENCIL_BUFFER_BIT);
  }
Beispiel #2
0
 /** Update Method, called by the World class 60 times per second. */
 public void update() {
   if (Keyboard.isKeyDown(Keyboard.KEY_R)) shade.recompile();
 }