OSF/Motif is the X Window System's industry-standard programming interface for user interface construction. Motif programmers writing 3D applications will want to understand how to integrate Motif with the OpenGL graphics system. This article, the last in a three-part series about OpenGL, describes how to write an OpenGL program within the user interface framework provided by Motif and the X Toolkit.
Most 3D applications end up using 3D graphics primarily in one or more ``viewing'' windows. For the most part, the graphical user interface aspects of such programs use standard 2D user interface objects like pulldown menus, sliders, and dialog boxes. Creating and managing such common user interface objects is what Motif does well. The ``viewing'' windows used for 3D are where OpenGL rendering happens. These windows for OpenGL rendering can be constructed with standard Motif drawing area widgets or OpenGL-specific drawing area widgets. Bind an OpenGL rendering context to the window of a drawing area widget and you are ready for 3D rendering.
Programming OpenGL with Motif has numerous advantages over using ``Xlib only'' as described in the first two articles in this series [3][2]. First and most important, Motif provides a well-documented, standard widget set that gives your application a consistent look and feel. Second, Motif and the X Toolkit take care of routine but complicated issues such as cut and paste and window manager conventions. Third, the X Toolkit's work procedure and timeout mechanisms make it easy to animate a 3D window without blocking out user interaction with your application.
This article assumes you have some experience programming with Motif and you have a basic understanding of how OpenGL integrates with X.
Section 2 describes how to use OpenGL rendering with either a standard Motif drawing area widget or an OpenGL-specific drawing area widget. Section 3 discusses using X Toolkit mechanisms for seamless animation. Section 4 provides advice on how to debug OpenGL programs by catching OpenGL errors. Throughout the discussion, a Motif-based OpenGL program named paperplane is used as an example. The complete source code for paperplane is found in the appendix. The program animates the 3D flight paths of virtual paper airplanes. The user can interact with the program via Motif controls. The program can be compiled to use either a standard Motif drawing area widget or an OpenGL-specific drawing area widget. Figure 1 shows paperplane running.