i
i
i
i
i
i
i
i
13.1. Visualizing a Virtual World Using OpenGL 317
vertices at most. Many 3D CAD software packages, however, use some form
of parametric surface description, NURBS or other type of surface patch.
OpenGL provides a few NURBS rendering functions, but these are part of the
auxiliary library and are u nlikely to be implemented in the GPU hardware,
so they tend to respond very slowly.
Even within applications which concentrate on simple triangular or quadri-
lateral polygons, there can be quite a bit of difference in their data structures.
OpenFX, for example, assigns attributes on a per-polygon basis, whereas 3DS
uses a materials approach, only assigning a material identifier to each poly-
gon, and thus whole objects or groups of polygons have the same attributes.
OpenGL assumes that vertices carry the attributes of color etc., and so in the
case of rendering polygons from an OpenFX mesh, many calls to the func-
tions that change the color state variable are required. Another difference
between OpenFX and 3DS concerns mapping. Fortunately, both packages
support mapping coordinates, and this is compatible with the way OpenGL
handles image mapping.
In the basic fixed-functionality pipeline of OpenGL, the lighting and
shading models are somewhat limited when compared to the near-photorealistic
rendering capability of packages such as 3ds Max, and some compromises
may have to be accepted.
Often, hardware acceleration poses some constraints on the way in which
the data is delivered to the hardware. With OpenGL, it is much more effi-
cient to render triangle strips than individual triangles. However, often tri-
angle meshes, especially those that arise by scanning physical models, are not
recorded in any sort of order, and so it can be well worth preprocessing or
reprocessing the mesh to try to build it up from as many triangle strips as
possible.
Most 3D modeling packages use a right-handed coordinate system in
which the z-axis is vertical. OpenGL’s right-handed coordinate system has
its y-axis vertical, and the default direction of view is from (0, 0, 0) looking
along the −z-direction. With any mesh model, we must be careful to remem-
ber this and accommodate the scales involved, too. In our 3D application
examples, we will always scale and change the data units so that the model
is centered at (0, 0, 0), the ver tex coordinates conform to OpenGL’s axes and
the largest dimension falls in the range [−1, +1].
The main window’s message-handling function pr ocesses a number mes-
sages. Listing 13.5 singles out the
WM TIMER message, which is used to incre-
ment the angular rotation of the model every few milliseconds and
WM COMMAND to handle commands from the user menu.