コード例 #1
0
  public void renderAnimationFrame(
      Transform transform, int frame, Texture tex, boolean horizontalFlip) {
    GL20.glUseProgram(animSpriteShaderProgram.getProgramId());

    spriteVAO.bind();
    // GL30.glBindVertexArray(flatPlane.getVaoId());

    Matrix4f finalMatrix =
        rs.getCamera()
            .getProjectionMatrix()
            .multiply(rs.getCamera().getWorldMatrix().multiply(transform.toMatrix()));

    // Diffuse Texture
    GL13.glActiveTexture(GL13.GL_TEXTURE0);
    GL11.glBindTexture(GL30.GL_TEXTURE_2D_ARRAY, tex.getTextureId());

    GL20.glUniformMatrix4fv(
        animSpriteShaderProgram.getUniform("mvpMatrix").getLocation(),
        false,
        finalMatrix.toBuffer());
    GL20.glUniform1i(animSpriteShaderProgram.getUniform("diffuseTextureAtlas").getLocation(), 0);
    GL20.glUniform1i(animSpriteShaderProgram.getUniform("currentFrame").getLocation(), frame);
    GL20.glUniform1i(
        animSpriteShaderProgram.getUniform("horizontalFlip").getLocation(),
        (horizontalFlip) ? GL11.GL_TRUE : GL11.GL_FALSE);

    GL11.glDrawArrays(GL11.GL_TRIANGLE_STRIP, 0, SPRITE_NUM_VERTICES);
  }
コード例 #2
0
  public void renderSprite(Transform transform, Texture texture, boolean hFlip, boolean vFlip) {
    GL20.glUseProgram(spriteShaderProgram.getProgramId());

    spriteVAO.bind();

    GL13.glActiveTexture(GL13.GL_TEXTURE0);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture.getTextureId());

    Matrix4f finalMatrix =
        rs.getCamera()
            .getProjectionMatrix()
            .multiply(rs.getCamera().getWorldMatrix().multiply(transform.toMatrix()));

    GL20.glUniformMatrix4fv(
        spriteShaderProgram.getUniform("mvpMatrix").getLocation(), false, finalMatrix.toBuffer());
    GL20.glUniform1i(
        spriteShaderProgram.getUniform("horizontalFlip").getLocation(),
        (hFlip) ? GL11.GL_TRUE : GL11.GL_FALSE);
    GL20.glUniform1i(
        spriteShaderProgram.getUniform("verticalFlip").getLocation(),
        (vFlip) ? GL11.GL_TRUE : GL11.GL_FALSE);
    GL20.glUniform1i(spriteShaderProgram.getUniform("sprite").getLocation(), 0);

    GL11.glDrawArrays(GL11.GL_TRIANGLE_STRIP, 0, SPRITE_NUM_VERTICES);
  }
コード例 #3
0
  @Deprecated
  public void renderUISprite(Rectangle rect, Texture image, boolean hFlip, boolean vFlip) {
    GL20.glUseProgram(spriteShaderProgram.getProgramId());

    // Remember to change this calculation when I change the size of the flatplane
    Matrix4f modelMatrix =
        Matrix4f.translation(rect.getX(), rect.getY(), 0)
            .multiply(Matrix4f.scale(rect.getWidth(), rect.getHeight(), 1f));

    spriteVAO.bind();

    image.bind();
    // GL30.glBindVertexArray(flatPlane.getVaoId());

    GL20.glUniformMatrix4fv(
        spriteShaderProgram.getUniform("mvpMatrix").getLocation(), false, modelMatrix.toBuffer());
    GL20.glUniform1i(
        spriteShaderProgram.getUniform("horizontalFlip").getLocation(),
        (hFlip) ? GL11.GL_TRUE : GL11.GL_FALSE);
    GL20.glUniform1i(
        spriteShaderProgram.getUniform("verticalFlip").getLocation(),
        (vFlip) ? GL11.GL_TRUE : GL11.GL_FALSE);
    GL20.glUniform1i(spriteShaderProgram.getUniform("sprite").getLocation(), 0);

    GL11.glDrawArrays(GL11.GL_TRIANGLE_STRIP, 0, SPRITE_NUM_VERTICES);
  }
コード例 #4
0
  public void destroy() {
    spriteShaderProgram.destroy();
    animSpriteShaderProgram.destroy();

    spriteVAO.destroy();
  }