我第一次学习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
任何帮助,非常感谢。