Beispiel #1
0
  public void createShader(Shader shader) {
    this.shader = shader;

    glActiveTexture(GL_TEXTURE1);
    shader.bind();

    int uniform = glGetUniformLocation(shader.getID(), "texture");
    glUniform1i(uniform, 1);

    glActiveTexture(GL_TEXTURE2);
    uniform = glGetUniformLocation(shader.getID(), "extraTexture");
    glUniform1i(uniform, 2);
    shader.release();
  }
Beispiel #2
0
  protected void compile() {
    vao = glGenVertexArrays();
    glBindVertexArray(vao);
    {
      vbo = glGenBuffers();
      glBindBuffer(GL_ARRAY_BUFFER, vbo);
      {
        glBufferData(GL_ARRAY_BUFFER, Buffer.createFloatBuffer(vertices), GL_STATIC_DRAW);
        glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, 0);
      }
      glBindBuffer(GL_ARRAY_BUFFER, 0);

      vio = glGenBuffers();
      glBindBuffer(GL_ARRAY_BUFFER, vio);
      {
        glBufferData(GL_ARRAY_BUFFER, Buffer.createByteBuffer(indices), GL_STATIC_DRAW);
      }
      glBindBuffer(GL_ARRAY_BUFFER, 0);

      vto = glGenBuffers();
      glBindBuffer(GL_ARRAY_BUFFER, vto);
      {
        glBufferData(GL_ARRAY_BUFFER, Buffer.createByteBuffer(texCoords), GL_STATIC_DRAW);
        glVertexAttribPointer(1, 3, GL_UNSIGNED_BYTE, false, 0, 1);
      }
      glBindBuffer(GL_ARRAY_BUFFER, 0);
    }
    glBindVertexArray(0);

    glActiveTexture(GL_TEXTURE1);
    shader.bind();
    int uniform = glGetUniformLocation(shader.getID(), "texture");
    glUniform1i(uniform, 1);
    shader.release();
  }
Beispiel #3
0
    @Override
    public void prepare(Object texObj, float alpha, int fbufWidth, int fbufHeight) {
      ctx.checkGLError("textureShader.prepare start");
      boolean wasntAlreadyActive = super.prepare(fbufWidth, fbufHeight);
      if (wasntAlreadyActive) {
        glActiveTexture(GL_TEXTURE0);
        glUniform1i(uTexture, 0);
      }

      int tex = (Integer) texObj;
      if (wasntAlreadyActive || tex != lastTex || alpha != lastAlpha) {
        flush();
        glUniform1f(uAlpha, alpha);
        lastAlpha = alpha;
        lastTex = tex;
        ctx.checkGLError("textureShader.prepare end");
      }
    }
Beispiel #4
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);
  }