Silicon Graphics

[Prev] [TOC] [Next]



(-) OpenGL Programming Guide
(-) Appendix EThe OpenGL Programming Guide Auxiliary Library

Handling Window and Input Events

After the window is created, but before you enter the main loop, you should register callback functions using the following three routines. void auxReshapeFunc(void (*function)(GLsizei, GLsizei));

Specifies the function that's called whenever the window is resized, moved, or exposed. The argument function is a pointer to a function that expects two arguments, the new width and height of the window. Typically, function calls glViewport(), so that the display is clipped to the new size, and it redefines the projection matrix so that the aspect ratio of the projected image matches the viewport, avoiding aspect ratio distortion. If you don't call auxReshapeFunc(), a default reshape function is called, which assumes a two-dimensional orthographic projection. With this auxiliary library, the window is automatically redrawn after every reshaping event.

void auxKeyFunc(GLint key, void (*function)(void)) ;

Specifies the function, function, that's called when the keyboard key indicated by key is pressed. Use one of the defined auxiliary library constants for key: AUX_A through AUX_Z, AUX_a through AUX_z, AUX_0 through AUX_9, AUX_LEFT, AUX_RIGHT, AUX_UP, AUX_DOWN (the arrow keys), AUX_ESCAPE, AUX_SPACE, or AUX_RETURN. With this auxiliary library, the window is automatically redrawn after every processed key event, although in a real application, you might wait for several events to be completed before drawing.

void auxMouseFunc(GLint button, GLint mode,
void (*function)(AUX_EVENTREC *));

Specifies the function, function, that's called when the mouse button indicated by button enters the mode defined by mode. The button argument can be AUX_LEFTBUTTON, AUX_MIDDLEBUTTON, or AUX_RIGHTBUTTON (assuming a right-handed setup). The mode argument indicates whether the button is clicked, AUX_MOUSEDOWN, or released, AUX_MOUSEUP. The function argument must take one argument, which is a pointer to a structure of type AUX_EVENTREC. The auxMouseFunc() routine allocates memory for the structure. For example, to determine the pointer coordinates at the time of the event, you might define function like this:

void function(AUX_EVENTREC *event)
{ GLint x, y;
x = event->data[AUX_MOUSEX];
y = event->data[AUX_MOUSEY];
...
}


[Prev] [TOC] [Next]

OpenGL Programming Guide


Maintained by Maintainer: Send e-mail to .htm">name@address.