Q:

Can't figure out how to work with projections in LWJGL 3

Here is my code (should use shaders, I know :)
import java.nio.ByteBuffer

import org.lwjgl.glfw.Callbacks._
import org.lwjgl.glfw.GLFW._
import org.lwjgl.glfw._
import org.lwjgl.opengl.GL11._
import org.lwjgl.opengl._
import org.lwjgl.system.MemoryUtil._

object Main extends App {
  SharedLibraryLoader.load()

  private val errorCallback = new GLFWErrorCallback() {
    override def invoke(error: Int, description: Long): Unit = {
      errorCallbackPrint(System.err)
    }
  }

  private val keyCallback = new GLFWKeyCallback() {
    override def invoke(window: Long, key: Int, scancode: Int, action: Int, mods: Int): Unit = {
      if (key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE)
        glfwSetWindowShouldClose(window, GL_TRUE)
    }
  }

  private val resizeCallback = new GLFWWindowSizeCallback {
    override def invoke(window: Long, width: Int, height: Int): Unit = {
      glViewport(0, 0, width, height)
    }
  }

  try {
    val windowId = init()
    setupGeometry()
    loop(windowId)
    glfwDestroyWindow(windowId)
  } finally {
    keyCallback.release()
    errorCallback.release()
    glfwTerminate()
  }

  private def init(): Long = {
    glfwSetErrorCallback(errorCallback)
    if (glfwInit() != GL11.GL_TRUE)
      throw new IllegalStateException("glfwInit returned false")

    glfwDefaultWindowHints()
    glfwWindowHint(GLFW_RESIZABLE, GL_TRUE)

    val windowId = glfwCreateWindow(300, 300, "Hello World!", NULL, NULL)
    if (windowId == NULL)
      throw new RuntimeException("glfwCreateWindow returned 0")

    glfwSetKeyCallback(windowId, keyCallback)
    glfwSetWindowSizeCallback(windowId, resizeCallback)

    glfwMakeContextCurrent(windowId)
    glfwSwapInterval(1)
    glfwShowWindow(windowId)

    GLContext.createFromCurrent()

    glEnable(GL_DEPTH_TEST | GL_DOUBLEBUFFER)
    glDepthFunc(GL_LESS)

    windowId
  }

  private def loop(windowId: Long): Unit = {
    glClearColor(0, 0, 0, 1)

    while (glfwWindowShouldClose(windowId) == GL_FALSE) {

      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

      glColor4f(1, 0, 0, 1)
      glBegin(GL_TRIANGLES)
        glVertex3d( 0,  1, -1)
        glVertex3d( 1, -1, -1)
        glVertex3d(-1, -1, -1)
      glEnd()
      glFlush()

      glfwSwapBuffers(windowId)
      glfwPollEvents()
    }
  }

  private def setupGeometry(): Unit = {
    val m = GLM.perspective(45.0f, 4.0f / 3.0f, 0.5f, 1000.0f)

    val buf = ByteBuffer.allocateDirect(16*4).asFloatBuffer()
    m.store(buf)
    buf.rewind()
    // buf = Vector(1.8106601, 0.0, 0.0, 0.0, 0.0, 2.4142134, 0.0, 0.0, 0.0, 0.0, -1.0010005, -1.0, 0.0, 0.0, -1.0005002, 1.0)
    println(s"buf = ${for(_ <- 1 to buf.capacity()) yield buf.get()}")
    buf.rewind()

    glMatrixMode(GL_PROJECTION)
    glLoadIdentity()
    //glMultMatrixf(buf)

    glMatrixMode(GL_MODELVIEW)
    glLoadIdentity()
  }
}

If I uncomment line glMultMatrixf(buf) triangle disappears. But I'm pretty sure that it's just in front of a camera, between Near and Far parameters of projection. I didn't forget to enable z-buffer. What am I doing wrong?
GLM class was copy-pasted from here and ShardLibraryLoader from here.

A:

Ok, I figured this out. First of all there is a bug in GLM.perspective method since according to C++ glm library buf[15] should be 0, not 1. But even if you fix this for some reason it will not solve a problem. Apparently some sort of error with buffers and pointers, I don't know.
So I switched to JOML library. It just works.

