I’m working on a little cellular automata project to familiarize myself with GLFW, (for those unfamiliar, its essentially just a grid that can be drawn into by the user, which updates each cell over time according to some function)
Currently, I process events by registering callbacks and calling glfwPollEvents() every frame before updating. As I understand it, this will de-queue every item currently in the event queue and dispatch to their respective callbacks. The input guide says “glfwPollEvents, processes only those events that have already been received and then returns immediately.” but the name implies it may also poll the current device states? …I’m just a little iffy on the exact behavior…
On to the main point of confusion: I wanted the user’s drawing to be as accurate as possible, so I decided I would examine every mouse position in the queue instead of just the most recent one. However, there are way, way fewer cursorPos events coming in than I would expect. Normally with the swap interval set to 1, (updating at 60 hz) I’m getting 1 or 2 cursorPos events coming in, maybe 3. I was a little surprised that there were so few so I experimented a little, changing the swap interval so it only updated once per second, and still got 1 - 4 events per update.
Hmm…ok maybe glfwSwapBuffers is preventing some events from being recorded while it waits for the swap interval to pass…? how bout if I just put an empty loop right before the call to glfwPollEvents and spin until at least a second has elapsed then continue? Same deal, at most 4 cursorPos events in the queue.
How do glfwPollEvents and the event queue work exactly?
At first I thought maybe it was polling and only giving me the current mouse position right when I called glfwPollEvents, but then why am I getting up to 4 per update (all roughly evenly spaced apart)?
Then I thought maybe GLFW was polling events for the queue way less frequently that I first assumed, but then why when processing the queue 60x less frequently, am I only seeing ~2x more cursorPos events? Is the event frequency dependent on something else I’m forgetting?
Is this just a completely unreliable way to track mouse input? Is there no guarantee that there will be regular cursorPos events in the queue (assuming the cursor is actually moving)?
Hopefully someone here can tell my that I’m stupid and thinking about this completely wrong . Maybe there’s a simple explanation that I’m just failing to see.
EDIT: It might also relevant to mention that I’m running on Windows 10.