Professional Documents
Culture Documents
This book is meant for computer science students and computer science teachers
alike who want to get the same graphics capabilities that certain special computer
wizards - usually teenage males - are constantly using. You, the student or teacher,
have no idea what these kids are doing. You do know, however, that they control
more colors, that their programs generally move faster, and that create all sorts of
dazzling effects, but you really have no idea what is going on.
Somehow you feel that these graphics wizards belong to a unique society. They are
like magicians, their knowledge carefully guarded and shared with those who belong
to the same secret society. Like magicians, everything they do appears effortlessly
simple, and yet, the results are amazing. Where your graphics images move with
sluggish hesitation, their graphics sprites bounce around with ease. Where you have
proudly mastered the sixteen basic VGA colors, they display a dazzling variety of
many different shades of each one of your 16 colors. Where you finally after much
effort managed to slowly save and load some graphics to and from a file, their
images leap onto the screen. You do not know what they are doing, exactly, but you
know that their way is better than yours. You can see the results. The society,
however, is closed, and membership is open only to those who speak the special
language.
Your feelings are shared by many students and teachers alike. Many people look at
their computer science textbooks and carefully follow the examples outlined in the
various chapters, but nothing seems to produce results similar to those of their more
gifted neighbors. For teenage students who do not belong to the society, there is no
problem. Many decide it is somehow genetic, and they simply do not have the
special genes.
Adults, and teachers especially, are more likely to feel uncomfortable. College
computer science courses place almost no emphasis on computer graphics
programming. The few courses that do exist on computer graphics start in outer
space on day-1, and end up in the next galaxy by day-5. An extremely brief look at
the course description discourages all but the very motivated. This leaves most
computer science teachers, perhaps like you, to the tried and true method of learning
the material on your own. Enthusiastically you sit behind your computer and
struggle through the supplied reference manual. Piece by piece, bit by bit, various
routines are making sense and start to take shape. You are happy and proudly walk
into the computer lab . . . and then you see the graphics on the screens of some of
You also feel discouraged when you look at the code of these graphics programs. It
is not familiar, and it does not even resemble any normal program. The code may
look something like the code shown in the sub programs below.
─────────────────────────────────────────────────────────────────────────
void SetMode(unsigned Mode)
{
_AX = Mode;
geninterrupt(0x10);
} // void function setmode
void SetPalette(PaletteType P)
{
outp(0x03C8,0);
for (Byte Count = 0; Count <= 255; Count++)
{
outp(0x03C9,P[Count].Red);
outp(0x03C9,P[Count].Grn);
outp(0x03C9,P[Count].Blu);
} // for count
} // void function setpalette
─────────────────────────────────────────────────────────────────────────
The code of these three routines includes some pretty bizarre looking stuff. Program
code that includes words like geninterrupt, outp, peekb, combined with strangely
positioned 0x numbers does not make much sense. What is going on, and where do
these kids get this stuff anyway?
What is going on is plenty logical. The purpose of this book is not only to give you
the power of advanced graphics routines, but also explain how such routines work.
You are about to enter the secret society, but remember, introduction into this society
is limited to those who have the power . . . and the power can only be acquired with
knowledge. This book combined with hands-on practice will give you the necessary
knowledge.
Too many graphics books plunge the poor readers into large obscure looking
routines that are very interesting, especially to the author of the graphics book, but
leave the reader bewildered. In this book, you will be looking at many small
programs that focus on one concept and guide you, with manageable increments,
from introductory basics to considerably complex concepts.
Don't be fooled by the fact that such kids give the impression that everything is so
easy. I have seen students in my class struggle to learn new concepts and after
considerable effort and agony they learned something new and exciting ... only to
turn around to see other struggling students who had "not yet arrived." These
beginners-turned-experts act as if there is no complexity to be concerned about, and
they seem surprised that anybody would be "confused about such simplicity."
You might wonder what knowledge a person should have in order to handle the
material in this book. You do realize that "Advanced Graphics" is not meant for the
person who is at the stage of wondering how to format a diskette. The explanations
in this book assume a good understanding of programming in C++. At a minimum
you should be comfortable with the amount of computer science that is normally
taught in the "A" level A.P. Computer Science course.
People learn at their own pace. Take this book, and go as quickly or as slowly as
you like. We hope that you will enjoy the material presented here, and that it will
give you a better understanding of computer graphics.
The program examples printed in this book come directly from the companion disk.
All printed examples were compiled and tested before being loaded into the word
processing file. Whether you look at the code in this book or on the disk, it will
follow the same style. It will be helpful to understand some of the conventions that
All Turbo C++ reserved words like void, struct, if, for, while, etc., must be
written in lower case, and are always shown in lower case.
All Turbo C++ predefined identifiers like cout, cin, getch, clrscr, etc. are
also shown in lower case.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
Some readers may be aware that there never existed a first edition of this book.
Reprinting the introduction to a "first edition" that never existed may seem quite
bizarre. The first edition of Student Friendly Advanced VGA Graphics was written
in Pascal. VGA graphics is based on concept that are not necessarily language
dependent. Both the Pascal and C++ second editions are based on the groundwork
IMPROVED ANIMATION
Additional program examples have been provided in the area of animation. The first
edition did show many examples, but it lacked programs with moving sprites over a
colored background without destroying the background. We realized that all the
examples showed movement over a black background. The second edition
addresses that shortcoming, and provides many detailed steps from clumsy, jerky
animation to a dozen sprites simultaneously moving across the monitor.
3D GRAPHICS EXPLAINED
In creating the first edition, we ran out of time when we reached the 3d graphics
chapter. Routines were provided, but explanations were not given. The second
edition starts with a variety of simpler 3d graphics routines that are admittedly slow,
but easier to understand. More advanced 3d graphics is slowly introduced, and we
hope that the explanations make sense. You must realize however that this book in
general and 3d graphics more specifically requires a good understanding of
mathematics. Anybody who thinks that the Sine of X is a circular board with a big
letter X on it might find the going tough.
SOUND APPENDIX
Sound is not an area of graphics, but many graphics programs, however, do include
sound effects and many people asked for information about sound. An appendix is
included that basically is a short chapter with a number of sound programs. It also
includes a Sound library that gives you the power to create your own music.
IN CONCLUSION
If you have purchased this new graphics book, you should have received a diskette
containing all the sample programs listed in the text. Having the programs available
can save you the time of entering it in manually, but typing in the code yourself can
help you achieve a better understanding of the concepts described.
We have suffered, agonized, rejoiced, and learned by the creation of this book. We
sincerely hope that our efforts will make it simpler for you and other people
interested in graphics to learn this fascinating subject. Please do not think that this
book is the final authority and complete bible of graphics. The subject of graphics is
huge in scope, but we do think that a suitable amount of material is presented that
allows you to explore graphics and write some fun graphics programs on your own.
Our wish is that this book will be useful for you and that learning graphics will be
more fun than frustration.
David Quarfoot, Leon Schram, Jaspreet Sidhu, Robby Slaughter, and Jason Wang