Chapter 15

The End—the Beginning

Well, you have covered a lot of territory in OpenGL and now have the basic tools you need 
to render and even animate great OpenGL scenes. Most importantly you have seen how to 
integrate OpenGL with Delphi. Take a moment to catch your breath, then congratulate 
yourself, then brace yourself. Although this book has given you a lot of OpenGL information 
and practice, it barely scratches the surface of what you can do with OpenGL.

More Buffers

Many OpenGL features have not even been explored in this book. You have read about 
several buffers in OpenGL, for example, but they are not the only ones. There are interesting 
things you can do with the stencil buffer, such as blocking out parts of a scene, that are 
outside the scope of this book that you may want to explore. You could use still another 
buffer, the accumulation buffer, to simulate motion blur.

More Curves

The curved surfaces you produced with small polygons and smooth shading are not the only 
way you can make curves in OpenGL. You could draw Bézier curves and surfaces or even 
Nurbs (Non-uniform rational B-splines).

More Effects

While this book did briefly introduce a simple shadow technique, there are many other ways 
available to produce shadows that are much better, albeit with serious performance hits. 
Special techniques such as rendering in more than one pass, with different states turned on 
or off in each pass, can produce significant effects such as highlighting on a texture.


PAGE 447
 More Math

In this book you needed nothing more than beginning algebra, and that rarely. You have 
seen that you can do a lot without getting very mathematical. OpenGL handles the gory 
details quite well. But, face it, if you really want to get fancy with three-dimensional 
graphics, you will have to get your hands dirty with math.

Matrix Math

Obviously, by the matrix nature of OpenGL, a good understanding of matrix manipulation 
and uses of matrices in three-dimensional graphics will help.

Algebra

A really solid grasp of algebra, trigonometry, and geometry will certainly be a plus. The 
more you know, the easier you can produce algorithms to reach your goals. You may be able 
to solve many problems without much knowledge in these areas, but you will have to work 
harder to get there.

Esoterica

Other branches of mathematics can also help you with some very special effects. Calculus 
and symmetry theory, for example, have been used to solve some difficult graphics 
problems.

More Information

There is more to know about the general nature of OpenGL, such as the basic steps that 
OpenGL takes to produce a pattern of colored pixels on the screen that you perceive as a 
scene.

Kinds of Data
There are two kinds of data that enter OpenGL’s processing: pixel data and geometry data. 
These two kinds of data go through two different pipelines until they merge near the end to 
produce the final step of pixels in the frame buffer.

PAGE 448
 Geometry Data

Geometric primitives can be points, lines, or polygons, which always resolve to vertices. 
These can come from the program in immediate mode (commands executed directly), from 
display lists, or even from evaluators for Béziers and Nurbs. The latter may start out as curve 
specifications, but they eventually turn into vertices. As you saw from the feedback chapter, 
vertex data consists of a lot more than just space coordinates.

In whatever way the vertex data arrives, it goes to vertex operations and primitive assembly. 
In the operations on each vertex, OpenGL transforms the vertex by the ModelView matrix, 
then by the projection matrix, along with clipping. Then OpenGL performs perspective 
division, which is dividing by the w coordinate. Finally OpenGL performs depth range and 
culling operations as appropriate and the viewport transformations to produce window 
coordinates. At this time OpenGL performs lighting calculations on the transformed 
coordinates.

The next step is rasterization. OpenGL determines which squares in a grid of window 
coordinates are occupied. The fragments produced here go to the fragment operations.

In the operations on each fragment, if texturing is involved, OpenGL generates texels. It then 
performs fog calculations as appropriate. OpenGL performs the scissor test, the alpha test, 
the stencil test, the depth-buffer test, and blending, if enabled. The results are written into 
the appropriate buffer and stored as pixels in the frame buffer.

Pixel Data

Pixel data such as bitmaps and images are unpacked into memory with the appropriate 
layout. Then operations you specify with OpenGL commands are applied. From that point, 
the pixel data may go directly to texture memory or proceed to the rasterization step just as 
if it came from geometry data. Interestingly, image data may come originally from the frame 
buffer, packed into an appropriate format, and sent back around. It almost sounds like 
having a cow drink milk for recycling, but it actually has its uses.

More Efficiency

When you want animation, you want efficiency, and three-dimensional graphics is the very 
antithesis of that. A huge amount of computation goes into rendering a 3-D scene. 
Fortunately, modern PCs have an astonishing 

PAGE 449
 amount of “horsepower” and modern video cards typically include hardware acceleration 
support for OpenGL.

Still, you do not have to introduce very much complication into an OpenGL scene to start 
bogging down your frame rate. As you advance in your knowledge of OpenGL internals, 
you can develop techniques in your coding that improve the efficiency of the code you write 
for using OpenGL capabilities.

You will, for example, want to do such things as minimize the number of state changes per 
frame. OpenGL has to perform internal calculations and realign pointers, etc., when you 
change states. Suppose you have to enable texturing for a certain part of your scene, and 
leave it disabled for the rest of the scene, except for one part where it uses a different texture. 
You may have to perform several state changes relating to the texturing before each of those 
two parts. You may find efficiency is greater if you leave the glEnable (GL_TEXTURE_2D) as 
the last change. While texturing is disabled and you make texture-related state changes, 
OpenGL only has to store the fact of the new state for each call. When you make the glEnable 
call, OpenGL performs all its calculations and adjustments only once. If, instead, you 
enabled texturing first, and the other texturing state changes afterward, OpenGL would 
have to perform its internal acrobatics with each state change you make.

With this one fact alone, you can go back and improve the frame rate of several of the 
example programs. Imagine what you can do if you really get into it!

More Resources

Naturally, you can expand your knowledge of various kinds of mathematics and general 
graphics principles with textbooks and reference books, but there is also a wealth of 
information on the Internet.

There are newsgroups and mailing lists devoted to OpenGL, to writing games, to general 
graphics topics, and much more. There are many web sites containing treatises on related 
subjects. On the CD included with this book is an HTML file with links to many such 
resources. You can expand your knowledge just as far as you want to go.

In conclusion, you may have reached the end of this book and obtained just about all you 
want, because it is enough for you to do great things with three-dimensional graphics. If, 
however, you want to go beyond even that, your learning adventure has just begun.

PAGE 450

