i
i
i
i
i
i
i
i
326 13. Programming 3D Graphics in Real Time
use a storage scheme based on chunks. There is a chunk to store the vertex
data, one to store the triangle face/polygon data and numerous others. Each
chunk comes with a header (OpenFX has a four-character ID and 3DS a
two-byte magic number) and a four-byte length. Any program parsing this
file can jump over chunks looking for those it needs by moving the file pointer
forward by the size of a chunk.
A fairly simplistic algorithm which attempts to locate strips of triangles
such as those in the mesh illustrated in Figure 13.5 is provided by function
StripFaces(). The strategy of the algorithm is summarized in Figure 13.6.
The algorithm locates groups of polygons that can form strips and sets the
member variable
next in each polygon’s data structure so that it behaves like
a linked list to vector a route through the array of polygons stored in RAM
at an address pointed to by
MainFp. By following this trail, the polygons can
be rendered as a triangle strip, thus taking advantage of OpenGL’s rendering
acceleration for such structures.
13.1.6 Rendering the 3D Data
We shall discuss rendering with the use of five listings so as to highlight the
differences which occur when one uses OpenGL to render simply-shaded
polygons, polygons that make up the whole or part of a smooth, rather than
faceted, object. We shall also introduce the display list, which allows further
optimization of the rendering process.
Display lists are very useful because they allow us to prepare a kind of
ready-made scene, one that can be quickly configured and rendered without
having to load all the vertices and images from the host computer’s RAM.
For a VR application, a display list can be used to store all the OpenGL
commands to render a mesh model, independent of taking any particular
view. The program’s user can then view the object from any angle by calling
the display list after position and rotation transformations are set up. Using a
display list works in this case because the mesh does not change over time. If the
mesh were deforming or moving, the list would have to be regenerated after each
change to the mesh.
The function which is called to render a particular view or in response
to a
WM PAINT message appears in Listing 13.11. Note that a transformation
of −5.0 is applied to the negative z-axis; this moves the model away from
the camera so that it all is visible, i.e., we see the outside. If the model were
of a virtual environment, we would wish to keep it centered at (0, 0, 0) and