我是第一次学习 LWJGL,并探索LWJGL3 站点上作为示例给出的简单代码块。我之前从未使用过 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, …Run Code Online (Sandbox Code Playgroud)