【发布时间】:2017-08-07 20:30:49
【问题描述】:
我是第一次学习 LWJGL,并探索了一个简单的代码块,作为 LWJGL3 site 上的示例。我之前也从未使用过 OpenGL 或 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
非常感谢任何帮助。
【问题讨论】: