Lecture Notes in Computer Graphics
Lecture Notes in Computer Graphics
Chapter One
Introduction to Computer graphics
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 the study of three-
dimensional computer graphics, it also encompasses two-dimensional graphics and image processing.
Computer graphics are graphics created using computers and, more generally, the representation and
manipulation of image data by a computer.
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.
Overview
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:
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.
Scientific visualization
Information visualization
Computer vision
Image processing
Computational Geometry
Computational Topology
Applied mathematics
Applications
Applications of computer graphics include:
3
CG art
Computational biology
Computational physics
Computer Aided Design (CAD), Computer Aided Engineering (CAE), and Computer Aided
Manufacturing (CAM)Computer simulation
Digital art
Education/ Training
Entertainment
Graphic design
Infographics
Information visualization
Medical applications
Rational drug design
Scientific visualization
Simulation
Special effects
Video Games
Virtual reality
Web design
Geometry
The subfield of geometry studies the representation of three-dimensional objects in a discrete digital
setting. Because the appearance of an object depends largely on its exterior, boundary representations
are most commonly used. Two dimensional surfaces are a good representation for most objects,
though they may be non-manifold. Since surfaces are not finite, discrete digital approximations are
used. Polygonal meshes (and to a lesser extent subdivision surfaces) are by far the most common
representation, although point-based representations have become more popular recently (see for
instance the Symposium on Point-Based Graphics). These representations are Lagrangian, meaning
the spatial locations of the samples are independent. Recently, Eulerian surface descriptions (i.e.,
where spatial samples are fixed) such as level sets have been developed into a useful representation
for deforming surfaces which undergo many topological changes (with fluids being the most notable
example).
Geometry Subfields
Implicit surface modeling - an older subfield which examines the use of algebraic surfaces,
constructive solid geometry, etc., for surface representation.
4
Animation
The subfield of animation studies descriptions for surfaces (and other phenomena) that move or
deform over time. Historically, most work in this field has focused on parametric and data-driven
models, but recently physical simulation has become more popular as computers have become more
powerful computationally.
Subfields
Performance capture
Character animation
Physical simulation (e.g. cloth modeling, animation of fluid dynamics, etc.)
Rendering
Rendering generates images from a model. Rendering may simulate light transport to create realistic
images or it may create images that have a particular artistic style in non-photorealistic rendering. The
two basic operations in realistic rendering are transport (how much light passes from one place to
another) and scattering (how surfaces interact with light).
Transport
Transport describes how illumination in a scene gets from one place to another. Visibility is a major
component of light transport.
Scattering
Models of scattering and shading are used to describe the appearance of a surface. In graphics these
problems are often studied within the context of rendering since they can substantially affect the
design of rendering algorithms. Shading can be broken down into two orthogonal issues, which are
often studied independently:
Indirect diffuse scattering simulated using path tracing and irradiance caching
The former problem refers to scattering, i.e., the relationship between incoming and outgoing
illumination at a given point. Descriptions of scattering are usually given in terms of a bidirectional
scattering distribution function or BSDF. The latter issue addresses how different types of scattering
are distributed across the surface (i.e., which scattering function applies where). Descriptions of this
kind are typically expressed with a program called a shader. (Note that there is some confusion since
the word "shader" is sometimes used for programs that describe local geometric variation.)
Other subfields
Computer graphics is the life line of today's computer world. 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, theses", and
other presentation material.
Many powerful tools have been developed to visualize data. Computer generated imagery can be
categorized into several different types: 2D, 3D, 5D, and animated graphics. As technology has
improved, 3D computer graphics have become more common, but 2D computer graphics are still
widely used. Computer graphics has emerged as a sub-field of computer science which studies
methods for digitally synthesizing and manipulating visual content. Over the past decade, other
specialized fields have been developed like information visualization, and scientific visualization
more concerned with "the visualization of three dimensional phenomena (architectural,
meteorological, medical, biological, etc.), where the emphasis is on realistic renderings of volumes,
surfaces, illumination sources, and so forth, perhaps with a dynamic (time) component".
6
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, 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
bend 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
7
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 altitude control system" in 1963. In this computer generated film, Zajac showed how
the altitude 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 quick to respond to this interest by
releasing the IBM 2250 graphics terminal, the first commercially available graphics computer.
Ralph Baer, a supervising engineer at Sanders Associates, came up with a home video game in 1966
that was later licensed to Magnavox and called the Odyssey. While very simplistic, and requiring
fairly inexpensive electronic parts, it allowed the player to move points of light around on a screen. It
was the first consumer computer graphics product.
Also in 1966, Sutherland at MIT invented the first computer controlled head-mounted display
(HMD). Called the Sword of Damocles because of the hardware required for support, it displayed two
separate wireframe images, one for each eye. This allowed the viewer to see the computer scene in
stereoscopic 3D. After receiving his Ph.D. from MIT, Sutherland became Director of Information
Processing at ARPA (Advanced Research Projects Agency), and later became a professor at Harvard.
Dave Evans was director of engineering at Bendix Corporation's computer division from 1953 to
1962, after which he worked for the next five years as a visiting professor at Berkeley. There he
continued his interest in computers and how they interfaced with people. In 1968 the University of
Utah recruited Evans to form a computer science program, and computer graphics quickly became his
primary interest. This new department would become the world's primary research center for
computer graphics.
In 1967 Sutherland was recruited by Evans to join the computer science program at the University of
Utah. There he perfected his HMD. Twenty years later, NASA would re-discover his techniques in
their virtual reality research. At Utah, Sutherland and Evans were highly sought after consultants by
large companies but they were frustrated at the lack of graphics hardware available at the time so they
started formulating a plan to start their own company.
8
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.
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.
One of the first displays of computer animation was Futureworld (1976), which included an
animation of a human face and hand — produced by Ed Catmull and Fred Parke at the University of
Utah.
There are several international conferences and journals where the most significant results in
computer graphics are published. Among them are the SIGGRAPH and Eurographics conferences
and the Association for Computing Machinery (ACM) Transactions on Graphics journal. The joint
Eurographics and ACM SIGGRAPH symposium series features the major venues for the more
specialized sub-fields: Symposium on Geometry Processing, Symposium on Rendering, and
Symposium on Computer Animation. As in the rest of computer science, conference publications in
computer graphics are generally more significant than journal publications (and subsequently have
lower acceptance rates).
A. Michael Noll
Noll was one of the first researchers to use a digital computer to create artistic patterns and to
formalize the use of random processes in the creation of visual arts. He began creating digital
computer art in 1962, making him one of the earliest digital computer artists. In 1965, Noll
along with Frieder Nake and Georg Nees were the first to publicly exhibit their computer art.
During April 1965, the Howard Wise Gallery exhibited Noll's computer art along with
random-dot patterns by Bela Julesz.
Other pioneers
Jim Blinn
Arambilet
Benoît B. Mandelbrot
Henri Gouraud
Bui Tuong Phong
Pierre Bézier
Paul de Casteljau
Daniel J. Sandin
Alvy Ray Smith
Ton Roosendaal
Ivan Sutherland
Steve Russell
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.
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. The word may stand for the branch of computer science that comprises such
techniques, or for the models themselves.
10
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. 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.
11
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.
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
12
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.
Pixel
In the enlarged portion of the image individual pixels are rendered as squares and can be easily seen.
13
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.
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.
Arambilet: Dots on the I's, D-ART 2009 Online Digital Art Gallery, exhibited at IV09 and CG09
computer Graphics conferences, at Pompeu Fabra University, Barcelona; Tianjin University, China;
Permanent Exhibition at the London South Bank University
Rendering
A 2D/3D scene file contains objects in a strictly defined language or data structure. It would contain
geometry, viewpoint, texture, lighting, and shading information as a description of the virtual scene.
The data contained in the scene file is then passed to a rendering program to be processed and output
to a digital image or raster graphics image file. The rendering program is usually built into the
computer graphics software, though others are available as plug-ins or entirely separate programs;
examples include mental images' mental ray and Disney Pixar's RenderMan. The term "rendering"
may be by analogy with an "artist's rendering" of a scene. Though the technical details of rendering
methods vary, the general challenges to overcome in producing a 2D image from a 3D representation
stored in a scene file are outlined collectively as the graphics pipeline along a rendering device, such
as a GPU. A GPU is a purpose-built device able to assist a CPU in performing complex rendering
calculations. If a scene is to look relatively realistic and predictable under virtual lighting, the
rendering software should solve the rendering equation. The rendering equation doesn't account for all
lighting phenomena, but is a general lighting model for computer-generated imagery. 'Rendering' is
also used to describe the process of calculating effects in a video editing file to produce final video
output.
3D projection
3D projection is a method of mapping three dimensional points to a two dimensional plane. As
most current methods for displaying graphical data are based on planar two dimensional
14
media, the use of this type of projection is widespread, especially in computer graphics,
engineering and drafting.
Ray tracing
Ray tracing is a technique for generating an image by tracing the path of light through pixels
in an image plane. The technique is capable of producing a very high degree of photorealism;
usually higher than that of typical scanline rendering methods, but at a greater computational
cost.
Shading
Shading refers to depicting depth in 3D models or illustrations by varying levels of darkness.
It is a process used in drawing for depicting levels of darkness on paper by applying media
more densely or with a darker shade for darker areas, and less densely or with a lighter shade
for lighter areas. There are various techniques of shading including cross hatching where
perpendicular lines of varying closeness are drawn in a grid pattern to shade an area. The
closer the lines are together, the darker the area appears. Likewise, the farther apart the lines
are, the lighter the area appears. The term has been recently generalized to mean that shaders
are applied.
Example of shading.
Texture mapping
Texture mapping is a method for adding detail, surface texture, or colour to a computer-
generated graphic or 3D model. Its application to 3D graphics was pioneered by Dr Edwin
Catmull in 1974. A texture map is applied (mapped) to the surface of a shape, or polygon.
This process is akin to applying patterned paper to a plain white box. Multitexturing is the use
of more than one texture at a time on a polygon. Procedural textures (created from adjusting
parameters of an underlying algorithm that produces an output texture), and bitmap textures
(created in an image editing application) are, generally speaking, common methods of
implementing texture definition from a 3D animation program, while intended placement of
textures onto a model's surface often requires a technique known as UV mapping.
Anti-aliasing
Rendering resolution-independent entities (such as 3D models) for viewing on a raster (pixel-
based) device such as a LCD display or CRT television inevitably causes aliasing artifacts
mostly along geometric edges and the boundaries of texture details; these artifacts are
informally called "jaggies". Anti-aliasing methods rectify such problems, resulting in imagery
more pleasing to the viewer, but can be somewhat computationally expensive. Various anti-
aliasing algorithms (such as supersampling) are able to be employed, then customized for the
most efficient rendering performance versus quality of the resultant imagery; a graphics artist
should consider this trade-off if anti-aliasing methods are to be used. A pre-anti-aliased bitmap
texture being displayed on a screen (or screen location) at a resolution different than the
resolution of the texture itself (such as a textured model in the distance from the virtual
camera) will exhibit aliasing artifacts, while any procedurally-defined texture will always
15
show aliasing artifacts as they are resolution-independant; techniques such as mipmapping and
texture filtering help to solve texture-related aliasing problems.
Volume rendering
Volume rendered CT scan of a forearm with different colour schemes for muscle, fat, bone, and
blood.
Volume rendering is a technique used to display a 2D projection of a 3D discretely sampled data set.
A typical 3D data set is a group of 2D slice images acquired by a CT or MRI scanner.
Usually these are acquired in a regular pattern (e.g., one slice every millimeter) and usually have a
regular number of image pixels in a regular pattern. This is an example of a regular volumetric grid,
with each volume element, or voxel represented by a single value that is obtained by sampling the
immediate area surrounding the voxel.
A modern render of the Utah teapot, an iconic model in 3D computer graphics created by Martin
Newell, 1975
3D modeling
Chapter Two
Overview of Graphics Systems
Output Devices
Output devices are feedback devices that display the output from the computer. There is a wide
variety of output devices designed for various purposes.
Text CRT (Cathode Ray Tubes) - These devices can display letters, numbers, punctuation, and
other simple symbols, usually only in monochrome (black and white, black and green, black and
amber). These characters are fixed in memory called character ROM .
Color Raster CRT - Display shaded and color images with high resolution. Images are dynamically
stored in a piece of memory called a frame buffer.
Printer - This is like CRT, except that it gives a hardcopy (not a softcopy ).
Film (video) recorder - This is like a color raster CRT. The images are stored in digitized form on
magnetic media.
Plotter - This is like a slow calligraphic CRT. Flatbed plotter, drum plotter are some of the plotters
available. Plotters can be very useful in drawing the graphs, barcharts, linedrawing and maps on rolls
of paper or sheets.
Head mounted displays - These are virtual reality displays which can project information on a
partially silvered wind screen of an airplane or car so that pilots or drivers can keep their attention
focused on the surroundings while receiving computer generated information.
Input Devices
Track balls and joysticks - usually used in computer games. These are analog input devices, which
are controlled by transducers.
Transducer is a device which converts the user's movements into changes in voltage or amperage by
varying the resistance of the circuit.
Mouse – good for choosing, positioning and drawing. The mechanical mouse is similar to the track
ball which uses two variable resistors to specify the x and y information. The digital version like the
optical mouse and acoustic mouse are also available.
18
Keyboard - good for entering alpha numeric data. The computer encodes the keyboard characters
using the American Standard Code for Information Interchange (ASCII). Each key has a unique 7-bit
ASCII code associated with it, with which we can communicate with the computer.
19
Chapter Three
Graphics Primitives
A primitive is a graphics object that is essential for the creation or construction of complex images.
Fortunately, graphics is constructed from three basic elements, as opposed to the great variety of
graphics applications.
Pixel
Line
Polygon
Pixels
Example: Compute the size of an image that has 512 X 512 pixels at 256 pixels per inch.
Answer: 512pixel/256 pixels per inch by 512pixel/256 pixels per inch = 2 inch by 2 inch
As the resolution of the screen increased, a better quality graphics we can get.
Image representation with pixels can be done using direct coding or lookup table.
Direct coding
Direct coding is used to allocate certain amount of storage space for each pixel to code its colour.
Example: If we use direct coding of RGB values with 4 bits per primary color, how many possible
colors do you have for each pixel?
Answer: There are 2^4 = 16 possible colors per each channel (Red for example).
This makes 2^4 X 2^4 X 2^4 = 2^12 = 4092 possible different colors for a pixel.
Lookup table
A colour look-up table (CLUT) is a mechanism used to transform a range of input colours into
another range of colours. It can be a hardware device built into an imaging system or a software
function built into an image processing application. The hardware colour look-up table will convert
the logical colour (pseudo-colour) numbers stored in each pixel of video memory into physical
colours, normally represented as RGB triplets, that can be displayed on a computer monitor. The
palette is simply a block of fast RAM which is addressed by the logical colour and whose output is
20
split into the red, green, and blue levels which drive the actual display (e.g., a CRT or cathode ray
tube).
The number of entries in the palette: determines the maximum number of colours which can
appear on screen simultaneously (a subset of the wider full palette, which is to be understood
as the total number of colours that a given system is able to generate or manage, e.g. the full
RGB colour palette).
The width of each entry in the palette: determines the number of colours which the wider full
palette can represent.
A common example would be a palette of 256 colours; that is, the number of entries is 256, and thus
each entry is addressed by an 8-bit pixel value. The 8 bits is known as colour depth, bit depth or bits
per pixel (bpp). Each colour can be chosen from a full palette, typically with a total of 16.7 million
colours; that is, the width of each entry is 24 bits, 8 bits per channel, which means combinations of
256 levels for each of the red, green, and blue components: 256 × 256 × 256 = 16,777,216 colours.
Lines
Lines, especially straight lines, constitute an important building block of computer images.
Line is the basic building block of Line graphs, like bar and pie charts, two and three-
dimensional graphs of mathematical functions, engineering drawings and architectural plans.
In computer graphics, straight line is so basic in creating images that we call it a graphics
primitive.
Straight lines can be developed in two different ways.
1. A structural method determines which pixels should be set before drawing the line;
2. A conditional method tests certain conditions to find which pixel should be set next.
Polygons
Chapter Four
Transformations and Animation
Basic Transformations
Basic Transformations
o Translation
o Rotation
o Scaling
Composite Transformations
Other Transformations
o Reflections
o Shear
Translation
A translation is the process of repositioning the object along a straightline path from one coordinate
to another.
Let
(x, y) be the original coordinate position.
(x′, y′) be the new position after translation
tx and ty be the translation distances in the x and y directions.
x′ = x + tx
y′ = y + t y
Rotation
A two-D rotation is applied to an object by repositioning it along a circular path in the xy plane.
To generate a rotation:
* We specify a rotation angle θ
*The position (xr , yr ) of the rotation point (or pivot point)
Positive values for the rotation angle define CCW rotations about the pivot point and negative values
rotate objects in the CW direction.
23
Scaling
Matrix Representation
Many graphics applications involve sequences of geometric transformations.
An animation, for example, might require an object to be translated and rotated at each increment of
the motion.
In picture construction applications, we perform translations, rotations, and scalings to fit the picture
components into their proper positions.
28
For translation,
M1 is the identity matrix.
M2 is the translation vector.
Homogeneous Coordinates
We can combine the multiplicative and translational terms for two-D geometric transformations into a
single matrix representation by expanding the 2 by 2 matrix representations to 3 by 3 matrices.
This allows us to express all transformation equations as matrix multiplications, providing that we
also expand the matrix representations for coordinate positions.
Each Cartesian coordinate position (x, y) is represented with the homogeneous coordinate triple (xh ,
yh , h)
Thus, a general homogeneous coordinate representation can also be written as (h ⋅ x,h ⋅ y,h)
A convenient choice is simply to set h =1
Each two-dimensional position is then represented with homogeneous coordinates (x, y,1)
Expressing positions in homogeneous coordinates allows us to represent all geometric transformation
equations as matrix multiplications.
29
Composite Transformations
The composite transformation matrix for this sequence is obtained with the concatenation
32
Reflections
A reflection is a transformation that produces a mirror image of an object.
The mirror image for a two-dimensional reflection is generated relative to an axis of reflection by
rotating the object 180° about the reflection axis.
34
Shear
A transformation that distorts the shape of an object such that the transformed shape appears as if the
object were composed of internal layers that had been caused to slide over each other is called a
shear.
An x-direction shear:
x′ = x + shx .y
y′ = y
36
37
Chapter Five
Introduction to Graphics Programming,
Geometric Objects & User Interaction
OpenGL programming
1. Download freeglut-2.6.0 (if you are using VS 2008) or freeglut-2.4.0 (if you are using VS 2005)
3. Build the project. Under the newly created "Debug" folder, you'll find [Link] and [Link].
[Link] [Link] [Link] (Note that [Link] and [Link] come with Visual Studio
2008.)
Drag and drop any OpenGL programs to the "Source Files" node under the project you created in VS
2008. Whenever you see
#include <GL/glut.h>
change it to
#include <GL/freeglut.h>
Coordinate systems
Graphics primitives
● Example
GLfloat normals[][3] = {{0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}, {-1.0, 0.0, 0.0}};
– glutAddSubMenu
– glutAttachMenu, glutDetachMenu, etc.
● See [Link] for details
sub_menu = glutCreateMenu(size_menu);
glutCreateMenu(top_menu);
glutAddMenuEntry(―quit‖, 1);
glutAddSubMenu(―Resize‖, sub_menu);
glutAttachMenu(GLUT_RIGHT_BUTTON);
Input Modes
● Input devices contain a trigger which can be used to send a signal to the operating system
– Button on mouse
– Pressing or releasing a key
● When triggered, input devices return information (their measure) to the system
– Mouse returns position information
– Keyboard returns ASCII code
Request Mode
Event Mode
● Most systems have more than one input device, each of which can be triggered at an arbitrary
time by a user
● Each trigger generates an event whose measure is put in an event queue which can be
examined by the user program
Event Types
Callbacks
GLUT callbacks
● GLUT recognizes a subset of the events recognized by any particular window system
(Windows, X Window, Macintosh)
● Can register callback functions to handle those events
– glutDisplayFunc
– glutMouseFunc
– glutReshapeFunc
– glutKeyFunc
– glutIdleFunc
– glutMotionFunc, glutPassiveMotionFunc
● See [Link] for details
43
● Remember that the last line in main.c for a program using GLUT must be
glutMainLoop();
● The display callback is executed whenever GLUT determines that the window should be
refreshed, for example
– When the window is first opened
– When the window is reshaped
– When a window is exposed
– When the user program decides it wants to change the display
● In main.c
– glutDisplayFunc(mydisplay) identifies the function to be executed
– Every GLUT program must have a display callback
Posting redisplays
glutPostRedisplay();
● GLUT checks to see if the flag is set at the end of the event loop
● If set then the display callback function is executed
● When we redraw the display through the display callback, we usually start by clearing the
window with glClear()and then draw the next frame
● Instead of one color buffer, we use two
– Front Buffer: one that is displayed but not written to
– Back Buffer: one that is written to but not altered
● The idle callback is executed whenever there are no events in the event queue
– glutIdleFunc(myidle)
● Useful for automatic animations. For example:
glutInit(&argc, argv);
glutInitWindowPosition(100,100); glutInitWindowSize(320,320);
45
glutCreateWindow("");
glutDisplayFunc(renderScene);
glutIdleFunc(renderScene);
glutReshapeFunc(changeSize); glEnable(GL_DEPTH_TEST);
glutMainLoop();
void renderScene(void) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotatef(angle,0.0,1.0,0.0);
glBegin(GL_TRIANGLES);
glVertex3f(-0.5,-0.5,0.0);
glVertex3f(0.5,0.0,0.0);
glVertex3f(0.0,0.5,0.0);
glEnd();
glPopMatrix();
glutSwapBuffers();
angle++;
#include <GL/glut.h>
46
void display(void)
glClear (GL_COLOR_BUFFER_BIT);
*/
glBegin(GL_POLYGON);
glEnd();
glFlush ();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
47
buffer and RGBA). Open window with "hello" in its title bar. Call
glutInit(&argc, argv);
glutCreateWindow ("hello");
init ();
glutDisplayFunc(display);
glutMainLoop();
The following procedure takes as input three points and returns the coefficients of the Cartesian plane
equation (a,b,c and d).
d2[j] = P3[j]-P1[j];
END FOR
(* Find the normal vector to the plane n = [a,b,c] = d1 X d2 *)
a := d1[1]*d2[2] - d1[2]*d2[1]
b := d1[2]*d2[0] - d1[0]*d2[2]
c := d1[0]*d2[1] - d1[1]*d2[0]
(* take the dot product with P-P1 *)
d := -(a*P1[0]+b*P1[1]+c*P1[2])
END PlaneEquation;
49
References
1. What is Computer Graphics?, Cornell University Program of Computer Graphics. Last updated
04/15/98. Accessed Nov 17, 2009.
2. University of Leeds ISS (2002). "What are computer graphics?". Last updated: 22 Sep 2008
3. Michael Friendly (2008). "Milestones in the history of thematic cartography, statistical graphics, and
data visualization".
4. Ira Greenberg (2007). Processing: Creative Coding and Computational Art. Apress.
ISBN 159059617X.
[Link]
graphic&lr=&as_brr=0&ei=llOVR5LKCJL0iwGZ8-ywBw&sig=YEjfPOYSUDIf1CUbL5S5Jbzs7M8.
5. Rudolf F. Graf (1999). Modern Dictionary of Electronics. Oxford: Newnes. p. 569. ISBN 0-7506-
43315.
[Link]
nary+of+Electronics%22+inauthor:graf&lr=&as_brr=0&ei=5ygASM3qHoSgiwH45-GIDA&sig=7tg-
LuGdu6Njypaawi2bbkeq8pw.
6. Blythe, David. Advanced Graphics Programming Techniques Using OpenGL. Siggraph 1999. (see:
Multitexture)
7. Best Practices Memo
8. Choosing a venue: conference or journal?
9. Graphics/vision publications acceptance rates statistics
10. An extensive history of computer graphics can be found at this page.
11. Ron Fedkiw
12. SIGGRAPH 2001 Course on Digital Geometry Processing
13. CS 598: Digital Geometry Processing (Fall 2004)
[Link]
14. Digital Geometry Processing
15. Discrete Differential Geometry
50
Exercises
1. The term computer graphics has been used in a broad sense to describe "almost everything on
computers that is not text or sound." Briefly explain.
2. An object is located at point P (3,4) in a two dimensional plane. If the object is rotated
counterclockwise by 15o, find the new coordinate of the point P’ in two decimal place
showing a schematic diagram of the solution.
3. What are the areas of applications of computer graphics?
4. A square is located in a two dimensional plane with vertexes (A,B,C and D) with the
following coordinates: A(1,4); B(3,4); C(3,2) and D(1,2). Draw a schematic of the square. If
the object is to be scaled with the scaling factors: Sx = 2 and Sy = 1, Show the new dimension
and coordinates of the transformed object with the aid of a schematic diagram. Show all
calculations
5. Write short notes on the studies connected with Computer Graphics
6. Write a procedure in any programming language you like which takes as input three points
and returns the coefficients of the Cartesian plane equation (a,b,c and d).
7. Briefly state the classification of major subfields in computer graphics
8. Image representation can be accomplished using direct coding and lookup table. Explain these
techniques stating the advantage(s) and disadvantage(s) of each over the other.
9. If we use direct coding of RGB values with 2 bits per primary color, how many possible
colors do we have for each pixel? Show a tabular representation to demonstrate your solution.
10. A total of 32 bits per pixel is used in a direct coding method. If 10 bits each is used for cyan
and magenta and 12 bits for yellow, how many possible simultaneous colors do we have?
11. Give a brief Historical account of Computer Graphics
12. Compute the size of an image that has 512 X 512 pixels at 256 pixels per inch.
13. Find the RGB coordinates of a color at (0.5, 0, 0.2) in the CMY coordinate
14. An object is located at a point P (2,2) in a two dimensional plane, if the object is translated to
a new point P’ (3,3), calculate the distance between P and P’.