我最近從LWJGL 2切換到LWJGL 3,並且在文檔和組裝程序使用它幾個小時後,我有這個代碼。請注意,方法中的代碼都是靜態的,並且Eclipse不會對與此相關的代碼提出任何問題。另外請注意,將其從allocateDirect更改爲分配不起作用。在Java中從GLFW獲取鼠標座標時出現的問題(可能是bytebuffer問題)
//At the beginning of the class declaration:
public static ByteBuffer mouseXb=ByteBuffer.allocateDirect(8), mouseYb=ByteBuffer.allocateDirect(8);
public static double mouseX=0,mouseY=0;
//Then later, in another method in the same class
\t glfwPollEvents();
\t glfwGetCursorPos(window, mouseXb, mouseYb);
\t mouseX=mouseXb.getDouble();
\t mouseY=mouseYb.getDouble();
\t System.out.println(mouseX+", "+mouseY);
\t mouseXb.flip();
\t mouseYb.flip();
奇怪的是,雖然,我得到這樣的價值觀: (另請注意,當鼠標在窗口中四處移動,他們只變了,從來沒有在它的外面,也沒有當鼠標沒有移動)
2.0857E-317, 2.604651E-317
3.121831E-317, 2.604651E-317
5.1940924E-317, 2.604651E-317
7.2664804E-317, 2.604651E-317
6.7490474E-317, 2.0865855E-317
4.6771653E-317, 7.785178E-317
5.19561E-317, 5.7129166E-317