GLUT Tutorial – How to detect a Mouse Click and Mouse Motion
In previous tutorial, we discussed about handling Keyboard event using GLUT. In this tutorial we pay our close attention towards Detecting Mouse click and Mouse motion.
Detecting Mouse Click
GLUT provides a function glutMouseFunc which is responsible for detecting mouse click generated by a program. Its syntax is
void glutMouseFunc(void (*func)(int button, int state, int x, int y));
Where,
GLUT provides a function glutMouseFunc which is responsible for detecting mouse click generated by a program. Its syntax is
void glutMouseFunc(void (*func)(int button, int state, int x, int y));
Where,
func –> Function that handles the mouse event i.e. when mouse click is detected, func is called |
func must have three parameters, as we see in above syntax The first parameter is button, its value is one of the following |
|
The second parameter is state, its value is one of the following |
|
When callback is generated with GLUT_DOWN GLUT environment assumes that GLUT_UP comes afterward even if mouse is not inside the window. |
Other two parameters x and y are coordinates of the point where mouse pointer is moved. |
Detecting Mouse Motion
GLUT provides two types of function as according to types of motion detection either Active Motion or Passive Motion. Active Motion refers to the Motion of mouse when there is Click and Passive motion refers to motion of a mouse without a click. The syntax of two functions are
glutMotionFunc(void (*func)(int x, int y)); //for Active motion |
glutMousePassiveMotionFunc(void (*func)(int x, int y)) // for Passive motion |
Where, |
func –> Function that responsible for handling respective motion |
x, y –> coordinates of the mouse relative to upper left corner of window |
Really trustworthy blog. Not only is this a well-written post, but I love the topic. Thanks for sharing !
very helpful to understand, but i have a question, do i call this function before or after the display?, for example if i want to draw a line like paint does. Thank you 🙂
example pls
u should atleast provide some examples for the biginners
Now I really understand what mouse function is.
baal bujjho tumi