GLUT Mouse Input Handler

Understanding mouse click handlers, active drags, and passive hover coordinate hooks.

Mouse Click Callback

Clicks are registered using glutMouseFunc(myMouse). The signature of the callback function is:

void myMouse(int button, int state, int x, int y) {
    if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) {
        // Handle click event at x, y
    }
}
                        

Parameters include the mouse button (e.g. GLUT_LEFT_BUTTON, GLUT_RIGHT_BUTTON), button state (GLUT_DOWN, GLUT_UP), and window relative coordinates.

Motion Callbacks

GLUT distinguishes between active dragging and passive hovering:

  • Active Motion: Hooked via glutMotionFunc(myMotion). Triggers when the cursor moves while a mouse button is pressed down. Perfect for drawing trails or rotating virtual trackballs.
  • Passive Motion: Hooked via glutPassiveMotionFunc(myPassiveMotion). Triggers when the cursor hovers and moves without any buttons pressed.

Ready to Test Mouse Interaction?

Launch our interactive visualizer to draw trails and track real-time coordinates.

Launch Mouse Visualizer →