Chapter 1
Chapter 1
Chapter 1
Computer Graphics
Chapter One: Introduction to Computer Graphics
1. Introduction
The term computer graphics has been used in a broad sense to describe "almost everything on
computers that is not text or sound". Typically, the term computer graphics refers to several
different things:
The representation and manipulation of image data by a computer
The various technologies used to create and manipulate images
The images so produced, and
The sub-field of computer science which studies methods for digitally synthesizing
and manipulating visual content, see study of computer graphics
The study of computer graphics is a sub-field of computer science which studies methods for
digitally synthesizing and manipulating visual content. Although the term often refers to three
dimensional computer graphics, it also encompasses two-dimensional graphics and image
processing.
As an academic discipline, computer graphics studies the manipulation of visual and
geometric information using computational techniques. It focuses on the mathematical and
computational foundations of image generation and processing rather than purely aesthetic
issues. Computer graphics is often differentiated from the field of visualization, although the
two fields have many similarities.
Initial Development of Computer Graphics
The advance in computer graphics was to come from one MIT student, Ivan Sutherland. In
1961 Sutherland created another computer drawing program called Sketchpad. Using a light
pen, Sketchpad allowed one to draw simple shapes on the computer screen, save them and
even recall them later. The light pen itself had a small photoelectric cell in its tip. This cell
emitted an electronic pulse whenever it was placed in front of a computer screen and the
screen's electron gun fired directly at it. By simply timing the electronic pulse with the current
location of the electron gun, it was easy to pinpoint exactly where the pen was on the screen at
any given moment. Once that was determined, the computer could then draw a cursor at that
location.
Sutherland seemed to find the perfect solution for many of the graphics problems he faced.
Even today, many standards of computer graphics interfaces got their start with this early
Sketchpad program. One example of this is in drawing constraints. If one wants to draw a
square for example, s/he doesn't have to worry about drawing four lines perfectly to form the
edges of the box. One can simply specify that s/he wants to draw a box, and then specify the
location and size of the box. The software will then construct a perfect box, with the right
dimensions and at the right location.
Another example is that Sutherland's software modeled objects - not just a picture of objects.
In other words, with a model of a car, one could change the size of the tires without affecting
the rest of the car. It could stretch the body of the car without deforming the tires.
These early computer graphics were Vector graphics, composed of thin lines whereas modern
day graphics are Raster based using pixels. The difference between vector graphics and raster
graphics can be illustrated with a shipwrecked sailor. He creates an SOS sign in the sand by
arranging rocks in the shape of the letters "SOS." He also has some brightly colored rope,
1
Chapter One: Introduction to Computer Graphics
with which he makes a second "SOS" sign by arranging the rope in the shapes of the letters.
The rock SOS sign is similar to raster graphics. Every pixel has to be individually accounted
for. The rope SOS sign is equivalent to vector graphics. The computer simply sets the starting
point and ending point for the line and perhaps bends it a little between the two end points.
The disadvantages to vector files are that they cannot represent continuous tone images and
they are limited in the number of colors available. Raster formats on the other hand work well
for continuous tone images and can reproduce as many colors as needed.
Also in 1961 another student at MIT, Steve Russell, created the first video game, Spacewar.
Written for the DEC PDP-1, Spacewar was an instant success and copies started flowing to
other PDP-1 owners and eventually even DEC got a copy. The engineers at DEC used it as a
diagnostic program on every new PDP-1 before shipping it. The sales force picked up on this
quickly enough and when installing new units, would run the world's first video game for
their new customers.
E. E. Zajac, a scientist at Bell Telephone Laboratory (BTL), created a film called "Simulation
of a two-giro gravity attitude control system" in 1963. In this computer generated film, Zajac
showed how the attitude of a satellite could be altered as it orbits the Earth. He created the
animation on an IBM 7090 mainframe computer. Also at BTL, Ken Knowlton, Frank Sindon
and Michael Noll started working in the computer graphics field. Sindon created a film called
Force, Mass and Motion illustrating Newton's laws of motion in operation. Around the same
time, other scientists were creating computer graphics to illustrate their research. At Lawrence
Radiation Laboratory, Nelson Max created the films, "Flow of a Viscous Fluid" and
"Propagation of Shock Waves in a Solid Form." Boeing Aircraft created a film called
"Vibration of an Aircraft."
It wasn't long before major corporations started taking an interest in computer graphics. TRW,
Lockheed-Georgia, General Electric and Sperry Rand are among the many companies that
were getting started in computer graphics by the mid 1960's. IBM was quk2ick to respond to
this interest by releasing the IBM 2250 graphics terminal, the first commercially available
graphics computer.
A student by the name of Edwin Catmull started at the University of Utah in 1970 and signed
up for Sutherland's computer graphics class. Catmull had just come from The Boeing
Company and had been working on his degree in physics. Growing up on Disney, Catmull
loved animation yet quickly discovered that he didn't have the talent for drawing. Now
Catmull (along with many others) saw computers as the natural progression of animation and
they wanted to be part of the revolution. The first animation that Catmull saw was his own.
He created an animation of his hand opening and closing. It became one of his goals to
produce a feature length motion picture using computer graphics. In the same class, Fred
Parke created an animation of his wife's face. Because of Evan's and Sutherland's presence,
UU was gaining quite a reputation as the place to be for computer graphics research so
Catmull went there to learn 3D animation.
As the UU computer graphics laboratory was attracting people from all over, John Warnock
was one of those early pioneers; he would later found Adobe Systems and create a revolution
in the publishing world with his PostScript page description language. Tom Stockham led the
image processing group at UU which worked closely with the computer graphics lab. Jim
Clark was also there; he would later found Silicon Graphics, Inc.
2
Chapter One: Introduction to Computer Graphics
The first major advance in 3D computer graphics was created at UU by these early pioneers,
the hidden-surface algorithm. In order to draw a representation of a 3D object on the screen,
the computer must determine which surfaces are "behind" the object from the viewer's
perspective, and thus should be "hidden" when the computer creates (or renders) the image.
Image types
2D computer graphics
2D computer graphics are the computer-based generation of digital images—mostly from two
dimensional models, such as 2D geometric models, text, and digital images, and by
techniques specific to them.
2D computer graphics are mainly used in applications that were originally developed upon
traditional printing and drawing technologies, such as typography, cartography, technical
drawing, advertising, etc... In those applications, the two-dimensional image is not just a
representation of a real world object, but an independent artifact with added semantic value;
two dimensional models are therefore preferred, because they give more direct control of the
image than 3D computer graphics, whose approach is more akin to photography than to
typography.
Pixel art
Pixel art is a form of digital art, created through the use of raster graphics software, where
images are edited on the pixel level. Graphics in most old (or relatively limited) computer and
video games, graphing calculator games, and many mobile phone games are mostly pixel art.
Vector graphics
Vector graphics formats are complementary to raster graphics, which is the representation of
images as an array of pixels, as it is typically used for the representation of photographic
images. Vector graphics consists in encoding information about shapes and colors that
comprise the image, which can allow for more flexibility in rendering. There are instances
when working with vector tools and formats is best practice and instances when working with
raster tools and formats is best practice. There are times when both formats come together. An
understanding of the advantages and limitations of each technology and the relationship
between them is most likely to result in efficient and effective use of tools.
3
Chapter One: Introduction to Computer Graphics
3D computer graphics
3D computer graphics in contrast to 2D computer graphics are graphics that use a three-
dimensional representation of geometric data that is stored in the computer for the purposes of
performing calculations and rendering 2D images. Such images may be for later display or for
real-time viewing.
Despite these differences, 3D computer graphics rely on many of the same algorithms as 2D
computer vector graphics in the wire frame model and 2D computer raster graphics in the
final rendered display. In computer graphics software, the distinction between 2D and 3D is
occasionally blurred; 2D applications may use 3D techniques to achieve effects such as
lighting, and primarily 3D may use 2D rendering techniques.
3D computer graphics are often referred to as 3D models. Apart from the rendered graphic,
the model is contained within the graphical data file. However, there are differences. A 3D
model is the mathematical representation of any three-dimensional object. A model is not
technically a graphic until it is visually displayed. Due to 3D printing, 3D models are not
confined to virtual space. A model can be displayed visually as a two dimensional image
through a process called 3D rendering, or used in non-graphical computer simulations and
calculations. There are some 3D computer graphics software for users to create 3D images.
Computer animation
Computer animation is the art of creating moving images via the use of computers. It is a
subfield of computer graphics and animation. Increasingly it is created by means of 3D
computer graphics, though 2D computer graphics are still widely used for stylistic, low
bandwidth, and faster real-time rendering needs. Sometimes the target of the animation is the
computer itself, but sometimes the target is another medium, such as film. It is also referred to
as CGI (Computer generated imagery or computer-generated imaging), especially when used
in films.
Virtual entities may contain and be controlled by assorted attributes, such as transform values
(location, orientation, and scale) stored in an object's transformation matrix. Animation is the
change of an attribute over time. Multiple methods of achieving animation exist; the
rudimentary form is based on the creation and editing of keyframes, each storing a value at a
given time, per attribute to be animated. The 2D/3D graphics software will interpolate
between keyframes, creating an editable curve of a value mapped over time, resulting in
animation. Other methods of animation include procedural and expression-based techniques:
the former consolidates related elements of animated entities into sets of attributes, useful for
creating particle effects and crowd simulations; the latter allows an evaluated result returned
from a user-defined logical expression, coupled with mathematics, to automate animation in a
predictable way (convenient for controlling bone behavior beyond what a hierarchy offers in
skeletal system set up).
To create the illusion of movement, an image is displayed on the computer screen then
quickly replaced by a new image that is similar to the previous image, but shifted slightly.
This technique is identical to the illusion of movement in television and motion pictures.
4
Chapter One: Introduction to Computer Graphics
Basics
Images are typically produced by optical devices; such as cameras, mirrors, lenses, telescopes,
microscopes, etc. and natural objects and phenomena, such as the human eye or water
surfaces.
A digital image is a representation of a two-dimensional image in binary format as a sequence
of ones and zeros. Digital images include both vector images and raster images, but raster
images are more commonly used.
Pixel
In digital imaging, a pixel (or picture element) is a single point in a raster image. Pixels are
normally arranged in a regular 2-dimensional grid, and are often represented using dots or
squares. Each pixel is a sample of an original image, where more samples typically provide a
more accurate representation of the original.
The intensity of each pixel is variable; in color systems, each pixel has typically three
components such as red, green, and blue.
5
Chapter One: Introduction to Computer Graphics
Graphics are visual presentations on some surface, such as a wall, canvas, computer screen,
paper, or stone to brand, inform, illustrate, or entertain. Examples are photographs, drawings,
line art, graphs, diagrams, typography, numbers, symbols, geometric designs, maps,
engineering drawings, or other images. Graphics often combine text, illustration, and color.
Graphic design may consist of the deliberate selection, creation, or arrangement of
typography alone, as in a brochure, flier, poster, web site, or book without any other element.
Clarity or effective communication may be the objective, association with other cultural
elements may be sought, or merely, the creation of a distinctive style.
Applications of computer graphics
Today, computers and computer-generated images touch many aspects of daily life. Computer
imagery is found on television, in newspapers, for example in weather reports, or for example
in all kinds of medical investigation and surgical procedures. A well-constructed graph can
present complex statistics in a form that is easier to understand and interpret. In the media
"such graphs are used to illustrate papers, reports, thesis", and other presentation material.
The development of computer graphics has made computers easier to interact with, and
better for understanding and interpreting many types of data. Developments in computer
graphics have had a profound impact on many types of media and have revolutionized
animation, movies and the video game industry.
The following are lists of fields in which computer graphics play very important role.
Computational biology Infographics
Computational physics Information visualization
Computer-aided design Rational drug design
Computer simulation Scientific visualization
Digital art Video Games
Education Virtual reality
Graphic design Web design
Before we look in any more detail at how computers can generate graphical images, let us
consider why we would want to do this. Since the early days of computing, the field of
computer graphics has become a very popular one because of its wide range of applications.
The following sections summarise the main categories of application.
Graphs and Charts: Graphs and charts have long been used for visualising data. They are
particularly widely used for visualising relationships and trends in scientific, mathematical,
financial and economic data. Although, in principle, we do not need advanced graphics
algorithms to display graphs and charts, many modern visualisation packages use 3-D effects
such as shadowing to make the graph/chart more visually appealing. For example, Figure
shows a range of graphs and charts produced by the free Fusion Charts Lite package
(http://www.infosoftglobal.com/FusionCharts/Lite). Commercial packages are also available
and include Microsoft Excel.
6
Chapter One: Introduction to Computer Graphics
(a) (b)
(c) (d)
7
Chapter One: Introduction to Computer Graphics
(a) (b)
(a) (b)
8
Chapter One: Introduction to Computer Graphics
(c) (d)
9
Chapter One: Introduction to Computer Graphics
(a) (b)
(c) (d)
Figure - Computer Graphics used for Virtual Reality and Augmented Reality
Education and Training: Computer graphics can be very beneficial in education and
training. For example, Figure below (a) shows a screenshot from some educational software
that teaches students about human anatomy. Graphics are used to help students visualise the
appearance and location of different organs inside the body.
Another common application of computer graphics is in training. In many jobs it is difficult
for workers to get direct experience of the environment that they are expected to work in. This
may be because the environment is inaccessible (e.g. space), dangerous (e.g. bomb disposal),
expensive (e.g. flying aircraft) or high-risk (e.g. surgery). Computer graphics, combined with
specialised hardware, can be used to simulate the working environment, so that workers can
gain the skills required for their work. For example, Figure below (b) shows a picture of a
truck-driving simulator used by the German army to train their drivers in emergency
situations; Figure below (c) shows a helicopter simulator; and Figure below (d) shows a
screenshot from a simulator for laser eye surgery.
10
Chapter One: Introduction to Computer Graphics
(a) (b)
(c) (d)
Figure - Computer Graphics used for Education and Training
Graphical User Interfaces: Another possibility that has been opened up by the
improvements in computer graphics technology is in the area of user interfaces. Figure below
shows the difference in visual appeal between an old text-based user interface and a modern
windows-based user interface. And the difference is not just in visual appeal: modern user
interfaces have made multitasking (doing several things at once) much easier and applications
such as word-processors have become much more powerful.
(a) (b)
11
Chapter One: Introduction to Computer Graphics
(a) (b)
(c) (d)
12
Chapter One: Introduction to Computer Graphics
CRT Displays
CRT display devices are very common in everyday life as well as in computer graphics: most
television sets use CRT technology. Figure illustrates the basic operation of a CRT display.
Beams of electrons are generated by electron guns and fired at a screen consisting of
thousands of tiny phosphor dots. When a beam hits a phosphor dot it emits light with
brightness proportional to the strength of the beam. Therefore pictures can be drawn on the
display by directing the electron beam to particular parts of the screen. The beam is directed
to different parts of the screen by passing it through a magnetic field. The strength and
direction of this field, generated by the deflection yoke, determines the degree of deflection of
the beam on its way to the screen.
To achieve a colour display, CRT devices have three electron beams, and on the screen the
phosphor dots are in groups of three, which give off red, green and blue light respectively.
Because the three dots are very close together the light given off by the phosphor dots is
combined, and the relative brightness’s of the red, green and blue components determines the
colour of light perceived at that point in the display.
13
Chapter One: Introduction to Computer Graphics
Random scan displays are not so common for CRT devices, although some early video games
did use random scan technology. These days random scan is only really used by some hard-
copy plotters.
14
Chapter One: Introduction to Computer Graphics
15
Chapter One: Introduction to Computer Graphics
update by ‘sweeping’ the electron beams across the raster scan-line by scan-line, starting from
the top and working towards the bottom. When the last scan-line is completed we start again
from the top.
The number of times that the entire raster is refreshed (i.e. drawn) each second is known as
the refresh rate of the device. For the display to appear persistent and not to flicker the
display must update often enough so that we cannot perceive a gap between frames. In other
words, we must refresh the raster when the persistence of the phosphor dots is beginning to
wear off. In practise, if the refresh rate is more than 24 frames per second (f/s) the display will
appear reasonably smooth and persistent.
Modern graphics displays have high refresh rates, typically in the region of 60 f/s. However,
early graphics systems tended to have refresh rates of about 30 f/s. Consequently, some
flicker was noticeable. To overcome this, a technique known as interlaced scanning was
employed. Using interlaced scanning alternate scan-lines are updated in each raster refresh.
For example, in the first refresh only odd numbered scan-lines may be refreshed, then on the
next refresh only even-numbered scan-lines, and so on (see Figurebelow). Because this
technique effectively doubles the screen refresh rate, it has the effect of reducing flicker for
displays with low refresh rates. Interlaced scanning was common in the early days of
computer graphics, but these days displays have better refresh rates so it is not so common.
The following are the specifications of some common video formats that have been (and still
are) used in computer graphics:
VGA: resolution 640x480, 60 f/s refresh rate, non-interlaced scanning.
PAL: resolution 625x480, 25 f/s refresh rate, interlaced scanning
NTSC: resolution 525x480, 30 f/s refresh rate, interlaced scanning
i. Frame Buffers
Frame buffers are used by raster scan display devices to store the pixel values of the image
that will be displayed on the raster. It is a 2-D array of data values, with each data value
corresponding to a pixel in the image. The number of bits used to store the value for each
pixel is known as the bit-planes or depth of the frame buffer. For example, a 640x480x8
frame buffer has a resolution of 640x480 and a depth of 8 bits; a 1280x1024x24 frame buffer
16
Chapter One: Introduction to Computer Graphics
has a resolution of 1280x1024 and a depth of 24 bits. For colour displays we need to store a
value for each component of the colour (red, green and blue), so the bit-planes will typically
be a multiple of 3 (e.g. 8 bit-planes each for red, green and blue makes a total of 24 bit-
planes).
Since the display processor contains dedicated hardware for executing graphics routines it
must be dedicated to a particular set of routines. In other words, display processors will only
be able to handle the graphics processing if the routines used are from a particular graphics
package. This is known as hardware rendering. Most commercial video cards will support
hardware rendering for the OpenGL graphics package, and many PC video cards will also
support hardware rendering for DirectX. Hardware rendering is much faster than the
alternative, software rendering, in which graphics routines are compiled and executed by the
CPU just like any other code. For the raster graphics architecture to support software
rendering the block-diagram shown in Figurebelow would need to be modified so that the
frame buffer was connected directly to the system bus in order that it could be updated by the
CPU.
17
Chapter One: Introduction to Computer Graphics
3-D displays can be divided into two types: head-mounted displays (HMDs) and head-tracked
displays (HTDs). HMDs are displays that are mounted on the head of the viewer. For
example, Figure below shows a HMD – the device fits on the head of the user and displays
separate images to the left and right eyes, producing a sense of stereo immersion. Such
devices are common in virtual reality applications. Normally a tracking device will be used to
track the location of the display device so that the images presented to the user can be updated
accordingly – giving the impression that the viewer is able to ‘move’ through the virtual
world.
18
Chapter One: Introduction to Computer Graphics
Whereas with a HMD the display moves with the viewer’s head, with a HTD the display
remains stationary, but the head of the viewer is tracked so that the images presented in the
display can be updated. The difficulty with HTDs is how to ensure that the left and right eyes
of the viewer receive separate stereo images to give a 3-D depth effect. A number of
technologies exist to achieve this aim. For example, the display can use polarised light filters
to give off alternate vertically and horizontally polarised images; the viewer then wears
special glasses with polarised filters to ensure that, for example, the left eye receives the
vertically polarised images and the right eye receives the horizontally polarised images. An
alternative technique is to use colour filters: the display draws a left-eye image in, for
example, blue, and a right eye image in green; then the viewer wears glasses with colour
filters to achieve the stereo effect. Other technologies also exist.
Tactile sensing involves simulation of the sense of human touch and includes the
ability to perceive pressure, linear force, torque, temperature, and surface texture.
Fine-motion control involves the use of sensors to detect the movements of the user's
hand and fingers, and the translation of these motions into signals that can be used by
a virtual hand (for example, in gaming ) or a robotic hand (for example, in remote-
control surgery).
19
Chapter One: Introduction to Computer Graphics
Graphics Software
To generate graphical images like those we have seen above, we need some type of graphics
software. We can divide graphics software into two categories:
Special-purpose graphics packages
General-purpose graphics packages
Special-purpose packages are designed for a specific purpose. For example a drawing package
such as the Paint accessory in Microsoft Windows is an example of a special-purpose
graphics package: it is designed to allow users to draw simple pictures consisting of lines,
curves and other basic components. Another example is CAD packages such as AutoCAD:
these are designed to allow users to build and visualise 3-D models. Special-purpose graphics
packages tend to be used mostly by end-users, not programmers or computer professionals. In
other words, you do not need to know about computer graphics theory to use them. Other
examples of special-purpose packages are the drawing applications Adobe Photoshop, Xara
and GIMP; the 3-D modelling applications 3-D Studio Max and Design Works; and the
visualisation software Fusion Charts and Microsoft Excel.
General-purpose packages are a pre-defined library of routines for drawing graphics
primitives. They are used by computer programmers to add graphical capability to their
programs. They provide a lot more flexibility than special-purpose packages but they require
technical knowledge of computer graphics and programming and so are not suitable for end-
users. Examples of general-purpose graphics packages are the standard low-level graphics
library OpenGL, the Microsoft equivalent DirectX and the higher-level library OpenInventor.
We can also think of scene description languages as a type of general-purpose graphics
package. Scene description languages are languages that can be used to define 3-D models of
scenes. Special viewing software is required to view and often interact with the scene. The
most common example of a scene description language is VRML, the Virtual Reality
Modelling Language.
20
Chapter One: Introduction to Computer Graphics
Introduction to OpenGL
Now we will introduce the OpenGL graphics package. This part of the course is aimed to give
you practical experience to reinforce the theory behind computer graphics. Code examples
will be given in C++, and you are expected to experiment with the OpenGL routines that are
introduced throughout the course.
In this course we will be using OpenGL together with the GL Utilities Toolkit (glut). You
should make sure that you have access to a C++ development environment that supports these
two libraries. Note that Turbo C++ does not support either of them. Two possibilities are:
The free Dev-C++ environment (www.bloodshed.net) has OpenGL built-in and glut
can be easily added on as a separate package.
Microsoft Visual C++ also has OpenGL built-in but not glut. The glut library is
available as a free download from http://www.xmission.com/~nate/glut.html.
Installation is fairly straightforward.
The examples and exercise solutions given in this course were coded with Dev-C++, but the
same source code should compile with Visual C++. Also, if you use Dev-C++, it comes with
a very useful OpenGL help file that you can use as a reference for different OpenGL routines
(it will be found in the Docs/OpenGL folder inside the Dev-C++ installation folder).
Although OpenGL is the core library that contains the majority of the functionality, there are
a number of associated libraries that are also useful. The following is a summary of the most
important of the OpenGL family of graphics libraries:
OpenGL: the core library, it is platform (i.e. hardware system) independent, but not
windows-system independent (i.e. the code for running on Microsoft Windows will be
different to the code for running on the UNIX environments X-Windows or Gnome).
21
Chapter One: Introduction to Computer Graphics
glut: The GL Utilities Toolkit, it contains some extra routines for drawing 3-D objects
and other primitives. Using glut with OpenGL enables us to write windows-system
independent code.
glu: The OpenGL Utilities, it contains some extra k2routines for projections and
rendering complex 3-D objects.
glui: Contains some extra routines for creating user-interfaces.
Every routine provided by OpenGL or one of the associated libraries listed above follows the
same basic rule of syntax:
The prefix of the function name is either gl, glu, or glut, depending on which of these
three libraries the routine is from.
The main part of the function name indicates the purpose of the function.
The suffix of the function name indicates the number and type of arguments expected
by the function. For example, the suffix 3f indicates that 3 floating point arguments are
expected.
For example, the function glVertex2i is an OpenGL routine that takes 2 integer arguments and
defines a vertex.
Some function arguments can be supplied as predefined symbolic constants. These are
basically identifiers that have been defined using the C++ #define statement. These symbolic
constants are always in capital letters, and have the same prefix convention as function names.
For example, GL_RGB, GL_POLYGON and GLUT_SINGLE are all symbolic constants used
by OpenGL and its associated libraries.
Finally, OpenGL has a number of built-in data types to help make it into a platform-
independent package. For example, the C++ int data type may be stored as a 16-bit number on
some platforms but as a 32-bit number on others. Therefore if we use these standard C++ data
types with OpenGL routines the resultant code will not be platform-independent. OpenGL
provides its own data types to overcome this limitation. Mostly, they have the same names as
C++ data types but with the prefix GL attached. For example, GLshort, GLint, GLfloat and
GLdouble are all built-in OpenGL data types. Although you will find that your OpenGL code
will still work on your computer if you do not use these data types, it will not be as portable to
other platforms so it is recommended that you do use them.
22