hide random home http://www.sgi.com/tech/openGL/mjk.intro/subsection3_4_1.html (Silicon Surf Promotional CD, 01/1995)



Next: 4.2 Scene Update Up: 4 A Simple Example Previous: 4 A Simple Example

4.1 Initialization

The following describes the steps involved in setting up a window to render OpenGL into it. The numbers listed correspond to numbers in the comments of the OpenGL program in Appendix A.

  1. As in all X programs, XOpenDisplay should be called to open a connection to the X server.
  2. Make sure the OpenGL GLX extension is supported by the X server.
  3. Before creating the window, the program needs to select an appropriate visual. The GLX routine glXChooseVisual makes it easy to find the right visual. In the example, an RGBA (and TrueColor) visual with a depth buffer is desired and if possible, it should support double buffering.
  4. Create an OpenGL rendering context by calling glXCreateContext.
  5. Create a window with the selected visual. Most X programs always use the default visual but OpenGL programmers will need to be comfortable with using visuals other than the default. XCreateWindow is called.
  6. Bind the rendering context to the window using glXMakeCurrent. Subsequent OpenGL rendering commands will use the current window and rendering context.
  7. To display the window, XMapWindow should be called.
  8. Set the desired OpenGL state. In this example, depth buffering is enabled, the clear color is set to black, and the 3D viewing volume is specified.
  9. Begin dispatching X events.
Button presses change the angle of rotation for the object to be viewed and cause a redraw. Expose events also cause a redraw (without changing the rotation). Window resizes call glViewport to ensure the OpenGL viewport corresponds to the maximum dimensions of the window.


mjk@asd.sgi.com
Wed Oct 19 18:06:42 PDT 1994