How do I get the current mouse position in C++ / OpenGL?

19,297

Solution 1

Register a glutPassiveMotionFunc callback function

See info about callbacks

Solution 2

You need to use the glutMotionFunc/glutPassiveMotionFunc callback to track mouse movement independent of mouse clicks.

7.6 glutMotionFunc, glutPassiveMotionFunc

Share:
19,297
KingNestor
Author by

KingNestor

CS Student at the University of Central Missouri

Updated on June 04, 2022

Comments

  • KingNestor
    KingNestor over 1 year

    I know that I can use a Mouse callback function for when a user clicks the mouse, but what if I want to know the current x/y position without the user clicking?

    Will I have to use a different callback that gets called on any mouse movement and keep track of the x/y myself or is there a function I can call within GLUT/OpenGL to get it?