# Mouse Lag

**URL:** <https://discourse.glfw.org/t/mouse-lag/273>\
**Category:** support\
**Created:** [June 19, 2011, 6:48pm UTC](https://discourse.glfw.org/t/mouse-lag/273 "2011-06-19T18:48:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/b8cdefe6b61b8d5aee6c43b2c56e9cf5eabecfe4.svg) [@system](https://discourse.glfw.org/u/system)\
**Post date:** [June 19, 2011, 6:48pm UTC](https://discourse.glfw.org/t/mouse-lag/273/1 "2011-06-19T18:48:26Z")

</div>

**anonymous** wrote on [Sunday, June 19, 2011](https://sourceforge.net/p/glfw/discussion/247562/thread/e342229f/#e680):

with glfwSwapInterval(1); the rendered point is lagging behind the real  
mouse cursor (both windows and ubuntu on laptop and desktop pc)  
glfwSwapInterval(0); makes the mouse move jerky  
mouse callback does change a thing  
glfwSleep fixes this problem but someone wrote that it won’t be available in  
later versions  
for (int i=0; i\<1000000; i++) float x = sqrt(1337.0); fixes the problem as  
well so I think that my pc is faster than glfw can spit the images on my  
screen but this is not a good solution because it won’t work on slower/faster  
systems and creates unnecessary overhead

not having that problem with freeglut so I will have to use that instead  
(well…I could get another lib for threads but….)

```
#include <GL/glfw.h>
int main(){
    int w = 640, h = 480, mx = 0, my = 0;
    glfwInit();
    glfwOpenWindow(w, h, 5, 6, 5, 0, 0, 0, GLFW_WINDOW);
    //glfwSwapInterval(1);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0, w, 0, h, -10, 10);
    glMatrixMode(GL_MODELVIEW);
    glPointSize(10);
    while (!glfwGetKey(GLFW_KEY_ESC) && glfwGetWindowParam(GLFW_OPENED)){
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glfwGetMousePos(&mx, &my);
        my = h-1-my;
        glBegin(GL_POINTS);
        glVertex2f(mx, my);
        glEnd();
        glfwSwapBuffers();
        //glfwSleep(0.001);
    }
    glfwTerminate();
    return 0;
}
```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/b8cdefe6b61b8d5aee6c43b2c56e9cf5eabecfe4.svg) [@system](https://discourse.glfw.org/u/system)\
**Post date:** [June 19, 2011, 6:50pm UTC](https://discourse.glfw.org/t/mouse-lag/273/2 "2011-06-19T18:50:32Z")

</div>

**anonymous** wrote on [Sunday, June 19, 2011](https://sourceforge.net/p/glfw/discussion/247562/thread/e342229f/#1632):

\*mouse callback doesn’t change a thing  
(no edit available….)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/b8cdefe6b61b8d5aee6c43b2c56e9cf5eabecfe4.svg) [@system](https://discourse.glfw.org/u/system)\
**Post date:** [June 20, 2011, 2:05pm UTC](https://discourse.glfw.org/t/mouse-lag/273/3 "2011-06-20T14:05:55Z")

</div>

**anonymous** wrote on [Monday, June 20, 2011](https://sourceforge.net/p/glfw/discussion/247562/thread/e342229f/#084a):

glfwWaitEvents(); seems to fix this, too  
is this function supposed to stay?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/b8cdefe6b61b8d5aee6c43b2c56e9cf5eabecfe4.svg) [@system](https://discourse.glfw.org/u/system)\
**Post date:** [June 20, 2011, 2:17pm UTC](https://discourse.glfw.org/t/mouse-lag/273/4 "2011-06-20T14:17:02Z")

</div>

**anonymous** wrote on [Monday, June 20, 2011](https://sourceforge.net/p/glfw/discussion/247562/thread/e342229f/#c6ce):

and if it is is there some way to continue anyway even if no events occurred?
