Download as pdf or txt
Download as pdf or txt
You are on page 1of 54

Course Code: CSC407

Introduction to computer
graphics
#computergraphics lecture note

Modules 1-8
Department of computer science, EKSU
Unit 1: Module 1
• What is computer Graphics? ➢Input devices keyboard ,
➢Use a computer to create mouse , touch panel,
pictures. ➢Graphics cards/ Accelerator
• Motivation of CG: • Software tools:
➢Appealing picture ➢ Operating system
produce. ➢ Complier
➢Humans respond better to
pictorial information. ➢ Editor
➢Human brain recognizes ➢ Debuggers
visual patterns. ➢ Graphics library
• CG tools: • Motivation of CG:
➢ CG tools include hardware ➢ Appealing picture produce.
and software tools. ➢ Humans respond better to
• Hardware Tools: pictorial information.
➢Output devices video ➢ Human brain recognizes
monitor, printer visual patterns.
Unit 1: Module 2
• Reasons to study CG: ➢ Image processing
➢ Information presentation. ➢ Alter images, remove
noise
➢ Job in CG ( Games, movies etc)
➢ Processing monitoring
➢ CG has many concept.
➢ Large systems or plants
➢ Computer scientists create ➢ Display simulations:
libraries, tools that artist /non
➢ Flight simulators, virtual
techines can use to create worlds.
pretty pictures.
➢ Computer- aided design,
➢ Artists use CG tools to creates architecture, electric
pretty Pictures circuit design
• Use of CG: ➢ Scientific analysis and
➢Art. Entertainment, publishing visualization.
➢Movies, TV, books, magazines, ➢ Molecular
game biology(human brain),
mat
Unit 1: Module 3
• Use of CG: ➢Flight simulators, virtual
➢Art. Entertainment, worlds.
publishing ➢Computer- aided design,
➢Movies , TV, books, architecture, electric
magazines, game circuit design
➢Image processing ➢Scientific analysis and
visualization.
➢Alter images, remove noise
➢Molecular
➢Processing monitoring biology(human brain),
➢Large systems or plants mat
➢Display simulations:
Unit 2: Module 1
• 1.1 Application of • Presentation Graphics: To
Computer Graphics produce illustrations which
• Computer-Aided Design for summarize various kinds of
engineering and data. Except 2D, 3D graphics
architectural systems etc.: are good tools for reporting
Objects maybe displayed in more complex data.
a wireframe outline form. • Computer Art: Painting
Multi-window environment packages are available. With
is also favored for cordless, pressure-sensitive
producing various zooming stylus, artists can produce
scales and views. electronic paintings which
Animations are useful for simulate different brush
testing performance. strokes, brush widths &
colors.
Unit 2: Module 2
Photorealistic techniques, models of specialized
morphing and animations systems such as the
are very useful in training of ship captains
commercial art. For films, and aircraft pilots.
24 frames per second are • Visualization: For analyzing
required. For video scientific, engineering,
monitor, 30 frames per medical and business data
second are required. or behavior. Converting
• Entertainment: Motion data to visual form can
pictures, Music videos, help to understand mass
and TV shows, Computer volume of data very
games efficiently.
• Education and Training: • Image Processing: Image
Training with computer- processing is to apply
generated techniques to modify or
Unit 2: Module 3
interpret existing pictures. It is widely used in medical
applications.
• Graphical User Interface: Multiple window, icons,
menus allow a computer setup to be utilized more
efficiently.
• Video Display devices:
1. Cathode-Ray Tubes (CRT) - still the most common video
display device presently
Unit 2: Module 4
An electron gun emits a display is the Shadow-
beam of electrons, which mask meth. The light
passes through focusing emitted by phosphor
and deflection systems and fades very rapidly, so it
hits on the phosphor- needs to redraw the
coated screen. The number picture repeatedly.
of points displayed on a
CRT is referred to as
resolutions (eg. 1024x768).
Different phosphors emit
small light spots of
different colors, which can
combine to form a range of
colors. A common
methodology for color CRT
Unit 3: Module 1
There are 2 kinds of • The electron beam is
redrawing mechanisms: swept across the screen
Raster-Scan and Random- one row at a time from
Scan top to bottom. As it
Raster-Scan moves across each row,
the beam intensity is
turned on and off to
create a pattern of
illuminated spots. This
scanning process is called
refreshing. Each complete
scanning of a screen is
normally called a frame.
Unit 3: Module 2
• The refreshing rate, called • Each entry in the bitmap is
the frame rate, is normally a 1-bit data which
60 to 80 frames per second, determine the on (1) and
or described as 60 Hz to 80 off (0) of the intensity of
Hz. the pixel.
• Picture definition is stored • On color systems, the
in a memory area called the frame buffer storing the
frame buffer. This frame values of the pixels is
buffer stores the intensity called a pixmap (Though
values for all the screen
points. Each screen point is
nowadays many graphics
called a pixel (picture libraries name it as bitmap
element). On black and too). Each entry in the
white systems, the frame pixmap occupies a number
buffer storing the values of of bits to represent the
the pixels is called a bitmap. color of the pixel.
Unit 3: Module 3
• The raster graphics developed in
early 70‟s.
• It is common CRT monitor.
• It is based on TV technology.
• In this system, electron beam
swaps across the screen one row
at a time form top to bottom.
• Beam intensity vary (on or off)
by the movement of electron
beam across each room.
• Picture definitions are stored in
refresh buffer or frame buffer
which holds the setup intensity
values for all the screen point
also known as pixel. (pel)
Unit 3: Module 4
• Stored intensity values are • The refresh rate for this
retrieved form the refresh system is at the rate of
buffer and painted on the 60 to 80 frame per
screen on scan line (one second. i.e refresh rate
row at a time). are described in units of
• It is suited for realistic cycle per second.
scenes containing shading
and color pattern.
• In monochrome monitor
frame buffer consists of
one bit per each pixel and
for color monitor frame
buffer consists of 24 bits
for each pixel.
Unit 3: Module 5
• In addition to the CPU a
special buffer processor
called video controller or
display controller is used to
control the operations of
display device.
• Frame buffer can be any
where in the system
memory, and the video
controller accesses the
frame buffer to refresh the
• Interactive raster screen.
graphic generally • A fixed area of system
employ several memory is reserved for the
processing units. frame buffer.
Unit 3: Module 6
• Video controller direct • Scan line are labeled
access the frame buffer. from Ymax at the top of
• Frame buffer location and screen to zero at the
corresponding screen bottom.
position are reference in • Scan line are labeled
Cartesian co-ordinate. from 0 to Xmax .
• Generally the co-ordinate
origin is defined at the
lower left screen corner.
• Positive X value increases to
the right and positive Y
value increases from
bottom to top.
Unit 4: Module 1
• Video Controller: • Initially the X register is set
0 and Y register is set to
ymax .
• The value stored in the
frame buffer for this pixel
position is then retrieved
and then used to set the
intensity of CRT beam.
• Then the x register is
increased by one and
Fig. Basic video controller
process repeated for the
Refresh operation.
next pixel in the top scan
• Two register are used to line.
store the co-ordinates of
the screen pixel.
Unit 4: Module 2
• This process is repeated • After cycling though
for each pixel along line. each pixel along the
• When the last pixel of the bottom scan line (y =0)
top scan line has been the video controller
processed the x register is resets the register the
reset to zero and y register first pixel poison on the
is decremented by 1 pixels top scan line and refresh
on the screen lines are process starts over.
processed against inturn; • Screen must be refresh
and the process is at least at the rate of 60
repeated for each frames per second.
successive scan line.
Unit 4: Module 3
• To speed of the pixel • Besides these refresh
processing video controller operation video controller
can retrieve multiple pixel also performs different
values from the refresh operation video controller
buffer on each pass. The retrieved pixel intensity
multiple pixel intensity are from different memory
then stored in a separate area on different refresh
register and used to cycle.
controlled the CRT bit • In high quality system, for
intensity for a group of example , two frame
adjacent pixel. When that buffers are often provided
group of pixel has been so that gun buffer can be
processes the next block used for refreshing while
of pixel values is retrieved the other is being filled
from the frame buffer. with intensity values.
Unit 4: Module 4
• This provides a fast • Random Scan display
mechanism for generating Processor:
real time animations • Figure given below shows
seans different views of the architecture of raster
moving object can be graphic system with a
successively loaded in the display processor.
refresh buffer.
• It contains a separate
• Video controller also display processor the
contain a look up table purpose of the display
instead of controlling CRT processor is to free the
beam intensity directly. CPU from graphics loads.
This provides a fast It is also called graphic
mechanism for changing controller or display co-
screen intensity values. processor.
Unit 4: Module 5
• The system memory
holds the data plus those
program that execute on
CPU: the application
program, graphics
package and operation
system. Similarly display
processor holds data plus
the programs that
perform scan conversion
• Fig. Architecture of raster and the raster operation.
graphics system with a
display processor
Unit 5: Module 1
• Random-Scan (Vector Random-scan generally
Display) have higher resolution
• The CRT's electron beam is than raster systems & can
directed only to the parts produce smooth line
of the screen where a drawings, however it
picture is to be drawn. The cannot display realistic
picture definition is stored shaded scenes.
as a set of line-drawing
commands in a refresh
display file or a refresh
buffer in memory.
Unit 5: Module 2
• Raster and vector display
architecture:
• In a random scan display,
an image on the screen is
drawn with one line at
time and for this reason it
is also called vector
display.
• A typical organization of a
vector system is shown
below.
• An application program is
input and stored in the
system memory along
with the graphic package.
Unit 5: Module 3
• This display file is then accessed
by the display processor to
refresh the screen.
• Sometimes the display
processor in a random scan is
referred to as a display
processing unit or a graphics
• Graphics commands controller.
in the application • The buffer stores and display
program are list of display program which
translated by the contains points and line
graphic package into plotting commands with (x,y)
a display file stored and end point co-ordinate as
in the system well as character plotting
memory. commands.
Unit 5: Module 4
• The commands for plotting • The main principal of
points lines and characters the vector system is
are interpreted by the that the beam is
display processor. deflected form end
• It sends digital and points point to end point as
co-ordinates to a vector detected by arbitrary
generator that converts order of the display
digital co-ordinates values commands term as
to analog voltages for random scan.
beam deflection circuits
that display an electron
beam writing on CRT
phosphor coating.
Unit 5: Module 5
• Since the light out put • (Note: jump instruction in
of phosphor decays in the figure above in refresh
tens or hundreds of buffer is to provide cyclic
microseconds, the refresh.
display processor must • A CRT beam in this system
cycle through the is adjusted in such a way
display list to refresh that electron beam only
the phosphor at least hits the spot where the
30 times per seconds graphics is to be drawn.
(Hz) to have flicker
hence the buffer • Thus the refresh rate in this
holding display list is system depends upon the
usually called a refresh number of lines to be
buffer. displayed.
Unit 5: Module 6
• Random scan display are • are stored in the form of
design to draw all the line drawing commands.
component lines of Disadvantages:
pictures 30 to 60 times
per seconds. • When the number of
• Vector display system are command in the buffer
mostly used for line goes high, the system
drawing applications and takes long time to process
can not display realistic and draw pictures.
shaded scenes. • It cannot apply shading
• It produces smooth line features.
drawing because the CRT
beam directly follows the
line path definitions that
Unit 5: Module 7
• Display Controller • Anti-Aliasing
• For a raster display • On dealing with integer pixel
device reads the frame positions, jagged or stair step
buffer and generates the appearances happen very
control signals for the usually. This distortion of
screen, ie. the signals for information due to under
horizontal scanning and sampling is called aliasing. A
vertical scanning. Most number of ant aliasing
display controllers methods have been developed
include a color map (or to compensate this problem.
video look-up table). The One way is to display objects
major function of a color at higher resolution. However,
map is to provide a there is a limit to how big we
mapping between the can make the frame buffer &
input pixel value to the still maintaining acceptable
output color. refresh rate.
Unit 6: Module 1
The frame buffer contain the • This process is called
displayable image created by scan conversion.
the scan conversion and Comparison between
raster operation. raster & vector graphics:
• It has also a separate display 1. Since the picture
processor or memory area definition is stored as the
in addition to system set of line-drawing
memory. instructions and not as a
• The major task of display set of intensity values for
processor is digitizing a all screen points, vector
picture definition given in an displays generally have
application program into a higher resolution than
set of pixel intensity values raster systems. For these
for storage in the frame reasons, random-scan
buffer.
Unit 6: Module 2
systems are designed for implement than in random scan
line-drawing applications system, whose vector generators
and cannot display must be highly accurate to
realistic shaded scenes. provide linearity and repeatability
Moreover, vector of beam’s deflection.
displays produce smooth 3. One major advantage of raster
line drawings because graphics over vector graphics
CRT beam directly includes the ability to display
follows a line path but areas filled with solid colors or
raster system in contrast patterns. Moreover, the refresh
produces jagged lines process is independent of
that are plotted as a complexity (i.e. no. of lines) of
discrete point sets. image and each pixel in buffer
2. Raster scan is easier can be read out on each refresh
and less expensive to cycles, allowing flicker free
display.
Unit 6: Module 3
4. Major disadvantage of raster system
compared to vector system is the discrete
nature of the pixel representation. This
happens due to scan-conversion of end
points (vertices) into their component
pixels in frame buffer.
5. Another drawback of raster system
arises from the nature of raster itself. A
vector system can draw continuous,
smooth line (curves) from any point on the
CRT face to other, the raster system
displays these lines (curves)
mathematically using various algorithms
causing problems of “jaggering” or
“staircasing”.
Unit 7: Module 1
• Drawing a Line in Raster • In its simplest
Devices implementation the DDA
• DDA Algorithm Line drawing algorithm
interpolates values in
• A hardware or software interval [(xstart, ystart),
implementation of a (xend, yend)] by computing
digital differential for each xi the equations xi
analyzer (DDA) is used = xi−1+1/m, yi = yi−1 + m,
for linear interpolation where Δx = xend − xstart
of variables over an and Δy = yend − ystart and
interval between start m = Δy/Δx.
and end point. DDAs are
used for rasterization of
lines, triangles and
polygons.
Unit 7: Module 2
The DDA is a scan The basic concept is:
conversion line - A line can be specified in the form:
algorithm based
on calculating y = mx + c
either dy or dx. A - Let m be between 0 to 1, then the
line is sampled at slope of the line is between 0 and 45
unit intervals in degrees.
one coordinate
and - For the x-coordinate of the left end
corresponding point of the line, compute the
integer values corresponding y value according to
nearest the line the line equation.
path are
determined for
other coordinates.
Unit 7: Module 3
• Thus we get the left • If D1 is smaller than D2, it
end point as (x1,y1), means that the line is closer
where y1 may not be to the upper pixel than the
an integer. lower pixel, then, we set the
• Calculate the distance upper pixel to on; otherwise
of (x1,y1) from the we set the lower pixel to on.
center of the pixel • Then increment x by 1 and
immediately above it repeat the same process
and call it D1 until x reaches the right end
• Calculate the distance point of the line.
of (x1,y1) from the • This method assumes the
center of the pixel width of the line to be zero.
immediately below it
and call it D2
Unit 7: Module 4
D2 for decision of pixel
location, it computes a
value, p, which is defined as:
• p = (D2-D1)* horizontal
length of the line
• if p>0, it means D1 is
smaller than D2, and we
Bresenham's Line can determine the pixel
Algorithm (BLA) location accordingly.
• This algorithm is very • However, the computation
efficient since it use only of p is very easy:
incremental integer • The initial value of p is 2 *
calculations. Instead of vertical height of the line -
calculating the non- horizontal length of the
integral values of D1 and line.
Unit 7: Module 5
• At succeeding x locations, if p has been smaller
than 0, then, we increment p by 2 * vertical
height of the line, otherwise we increment p by
2 * (vertical height of the line - horizontal length
of the line).
• All the computations are on integers. The
incremental method is applied to
void BresenhamLine(int x1, int y1, int x2, int y2)
{ int x, y, p, const1, const2;
/* initialize variables */ p=2*(y2-y1)-(x2-x1);
const1=2*(y2-y1);
const2=2*((y2-y1)-(x2-x1));
x=x1;
y=y1;
Unit 7: Module 6
SetPixel(x,y);
while (x<xend) {
x++;
if (p<0)
{ p=p+const1;
}
else
{ y++;
p=p+const2;
}
SetPixel(x,y);
}
}
Bitmap
• A graphics pattern such as an icon or a character may be
needed frequently, or may need to be re-used.
Unit 7: Module 7
• Generating the pattern every time when
needed may waste a lot of processing time.
• A bitmap can be used to store a pattern and
duplicate it to many places on the image or
on the screen with simple copying
operations.
Unit 8: Module 1
Example 1: Digitize
a line with end
points (10,15) and
(15, 30).
Solution:
• The slope of line
is
Comments
1. It is faster to calculate pixel
• So we sample at y position.
interval. The 2. Due to propagation of round off
formula is given errors due to successive addition
by xk+1= xk+1/m. the calculated pixel may shift
among from the true line path.
Unit 8: Module 2
Example 2 We know that ,
• Digitize a line with end If pk < 0
points (15, 18) and Pk+1 = pk+2△y
(10,15) using BLA
Yk+1 = yk
Solution:
if p ≥ 0
△y = /15-18/ = 3
Pk+1 = pk+2△y– 2 △x
△x = /10-15/ = 5
Yk+1 = yk +1
|m|<1, we sample at x
direction. We have pk ≥ 0,
First pixel ,(10, 15) So, p1 = p0 + 2 △y – 2 △x
P0 = 2 △y – △x =1+2x3–2x5
= 2 × 3- 5 = 1 = -3
Unit 8: Module 3
P2 = p1 + 2 △y
= - 3+2 x 3
=3
P3 = p2 + 2△y – 2 △x
= 3+ 2 x 3 – 2 x 5
= 9 – 10
= -1
Unit 8: Module 4
Example 3 We know that, If pk ≥ 0
Digitize a line with end P1 = p0 + 2 △y – 2 △x
points (15, 15) and (10, 18) =1+2x3–2x5
use BLE and DDA. = -3
Solution:
△y = /15-18/ = 3
△y = / 10-15/ = 5 m =
3/ 5 = 0.6
|m| < 1, we sample at
x direction,
First pixel , ( 10, 15) Pk < 0
P0 = 2 △y– △x P2 = pk + 2 △y.
=2×3–5 = -3 + 2 x 3
=1 =3
Unit 8: Module 5
P3 = p2 + 2 △y – 2 △x
= 3 + 2×3 – 2× 5
= -1

Pk < 0
P4 = p3 + 2 △y
= -1+ 2×3
=5
Unit 8: Module 6

You might also like