Programming and Graphics

(Kiana) #1

8.2 Graphics events 271


This callback specifies the function to be executed when a mouse button
is clicked:


  • Ifbtn=GLUTLEFTBUTTON, the left button has been clicked.

  • Ifbtn=GLUTRIGHTBUTTON, the right button has been clicked.

  • Ifbtn=GLUTMIDDLEBUTTON, the middle button has been clicked.

  • Ifstate=GLUTUP, the button has been pressed.

  • Ifstate=GLUTDOWN, the button has been released.

  • The variablesxandyare the mouse coordinates.


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

This callback specifies the function to be executed when a key is pressed.
The variablesxandyare the mouse coordinates.

void glutMotionFunc(void (*func)(int x, int y));

This callback specifies the function to be executed when the mouse is
moved while a button is pressed. The variablesxandyare the mouse
coordinates.

void glutReshapeFunc(void (*func)(int width, int height));

This callback specifies the function to be executed when the window is
being moved or resized. The arguments are the redrawn window width
and height.

void glutTimerFunc(unsigned int msecs, void (*func)(int value), value);

This callback prompts the execution of the function stated in the second
argument, called the “timer callback,” after a maximum delay ofmsecs
milliseconds.

The parametervalueof the timer callback is the same as that in the
third argument of theglutTimerFunccallback. It is possible to register
multiple timer callbacks. Although a callback cannot be unregistered, it
can be deactivated using thevalueparameter.

Timer callback


The following code implemented in the fileascii.ccgenerates a window
and prints all ASCII characters in animation using a time callback:

Free download pdf