我第一次學習LWJGL,並在LWJGL3 site上探索一個簡單的代碼塊作爲示例。我從來沒有使用過OpenGL或GLFW。LWJGL新手 - 什麼是stackPush(),mallocInt(1)和類似的GLFW方法?
我不明白這一小塊代碼。如果我刪除它,主代碼仍然有效。這整個事情只是爲了創造中心窗口嗎?
mallocInt (1)
是什麼意思?整個想法stackPush()
和奇怪的方法調用已被混淆。我用過SWT和awt,從來沒有見過類似的東西。
// Get the thread stack and push a new frame
try (MemoryStack stack = stackPush()) {
IntBuffer pWidth = stack.mallocInt(1); // int*
IntBuffer pHeight = stack.mallocInt(1); // int*
// Get the window size passed to glfwCreateWindow
glfwGetWindowSize(window, pWidth, pHeight);
// Get the resolution of the primary monitor
GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
// Center the window
glfwSetWindowPos(window,
(vidmode.width() - pWidth.get(0))/2,
(vidmode.height() - pHeight.get(0))/2);
}
// the stack frame is popped automatically
任何幫助,非常感謝。