Note that if you are not careful when you create a popup menu as a child of GLwMDrawingArea widget, you may get a BadMatch X protocol error: The menu (like all other Xt shell widgets) inherits its default colormap and depth from the GLwMDrawingArea widget, but its default visual from the parent (root) window. Since the GLwMDrawingArea widget is normally not the default visual, the menu inherits a nondefault depth and colormap from the GLwMDrawingArea widget, but also inherits its visual from the root window (that is, inherits the default visual); leading to a BadMatch X protocol error. See "Inheritance Issues" for more detail and for information on finding the error.
There are two ways to work around this:
static void create_popup(Widget parent) { Arg args[10]; static Widget popup; int n; XmButtonType button_types[] = { XmPUSHBUTTON, XmPUSHBUTTON, XmSEPARATOR, XmPUSHBUTTON, }; XmString button_labels[XtNumber(button_types)]; button_labels[0] = XmStringCreateLocalized("draw filled"); button_labels[1] = XmStringCreateLocalized("draw lines"); button_labels[2] = NULL; button_labels[3] = XmStringCreateLocalized("quit"); n = 0; XtSetArg(args[n], XmNbuttonCount, XtNumber(button_types)); n++; XtSetArg(args[n], XmNbuttonType, button_types); n++; XtSetArg(args[n], XmNbuttons, button_labels); n++; XtSetArg(args[n], XmNsimpleCallback, menu); n++; popup = XmCreateSimplePopupMenu(parent, "popup", args, n); XtAddEventHandler(parent, ButtonPressMask, False, activate_menu, &popup); XmStringFree(button_labels[0]); XmStringFree(button_labels[1]); XmStringFree(button_labels[3]); } main(int argc, char *argv[]) { Display *dpy; XtAppContext app; XVisualInfo *visinfo; GLXContext glxcontext; Widget toplevel, frame, glxwidget; toplevel = XtOpenApplication(&app, "simple-popup", NULL, 0, &argc, argv, fallbackResources, applicationShellWidgetClass, NULL, 0); dpy = XtDisplay(toplevel); frame = XmCreateFrame(toplevel, "frame", NULL, 0); XtManageChild(frame); /* specify visual directly */ if (!(visinfo = glXChooseVisual(dpy, DefaultScreen(dpy), attribs))) XtAppError(app, "no suitable RGB visual"); glxwidget = XtVaCreateManagedWidget("glxwidget", glwMDrawingAreaWidgetClass, frame, GLwNvisualInfo, visinfo, NULL); XtAddCallback(glxwidget, GLwNexposeCallback, expose, NULL); XtAddCallback(glxwidget, GLwNresizeCallback, resize, NULL); XtAddCallback(glxwidget, GLwNinputCallback, input, NULL); create_popup(frame); XtRealizeWidget(toplevel); glxcontext = glXCreateContext(dpy, visinfo, 0, GL_TRUE); GLwDrawingAreaMakeCurrent(glxwidget, glxcontext); XtAppMainLoop(app); }