Graphics 版 (精华区)

发信人: dcs (euraka), 信区: Graphics
标  题: Motif&Opengl(1)
发信站: 紫 丁 香 (Mon Mar 29 21:34:23 1999), 转信

2 OpenGL with Widgets

Your application's 3D viewing area can be encapsulated by an X Toolkit widget. There are two approaches to rendering
OpenGL into a widget. You can render OpenGL into a standard Motif drawing area widget, or you can use a special OpenGL
drawing area widget. 

The Motif drawing area widget would seem a natural widget for OpenGL rendering. Unfortunately, the X Toolkit's design
(upon which Motif relies) allows programmers to specify a widget's visual only if its class is derived from the shell widget class.
Shell widgets are often called ``top level'' widgets because they are designed to communicate with the window manager and
act as containers for other widgets. Non-shell widgets inherit the depth and visual of their parent widget. The Motif drawing
area widget class (like most widget classes) is not derived from the shell widget class. It is impossible (without resorting to
programming widget internals) to set the visual of a standard non-shell Motif widget differently than its ancestor shell widget. 

But in OpenGL, the X notion of a visual has expanded importance for determining the OpenGL frame buffer capabilities of an
X window. In many cases, an application's 3D viewing area is likely to demand a deeper, more capable visual than the default
visual which Motif normally uses. 

There are two options: 

   1.Use the standard Motif drawing area widget for your OpenGL rendering area and make sure that the top level shell
     widget is created with the desired visual for OpenGL's use. 
   2.Use an OpenGL drawing area widget that is specially programmed to overcome the limitation on setting the visual and
     depth of a non-shell widget. 

Either approach works. 

The paperplane example in the appendix is written to support either scheme depending on how the code is compiled. By
default, the code compiles to use the OpenGL-specific widget. If the noGLwidget C preprocessor symbol is defined, the
standard Motif drawing area widget will be used, forcing the use of a single visual throughout the example's widget hierarchy.
The code differences between the two schemes in the paperplane example constitute seven changed lines of code. 

The preferable approach is to use the OpenGL-specific widget, since you can run most of the application's user interface in the
default visual and use a deeper, more capable visual only for 3D viewing areas. Limiting the use of deeper visuals can save
memory and increase rendering speed for the user interface windows. If you use a 24-bit visual for your 3D viewing area and
use the same visual for your entire application, that means that the image memory for pixmaps used by non-OpenGL windows
is four times what it would be for an 8-bit visual. Some X rendering operations might also be slower for 24-bit windows
compared with 8-bit windows. 

There can be advantages to running your entire application in a single visual. Some workstations with limited colormap
resources might not be capable of showing multiple visuals without colormap flashing. Such machines which support OpenGL
should be rare. Even if running in a single visual is appropriate, nothing precludes doing so using an OpenGL-specific widget. 








--
※ 来源:.紫 丁 香 bbs.hit.edu.cn.[FROM: 202.118.239.121]
[百宝箱] [返回首页] [上级目录] [根目录] [返回顶部] [刷新] [返回]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:1.988毫秒