Functions related to mouse and keyboard events in OPENGL

1. void glutMotionFunc(void (*func)(int x, int y))

Call the callback function registered by glutMotionFunc when the mouse is pressed and moved in the window, x and y are the position of the mouse when the mouse is pressed

2. void glutPassiveMotionFunc(void (*func)(int x, int y))

Call the callback function registered by glutPassiveMotionFunc when the mouse moves in the window. x, y: Mouse down type, the position of the cursor relative to the upper left corner of the window, in pixels.

3. void glutKeyboardFunc(void(*func)(unsigned char key,int x,int y))

This function can be used to handle key press events that can be represented by ascii codes on the keyboard. key is the ascii code of this key, and x and y are the position of the mouse relative to the upper left corner of the window when the key is pressed.

4. void glutSpecialFunc(void (*func)(int key,int x,int y))

This function is used to deal with events pressed by some special keys (such as: F1, F2, etc). The parameter key is the key number. These constants are predefined in glut.h:

#define GLUT_KEY_F1          1
#define GLUT_KEY_F2          2
#define GLUT_KEY_F3          3

There are many predefined keys, which can be viewed in the glut.h file, or directly output key values ​​for viewing. Similarly, x and y are also the current mouse position.

5. void glutMouseFunc(void(*func)(int button,int state,int x,int y))

This function is used to handle the events of the left and right mouse buttons and the middle button press. The button saves the key position information of the pressed mouse button. In glut.h, there are definitions:

#define GLUT_LEFT_BUTTON    0
#define GLUT_MIDDLE_BUTTON  1
#define GLUT_RIGHT_BUTTON    2

#define GLUT_DOWN        0
#define GLUT_UP          1

The parameter state indicates whether the key is pressed or released when this event occurs.
The parameters x and y represent the current mouse position.

6. void glutPassiveMotionFunc(void (*func)(int x,int y))

This function handles the event of mouse drag when there is no mouse button pressed. When the mouse is dragged, this function will be called once every frame.

7. void glutEntryFunc(void(*func)(int state))

This function handles events when the mouse leaves and enters the window. The value of the parameter state is defined in glut.h:

#define GLUT_LEFT        0
#define GLUT_ENTERED      1

8. int glutGetModifiers(void)

The return value of this function is one of the three predefined constants in glut.h, or a combination of them. The three constants are:

GLUT_ACTIVE_SHIFT: 返回它,当按下SHIFT键或以按下CAPS LOCK,注意两者同时按下时,不会返回这个值。
GLUT_ACTIVE_CTRL: 返回它,当按下CTRL键。
GLUT_ACTIVE_ATL:返回它,当按下ATL键

Guess you like

Origin blog.csdn.net/Miha_Singh/article/details/84997067