@Override
  protected boolean render(GL gl) {

    GL3 gl3 = (GL3) gl;

    // Setup blending
    gl3.glEnable(GL_BLEND);
    gl3.glBlendEquation(GL_FUNC_ADD);
    gl3.glBlendFunc(GL_ONE, GL_SRC1_COLOR);

    Mat4 projection = glm.perspective_((float) Math.PI * 0.25f, 4.0f / 3.0f, 0.1f, 100.0f);
    Mat4 model = new Mat4(1.0f);
    Mat4 mvp = projection.mul(viewMat4()).mul(model);

    gl3.glViewport(0, 0, windowSize.x, windowSize.y);
    gl3.glClearBufferfv(GL_COLOR, 0, clearColor.put(0, 1).put(1, 1).put(2, 1).put(3, 1));

    gl3.glUseProgram(programName);
    gl3.glUniformMatrix4fv(uniformMvp, 1, false, mvp.toFa_(), 0);
    gl3.glUniform1i(uniformDiffuse, 0);

    gl3.glActiveTexture(GL_TEXTURE0);
    gl3.glBindTexture(GL_TEXTURE_2D, textureName.get(0));

    gl3.glBindVertexArray(vertexArrayName.get(0));
    gl3.glDrawArraysInstanced(GL_TRIANGLES, 0, vertexCount, 1);

    return true;
  }
  private boolean initTexture(GL3 gl3) {

    try {
      jgli.Texture2d texture = new Texture2d(jgli.Load.load(TEXTURE_ROOT + "/" + TEXTURE_DIFFUSE));
      jgli.Gl.Format format = jgli.Gl.translate(texture.format());
      jgli.Gl.Swizzles swizzles = jgli.Gl.translate(texture.swizzles());

      gl3.glGenTextures(1, textureName);

      gl3.glActiveTexture(GL_TEXTURE0);
      gl3.glBindTexture(GL_TEXTURE_2D, textureName.get(0));
      gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_R, swizzles.r.value);
      gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_G, swizzles.g.value);
      gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_B, swizzles.b.value);
      gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_A, swizzles.a.value);

      for (int level = 0; level < texture.levels(); ++level) {
        gl3.glTexImage2D(
            GL_TEXTURE_2D,
            level,
            format.internal.value,
            texture.dimensions(level)[0],
            texture.dimensions(level)[1],
            0,
            format.external.value,
            format.type.value,
            texture.data(level));
      }

    } catch (IOException ex) {
      Logger.getLogger(Gl_330_blend_index.class.getName()).log(Level.SEVERE, null, ex);
    }
    return checkError(gl3, "initTexture");
  }
  @Override
  protected boolean render(GL gl) {

    GL3 gl3 = (GL3) gl;

    Mat4 projection = glm.ortho_(-1.0f, 1.0f, -1.0f, 1.0f, 1.0f, -1.0f);
    Mat4 model = new Mat4(1.0f);
    Mat4 mvp = projection.mul(new Mat4(1.0f)).mul(model);

    gl3.glViewport(0, 0, windowSize.x, windowSize.y);
    gl3.glClearBufferfv(GL_COLOR, 0, clearColor.put(0, 0).put(1, 0).put(2, 0).put(3, 0));

    // Bind the program for use
    gl3.glUseProgram(programName);
    gl3.glUniform1i(uniformDiffuse, 0);
    gl3.glUniformMatrix4fv(uniformMvp, 1, false, mvp.toFa_(), 0);

    gl3.glActiveTexture(GL_TEXTURE0);
    gl3.glBindTexture(GL_TEXTURE_RECTANGLE, textureRectName.get(0));

    gl3.glBindVertexArray(vertexArrayName.get(0));
    gl3.glDrawArraysInstanced(GL_TRIANGLES, 0, vertexCount, 1);

    return true;
  }
  private boolean initTexture(GL3 gl3) {

    try {
      jgli.Texture2d texture = new Texture2d(jgli.Load.load(TEXTURE_ROOT + "/" + TEXTURE_DIFFUSE));
      assert (!texture.empty());

      gl3.glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

      gl3.glGenTextures(1, textureName);

      gl3.glActiveTexture(GL_TEXTURE0);
      gl3.glBindTexture(GL_TEXTURE_2D, textureName.get(0));
      gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
      gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, texture.levels() - 1);
      gl3.glTexParameteri(
          GL_TEXTURE_2D,
          GL_TEXTURE_MIN_FILTER,
          texture.levels() == 1 ? GL_NEAREST : GL_NEAREST_MIPMAP_NEAREST);
      gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
      gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
      gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
      gl3.glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_LOD, -1000.f);
      gl3.glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 1000.f);
      gl3.glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_LOD_BIAS, 0.0f);

      jgli.Gl.Format format = jgli.Gl.translate(texture.format());
      for (int level = 0; level < texture.levels(); ++level) {
        gl3.glTexImage2D(
            GL_TEXTURE_2D,
            level,
            format.internal.value,
            texture.dimensions(level)[0],
            texture.dimensions(level)[1],
            0,
            format.external.value,
            format.type.value,
            texture.data(level));
      }

      if (texture.levels() == 1) {
        gl3.glGenerateMipmap(GL_TEXTURE_2D);
      }

      gl3.glPixelStorei(GL_UNPACK_ALIGNMENT, 4);

    } catch (IOException ex) {
      Logger.getLogger(Gl_320_texture_2d.class.getName()).log(Level.SEVERE, null, ex);
    }
    return true;
  }
  private boolean initTexture(GL3 gl3) {

    IntBuffer textureSize = GLBuffers.newDirectIntBuffer(1);

    try {
      gl3.glPixelStorei(GL_UNPACK_ALIGNMENT, 4);

      gl3.glGetIntegerv(GL_MAX_RECTANGLE_TEXTURE_SIZE, textureSize);

      gl3.glGenTextures(1, textureRectName);

      gl3.glActiveTexture(GL_TEXTURE0);
      gl3.glBindTexture(GL_TEXTURE_RECTANGLE, textureRectName.get(0));
      gl3.glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_BASE_LEVEL, 0);
      gl3.glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MAX_LEVEL, 0);
      gl3.glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
      gl3.glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

      jgli.Texture2d texture = new Texture2d(jgli.Load.load(TEXTURE_ROOT + "/" + TEXTURE_DIFFUSE));
      jgli.Gl.Format format = jgli.Gl.translate(texture.format());

      assert (texture.dimensions()[0] <= textureSize.get(0)
          && texture.dimensions()[1] <= textureSize.get(0));

      gl3.glTexImage2D(
          GL_TEXTURE_RECTANGLE,
          0,
          format.internal.value,
          texture.dimensions()[0],
          texture.dimensions()[1],
          0,
          format.external.value,
          format.type.value,
          texture.data());

      gl3.glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

    } catch (IOException ex) {
      Logger.getLogger(Gl_330_texture_rect.class.getName()).log(Level.SEVERE, null, ex);
    }

    BufferUtils.destroyDirectBuffer(textureSize);

    return true;
  }
  @Override
  protected boolean render(GL gl) {

    GL3 gl3 = (GL3) gl;
    {
      gl3.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM));
      ByteBuffer pointer =
          gl3.glMapBufferRange(
              GL_UNIFORM_BUFFER, 0, Mat4.SIZE, GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT);

      Mat4 projection = glm.perspective_((float) Math.PI * 0.25f, 4.0f / 3.0f, 0.1f, 100.0f);
      Mat4 model = new Mat4(1.0f);

      pointer.asFloatBuffer().put(projection.mul(viewMat4()).mul(model).toFa_());

      gl3.glUnmapBuffer(GL_UNIFORM_BUFFER);
    }

    gl3.glDrawBuffer(GL_BACK);

    gl3.glViewport(0, 0, windowSize.x, windowSize.y);
    gl3.glDisable(GL_FRAMEBUFFER_SRGB);
    clearColor.put(new float[] {1.0f, 0.5f, 0.0f, 1.0f}).rewind();
    gl3.glClearBufferfv(GL_COLOR, 0, clearColor);

    gl3.glUseProgram(programName);

    gl3.glDisable(GL_FRAMEBUFFER_SRGB);
    gl3.glActiveTexture(GL_TEXTURE0);
    gl3.glBindTexture(GL_TEXTURE_2D, textureName.get(0));
    gl3.glBindBufferBase(
        GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM));
    gl3.glBindVertexArray(vertexArrayName.get(0));

    gl3.glDrawElementsInstancedBaseVertex(GL_TRIANGLES, elementCount, GL_UNSIGNED_SHORT, 0, 1, 0);

    return true;
  }