Programming and Graphics

(Kiana) #1

270 Introduction to C++ Programming and Graphics


//--- keyboard:

void keyboard(unsigned char key, int x, int y)
{
cout <<"Please enter a number:"<<endl;
cin >> a;

//--- mouse:

void mouse(int button, int state, int x, int y)
{
a=-1000000;
}

//--- add:

void add(void)
{
a=a+1;
cout << a << endl;
}

Idle functions find important applications in window resizing and animation.


Event callbacks


Following is a summary of callbacks triggered by events:

void glutDisplayFunc(void (*func)(void));

This callback specifies the function to be executed when the window is
shown for the first time, popped up, or otherwise redrawn.

void glutPostRedisplay(void);

This callback prompts the execution of the function defined by
theglutPostDisplayFunccallback at the first available opportunity, sig-
naling a need for redraw.

void glutIdleFunc(void (*func)(void));

This callback specifies the function to be executed between events and
finds important applications in animation.

void glutMouseFunc(void (*func)(int btn, int state, int x, int y));
Free download pdf