Scanning pods... Creating GLwDrawingArea.html from GLwDrawingArea.pod
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 Motif 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 open GL 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 are created in 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 open GL 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 open GL 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.
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).
If TRUE, the background pixel and pixmap will be allocated if appropriate using the newly calculated colormap and visual. If FALSE, they will retain values calculated using the parent's colormap and visual. Applications which wish to have X clear their background for them will usually set this to TRUE. Applications clearing their own background will often set this to FALSE, although they may set this to TRUE if they query the background for their own use. One reason to leave this resource FALSE is that if color index mode is in use this avoid using up a pixel from the newly allocated colormap. Also, on hardware that supports only one colormap, the application may need to do more careful color allocation to avoid flashing between the openGL colormap and the default X colormap. (Note that because of the way Xt works, the background colors are originally calculated using the default colormap; if this resource is set they can be recalculated correctly. If a colormap was explicitly supplied to the widget rather than being dynamically calculated, these resources are always calculated using that colormap.)
This is similar to GLwNallocateBackground , but allocates other colors normally allocated by widgets. Although the GLwDrawingArea and GLwMDrawingArea widget do not make use of these colors the application may choose to query them. For the non-Motif GLwDrawingArea widget there are no other colors allocated, so this resource is a no-op. For the Motif GLwMDrawingArea are widget, the XmPrimitive resources XmNforeground, XmNhighlightColor, and XmNhighlightPixmap are calculated.
The input callback is provided as a programming convenience, as it provides a convenient way to catch all input events. However, a more modular program can often be obtained by providing specific actions and translations in the application rather than using a single catch all callback. Use of explicit translations can also provide for more customizability.
If set to TRUE, the background is installed on the window. If set to FALSE, the window has no background. This resource has no effect unless GLwNallocateBackground is also TRUE.
Both GLwDrawingArea and GLwMDrawingArea inherit behavior and resources from the core superclass. Other than the behavior of the colormap and background resources described previously, all defaults are the same as for core.
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.
GLwMDrawingArea has the following additional translation:
An application wishing to catch other events than these defaults can do so by installing a different translation table.
Between the time the widget is created and it is realized, the following apply:
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
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 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.
e
EXAMPLE
Here are some code fragments that create a GLwDrawingArea
widget, and manage the appropriate callbacks.
WARNINGS
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.
RELATED INFORMATION
glXChooseVisual,
GLwDrawingAreaMakeCurrent
, glXMakeCurrent,
GLwDrawingAreaSwapBuffers, GLwCreateMDraw, Core,
XmPrimitive, VirtualBindings, Gflush),
XSetWMColormapWindows and the Open GL spec.
DATE
$Id: GLwDrawingArea.pod,v 1.3 1995/04/11 23:42:06 ohl Exp $