Hey
I cannot figure out how to retrieve the window size with the glfw functions. According to the docs, I need to pass through bytebuffers as parameters. It works fine but the buffer's limit is always 0, which means no data has written. This is my code:
PointerBuffer bufferW = new PointerBuffer(4);
PointerBuffer bufferH = new PointerBuffer(4);
glfwGetFramebufferSize(window,bufferW.getBuffer(),bufferH.getBuffer());
bufferW.flip();
System.out.println(bufferW);
There are 3 problems with the above code:
- You're using PointerBuffers, which are meant to be used for pointer data (arrays of pointers). You should be using ByteBuffers, or IntBuffers.
- glfwGetFramebufferSize returns the framebuffer size, not the window size. Technically these are not the same, the framebuffer size is in pixels, whereas the window (client area) size is in screen coordinates.
- You should never call flip after an LWJGL call. LWJGL may read the current buffer position and limit, but never modifies them.
This is the correct code:
ByteBuffer w = BufferUtils.createByteBuffer(4);
ByteBuffer h = BufferUtils.createByteBuffer(4);
glfwGetWindowSize(window, w, h);
int width = w.getInt(0);
int height = h.getInt(0);
or with IntBuffers:
IntBuffer w = BufferUtils.createIntBuffer(1);
IntBuffer h = BufferUtils.createIntBuffer(1);
glfwGetWindowSize(window, w, h);
int width = w.get(0);
int height = h.get(0);