13.016 Introduction to Geometric Modeling and Computation


OpenGL Window System Interaction

OpenGL makes no assumptions about the display hardware, which can be a dedicated terminal or a window on a workstation display. In the Athena environment, we will be working with a window (or windows) on the display screen of an SGI workstation.

The SGI machines use the X Window System, a windowing system originally developed at MIT. Activities such as creating or moving a window, or using input devices such as the mouse or keyboard are the responsibility of the windowing system, not OpenGL.

Because working with X is quite complicated, we will be using a simplified library called GLUT, or Graphics Library Utility Toolkit.

Traditional programs use a command-driven style of organization. At well defined times, the program will prompt for and receive input. The interaction with the outside world is under the control of the program.

  ...
  printf(...);   /* prompt for keyboard input */
  scanf(...);    /* receive keyboard input */
  ...            /* process the input */

  printf(...);   /* prompt for keyboard input */
  scanf(...);    /* receive keyboard input */
  ...

Almost all current windowing systems use an event-driven style of program organization. In other words, your program must wait for the window system to report an event, such as a mouse click or keyboard key press. After the program receives the event, it can take the appropriate action, then it must wait for the next event. Interaction with the outside world is not under the control of the program. Events are asynchronous; they can occur in any sequence and at any time.

while (1) {      /* loop forever */

  /* get the next event ... */

  /* take the appropriate action to service the event ... */

  switch (eventType) {
  case event_1: ...     /* respond to event type 1 */
    break;
  case event_2: ...     /* respond to event type 2 */
    break;
  ...
  case event_n: ...     /* respond to event type n */
    break;
  }
}

This type of loop is called the event loop.

To simplify the handling of events, a C function that handles a specific event can be registered with the window system. Whenever, that event occurs, the window system will automatically invoke the registered function. These types of functions are known as callback functions.


On to GLUT...
Back to mapping to the viewport...
Back to the overview...