#include <X11/GLw/GLwMDrawA.h>
ld ... -lGLw -lGL -lXm -lXext -lXt -lX11 -lm
GLwDrawingArea is not a part of any widget set, but depends only on Xt. GLwDrawingArea can be used with any widget set. GLwMDrawingArea is identical to GLwDrawingArea except that it is a subclass of the MotifTm widget class XmPrimitive and has resources and defaults suitable for use with Motif. For example, GLwMDrawingArea provides the default Motif background and foreground colors for resources, and deals better with keyboard traversal. Although the GLwDrawingArea widget can be used in a Motif program, it is recommended that GLwMDrawingArea be used instead.
Since both GLwDrawingArea and GLwMDrawingArea widgets behave almost identically, the remainder of this manual page will refer only to GLwDrawingArea, except when the behaviors differ. Unless explicitly stated, all statements about GLwDrawingArea also apply to GLwMDrawingArea.
Among the information provided when creating a GLwDrawingArea is information necessary to determine the visual. This may be provided in three ways, all of them through resources. A specific visualInfo structure may be passed in. (This visualInfo must have been obtained elsewhere; it is the application designer's responsibility to make sure that it is compatible with the OpenGL rendering done by the application). Alternatively, an attribute list may be provided. This attribute list is formatted identically to that used for direct open GL programming. Finally, each attribute can be specified as an individual resource. The latter method is the simplest, and is the only method that works from resource files.
In addition to allocating the visual, the GLwDrawingArea will also allocate the colormap unless one is provided by the application. (If one is provided it is the application writer's responsibility to guarantee compatibility between the colormap and the visual). If an application creates multiple GLwDrawingAreas with the same visual, the same colormap will be used. (However the colormap will not be shared among separate applications).
Creating the widget does not actually create the window until it is realized, and consequently, the application should not perform any OpenGL operations to the window immediately after creation. Instead the application must wait until after it has realized the window. Alternatively, the ginit callback may be used to indicate when the window has been created. Upon receiving this callback, the application can perform all OpenGL initialization for the window, and can subsequently perform other operations on it. The initialization is discussed in more detail below.
Applications select which GLwDrawingArea they are accessing using either glXMakeCurrent or the convenience function GLwDrawingAreaMakeCurrent which uses a widget instead of a display and window. If there is only one GLwDrawingArea this need only be called once, however if there is more than one GLwDrawingArea it should be called at the start of each callback. Callbacks in this case include not only callbacks provided by the widget itself, but any other callback that leads to GL activity such as a timeout or a workproc.
If an application is using double buffering, it may call GLwDrawingAreaSwapBuffers instead of glXSwapBuffers. This allows the use of the widget instead of the display and window.
Name | Class | Type | OpenGL attribute |
GLwNbufferSize | GLwCBufferSize | int | GLX_BUFFER_SIZE |
GLwNlevel | GLwCLevel | int | GLX_LEVEL |
GLwNrgba | GLwCRgba | Boolean | GLX_RGBA |
GLwNdoublebuffer | GLwCDoublebuffer | Boolean | GLX_DOUBLEBUFFER |
GLwNstereo | GLwCStereo | Boolean | GLX_STEREO |
GLwNauxBuffers | GLwCAuxBuffers | Boolean | GLX_AUX_BUFFERS |
GLwNredSize | GLwCColorSize | int | GLX_RED_SIZE |
GLwNgreenSize | GLwCColorSize | int | GLX_GREEN_SIZE |
GLwNblueSize | GLwCColorSize | int | GLX_BLUE_SIZE |
GLwNalphaSize | GLwCAlphaSize | int | GLX_ALPHA_SIZE |
GLwNdepthSize | GLwCDepthSize | int | GLX_DEPTH_SIZE |
GLwNstencilSize | GLwCStencilSize | int | GLX_STENCIL_SIZE |
GLwNaccumRedSize | GLwCAccumColorSize | int | GLX_ACCUM_RED_SIZE |
GLwNaccumGreenSize | GLwCAccumColorSize | int | GLX_ACCUM_GREEN_SIZE |
GLwNaccumBlueSize | GLwCAccumColorSize | int | GLX_ACCUM_BLUE_SIZE |
GLwNaccumAlphaSize | GLwCAccumAlphaSize | int | GLX_ACCUM_ALPHA_SIZE |
The following table lists other resources of the GLwDrawingArea widget. each of these will be described subsequently. The codes in the access column indicate if the given resource can be set at creation time (C), set by using XtSetValues (S), retrieved by using XtGetValues (G), or is not applicable (N/A).
Name | Class | Type | Def | Acc |
GLwNallocateBackground | GLwCAllocateColors | Boolean | F | CG |
GLwNallocateOtherColors | GLwCAllocateColors | Boolean | F | CG |
GLwNattribList | GLwCAttribList | int * | NULL | CG |
GLwNexposeCallback | GLwCCallback | XtCallbackList | NULL | C |
GLwNginitCallback | GLwCCallback | XtCallbackList | NULL | C |
GLwNinputCallback | GLwCCallback | XtCallbackList | NULL | C |
GLwNinstallBackground | GLwCInstallBackground | Boolean | T | CG |
GLwNinstallColormap | GLwCInstallColormap | Boolean | T | CG |
GLwNresizeCallback | GLwCCallback | XtCallbackList | NULL | C |
GLwNvisualInfo | GLwCVisualInfo | XVisualInfo* | NULL | CG |
In addition, the Motif version GLwMDrawingArea also inherits from XmPrimitive. The behavior of the color resources has been described previously. The TraversalOn resource is disabled for this widget, but if keyboard input is required it should be enabled. (Also, the application should call XmProcessTraversal(widget, XmTRAVERSE_CURRENT) whenever mouse button 1 is clicked in the widget. This is similar to the requirements of the Motif Drawing area.) Because Motif gets confused by having multiple visuals in one top level shell, XmNhighlightOnEnter has been disabled, and XmNhighlightThickness has been set to 0.
typedef struct { int reason; XEvent *event; Dimension width, height; } GLwDrawingAreaCallbackStruct;
GLwMDrawingArea has the following additional translation:
<Key>osfHelp: PrimitiveHelp()
An application wishing to catch other events than these defaults can do so by installing a different translation table.
When the widget is initially created (e.g. through XtCreateWidget(3X) ) the associated window is not actually created. Instead, window creation is delayed until the widget is realized. However, glXchooseVisual is called immediately, so information based on its results is available.
Between the time the widget is created and it is realized, the following apply:
When the widget is realized, the following actions take place:
When using the input callback to receive keyboard input, the keycode in the event must be converted to a KeySym. Use XLookupKeysym(3X) or XLookupString(3X) to do the conversion. Keyboard input can also be dealt using translations, in which case no such conversion is required.
Motif programmers should keep in mind that OSF uses virtual bindings and replaces some of the key bindings. As a common example, if the ESC key is to be used to exit the program (as it often is in GL programs), the translation should specify <key>osfCancel instead of <key>Escape.
Motif programmers may also create a GLwMDrawingArea widget with the Motif style GLwCreateMDrawingArea.
CW #include <stdlib.h> #include <X11/GLw/GLwDrawA.h> static GLXContext glx_context; /* assume only one context */ . . . main() { Arg args[10]; int n; Widget parent; /* The parent of the gl widget */ Widget glw; /* The GLwDrawingArea widget */ . . . /* Create the widget using RGB mode. This can also be set * in an X Defaults file */ n = 0; XtSetArg(args[n], GLwNrgba, True); n++; glw = XtCreateManagedWidget("glw", glwDrawingAreaWidgetClass, parent, args, n); XtAddCallback(glw, GLwNexposeCallback, exposeCB, NULL); XtAddCallback(glw, GLwNresizeCallback, resizeCB, NULL); XtAddCallback(glw, GLwNginitCallback, ginitCB, NULL); /* Also add input callback if needed */ . . . } static void exposeCB(Widget w, XtPointer client_data, GLwDrawingAreaCallbackStruct *call_data) { GLwDrawingAreaMakeCurrent(w, glx_context); /* redraw the display */ } static void resizeCB(Widget w, XtPointer client_data, GLwDrawingAreaCallbackStruct *call_data) { GLwDrawingAreaMakeCurrent(w, glx_context); /* perform any resize actions */ } static void ginitCB(Widget w, XtPointer client_data, GLwDrawingAreaCallbackStruct *call_data) { Arg args[1]; XVisualInfo *vi; XtSetArg(args[0], GLwNvisualInfo, &vi); XtGetValues(w, args, 1); /* create a visual context */ glx_context = glXCreateContext(XtDisplay(w), vi, NULL, GL_FALSE); GLwDrawingAreaMakeCurrent(w, glx_context); /* Perform any necessary graphics initialization.*/ }
The Motif program need only differ by including GLwMDrawingArea.h instead of GLwDrawingArea.h and by creating a widget of type GLwMDrawingAreaWidgetClass instead of GLwDrawingAreaWidgetClass. As an alternative, the Motif program could use GLwCreateMDraw(3X) instead.
If a GLwDrawingArea widget is created as a child of an already realized widget, the GLwDrawingArea widget will be created immediately, without giving the user an opportunity to add the ginit callback. In such a case, initialization should be done immediately after creating the widget rather than by using the callback.
If the non-Motif GLwDrawingArea widget is used in a Motif program and keyboard traversal is attempted, the behavior is undefined if the user traverses into the GLwDrawingArea widget.