Next | Prev | Up | Top | Contents | Index

How to Create Overlays

This section explains how to create overlay planes, using an example program based on Motif. If you create the window using Xlib, the same process is valid (and a parallel example program is available in the example program directory).

The example program from which the code fragments are taken, motif/overlay.c, uses the visual info extension to find a visual with a transparent pixel. See "The Visual Info Extension" for more information.

Note: This example does not work if the visual info extension is not available (see "How to Check for OpenGL Extension Availability"). The visual info extension is available only in IRIX 6.2. In IRIX 5.3 and earlier releases, you must look at the TRANSPARENT_OVERLAYS property on the root window to get the information. To create the overlay, follow these steps:

  1. Define attribute lists for the two widgets (the window and the overlay). For the overlay, specify GLX_LEVEL as 1 and GLX_TRANSPARENT_TYPE_EXT as GLX_TRANSPARENT_RGB_EXT if the visual info extension is available.

    static int attribs[] = { GLX_RGBA, GLX_DOUBLEBUFFER, None};

    static int ov_attribs[] = {

    GLX_BUFFER_SIZE, 2,

    GLX_LEVEL, 1,

    GLX_TRANSPARENT_TYPE_EXT, GLX_TRANSPARENT_RGB_EXT,

    None };

  2. Create a frame and form, then create the window widget, attaching it to the form on all four sides. Add expose, resize, and input callbacks.

    /* specify visual directly */

    if (!(visinfo = glXChooseVisual(dpy, DefaultScreen(dpy), attribs)))

    XtAppError(appctx, "no suitable RGB visual");

    /* attach to form on all 4 sides */

    n = 0;

    XtSetArg(args[n], XtNx, 0); n++;

    XtSetArg(args[n], XtNy, 0); n++;

    XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;

    XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;

    XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;

    XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;

    XtSetArg(args[n], GLwNvisualInfo, visinfo); n++;

    state.w = XtCreateManagedWidget("glxwidget",

    glwMDrawingAreaWidgetClass, form, args, n);

    XtAddCallback(state.w, GLwNexposeCallback, expose, NULL);

    XtAddCallback(state.w, GLwNresizeCallback, resize, &state);

    XtAddCallback(state.w, GLwNinputCallback, input, NULL);

    state.cx = glXCreateContext(dpy, visinfo, 0, GL_TRUE);

  3. Create the overlay widget, using the overlay visual attributes specified in Step 1 and attaching it to the same form as the window. This assures that when the window is moved or resized, the overlay is as well.

    if (!(visinfo = glXChooseVisual(dpy, DefaultScreen(dpy),

    ov_attribs)))

    XtAppError(appctx, "no suitable overlay visual");

    XtSetArg(args[n-1], GLwNvisualInfo, visinfo);

    ov_state.w = XtCreateManagedWidget("overlay",

    glwMDrawingAreaWidgetClass, form, args, n);

  4. Add callbacks to the overlay.

    XtAddCallback(ov_state.w, GLwNexposeCallback, ov_expose, NULL);

    XtAddCallback(ov_state.w, GLwNresizeCallback, resize, &ov_state);

    XtAddCallback(ov_state.w, GLwNinputCallback, input, NULL);

    ov_state.cx = glXCreateContext(dpy, visinfo, 0, GL_TRUE);

    Note that the overlay uses the same resize and input callback:

  5. Call XRaiseWindow() to make sure the overlay is on top of the window.
   XRaiseWindow(dpy, XtWindow(ov_state.w));

Next | Prev | Up | Top | Contents | Index