Chapter 1. Introduction to Porting From IRIS GL to OpenGL

This chapter provides an overview to porting from IRIS GL to OpenGL. It discusses the following topics:

Differences Between IRIS GL and OpenGL

One focus of OpenGL is portability. OpenGL and IRIS GL therefore differ in several major areas. This section lists a few important ways in which OpenGL is different from IRIS GL. A more complete list of the differences between the two languages is provided in Appendix B, “Differences Between OpenGL and IRIS GL.”

Here are some key differences between OpenGL and IRIS GL:

  • Window Management. OpenGL is window-system independent. It therefore contains no windowing, pop up menus, event handling, color-map loading, buffer allocation and management, font file formats, or cursor handling. These functions are delegated to the window or operating system. You can use the GLUT library for simple window handling under X. If you need more sophisticated windowing and event handling calls, you have to include the relevant X Window System calls in your program. Silicon Graphics provides some special GLX calls, where OpenGL rendering is made available as an extension to X in the formal X sense, and an widget to help you replace your IRIS GL windowing, event, and colormap handling calls. See Chapter 4, “OpenGL in the X Window System,” for details.

  • Naming Conventions. OpenGL establishes and adheres to a standard “name space.” OpenGL commands begin with the gl prefix (glEnable(), glTranslatef(), and so on). This convention prevents conflict with commands from other libraries. “OpenGL Command Names” explains the OpenGL naming conventions, and “OpenGL Defined Types” lists the OpenGL defined types with their C data type equivalents.

  • State Variables. Like IRIS GL, OpenGL maintains state variables for color, fog, texture, lighting, viewport, and so on. But OpenGL manages state variables more directly and consistently than IRIS GL does. With OpenGL there are no tables—you just load values directly.

    Because OpenGL doesn't keep tables of predefined lights and materials, it has no equivalent for “binds,” although you can use display lists to get a similar effect. “Porting defs, binds, and sets: Replacing `Tables' of Stored Definitions” explores different approaches to replacing display lists. Refer also to “Porting Lighting and Materials Calls” and “Porting Texture Calls” for more discussion and some examples.

  • Display Lists. OpenGL display lists are not editable. In OpenGL, the sole purpose of display lists is to efficiently cache OpenGL commands. As a result, IRIS GL calls for editing display lists have no OpenGL equivalent. If your IRIS GL program edits display lists, you have to reimplement it to some extent. “Porting Display Lists” lists the relevant IRIS GL calls, and “Achieving Edited Display List Behavior” provides some suggestions for porting code that edits display lists.

  • Fonts. IRIS GL provides calls to handle fonts and text strings. Although OpenGL can render text, it doesn't provide a file format for fonts. For fonts and text strings, you can use the GLX call glXUseXFont() in conjunction with the OpenGL calls glCallLists() and glListBase(). “Fonts and Strings” provides suggestions for porting fonts and strings.

  • Utility Library. OpenGL provides a utility library, called the GL Utility Library (GLU), that contains additional routines (such as NURBS and quadric surfaces rendering routines). This library is discussed in the OpenGL Programming Guide. Reference pages for all the routines the GLU consists of are included in the OpenGL Reference Manual. These routines all begin with the “glu” prefix (gluDisk(), gluErrorString(), and so on).

Tools and Libraries to Help Port Your Code

Silicon Graphics provides tools and libraries to help you port your IRIS GL program:

  • The toogl tool translates your program's IRIS GL calls to OpenGL calls. toogl does do a lot of the translation work for you but it can't translate everything (in particular, it can't translate windowing and event calls). You therefore have to edit the output. Chapter 2, “Using the toogl Tool,” explains how to use toogl.

  • The OpenGL extension to X (GLX) provides a variety of routines to help you replace your old IRIS GL windowing, event, and font calls. Chapter 4 explains how to use GLX. Reference pages for the GLX routines are included in the OpenGL Reference Manual. Consider looking at the glXIntro reference page first for an overview.

  • The GLwDrawingArea and GLwMDrawingArea widgets help you port your code to run in an X window. These widgets provide a window with the appropriate visual and color maps needed for OpenGL, based on supplied parameters. They also provide callbacks for redraw, resize, input, and initialization. For information on how to use these widgets, see Chapter 4.

  • The GLUT Library is a programming interface with ANSI C and FORTRAN bindings for writing window system independent OpenGL programs. The toolkit supports the following functionality:

    • Multiple windows for OpenGL rendering

    • Callback-driven event processing

    • Sophisticated input devices

    • An “idle” routine and timers.

    • A simple cascading pop-up menu facility

    • Utility routines to generate various solid and wire frame objects

    • Support for bitmap and stroke fonts

    • Miscellaneous window management functions, including managing overlays

    You can find the GLUT library (and the associated documentation) on the OpenGL home page http://www.opengl.org, or the Silicon Graphics OpenGL page, http://www.sgi.com/Technology/openGL/. It is also discussed in OpenGL Programming for the X Window System; see “Where to Get More Information”.

Porting IRIS GL Programs to OpenGL

This section lists three porting scenarios. Select the one that best matches your situation and complete the porting tasks listed. More information is provided in subsequent chapters. This overview discusses the major porting tasks for different kinds of programs:

In all cases, after you've finished the porting tasks listed, you probably have to iteratively compile, run, and debug your program. If necessary, run the toogl script again to catch any IRIS GL commands that you missed. You may find it useful to refer to “Error Handling” which gives some basic information on error handling in OpenGL.

Porting IRIS GL Programs That Use X Calls

If your IRIS GL program uses X for all window system calls, including windowing and event handling, it will be relatively easy to port it to OpenGL. Here's what you have to do:

  1. Run your program through a C beautifier (such as cb).

  2. Run the toogl filter script on your code.

  3. Edit toogl output. See Chapter 2 for a list of known trouble spots where you have to port your code explicitly. See Chapter 3, “After toogl: How to Finish Porting to OpenGL,” for specific suggestions.

  4. Convert your IRIS GL X Window System calls to GLX calls.

    • If you used one of the Motif widgets, GlxDraw or GlxMDraw, switch to the OpenGL version: GLwDrawingArea or GLwMDrawingArea. Chapter 4 discusses mixed-model programming in OpenGL and provides information about the OpenGL version of the Silicon Graphics mixed-model widget.

    • If you didn't use a widget, look at Appendix F, “Example Mixed-Model Programs With Xlib.”

    • The OpenGL Reference Manual contains an overview of the OpenGL Extension to the X Window System. It also includes a glXIntro reference page and reference pages for all the OpenGL/X routines.

    • OpenGL Programming for the X Window System by Mark Kilgard discusses all aspects of using OpenGL in the X Window System environment. See “Where to Get More Information” for complete bibliographical information.

Porting IRIS GL Programs With Simple Windowing

If your program doesn't use X Window System calls but does use simple windowing, you can probably use the GLUT library to replace IRIS GL windowing, color map, and event handling calls. This is possible if your code meets the following conditions:

  • Is reasonably simple

  • Conforms to Silicon Graphics recommendations

  • Doesn't use unsupported calls,

Here's what you have to do:

  1. Replace windowing and event handling calls with GLUT calls.

  2. Run your program through a C beautifier (such as cb).

  3. Run the toogl filter script on your code.

  4. Edit toogl output. See Chapter 2 for a list of known trouble spots. You will probably have port some of the trickier commands explicitly; see Chapter 3 for specific suggestions.

Porting IRIS GL Programs With Complex Windowing

If your IRIS GL code doesn't use X windowing calls and your windowing and event handling code uses unsupported calls, doesn't conform to Silicon Graphics recommendations, or is complicated or unusual in scope, using the X Window System is the best solution.

Here's what you have to do:

  1. Run your program through a C beautifier (such as cb),

  2. Run the toogl filter script on your code.

  3. Edit toogl output. See Chapter 2 for a list of known trouble spots. You will probably have port some of the trickier commands explicitly; see Chapter 3 for specific suggestions.

  4. Port your program to use OpenGL and X. You can do this either by using Xlib and directly replacing calls like winopen() and qread() with their GLX equivalents, or by using Xt along with a widget set and the OpenGL widget GLwDrawingArea. See Chapter 4 for more information.

If You're Not Porting Your Code to OpenGL Yet

If you're not porting to OpenGL now, but know that you will be porting in the future, it's a good idea to switch to mixed-model mode now.

  • Replace all GL windowing calls with GLX and X calls.

  • Replace GL event handling with X event handling. Refer to the Graphics Library Programming Tools and Techniques manual for detailed instructions.

  • Learn what IRIS GL features have no OpenGL equivalents. Avoid using them in new code, and reimplement code that does use them. Appendix A, “OpenGL Commands and Their IRIS GL Equivalents,” lists IRIS GL commands and indicates which commands are not supported in OpenGL.

  • Replace any obsolete or unsupported calls with newer IRIS GL equivalents as soon as possible.