You are on page 1of 74

COMPUTERGRAPHI

CSANDVI
SUALI
ZATI
ON(
18CS62)

1.Ov
erv
iew:Comput
erGr
aphi
csandOpenGL

1.
1 Basi csofcomput ergr aphi cs
1.
2 Appl icat
ionofComput erGr aphics,
1.
3 VideoDi splayDev i
ces
1.
3.1 Random ScanandRast erScandi spl
ays,
1.
3.2 Col orCRTmoni tors,
1.
3.4Fl
atpaneldi splays.
1.
4 Rast er-
scansyst ems:
1.
4.1 Vi deocont roller,
1.
4.2 Rast erscanDi spl aypr ocessor ,
1.
4.3 Gr aphi cswor kstat i
onsandvi ewi ngsystems,
1.
5 I
nputdevi ces,
1.
6 Graphi csnet wor ks,
1.
7 Graphi csont hei nter net ,
1.
8 Graphi cssof twar e.
Op enGL :
1.
9 I
nt roduct i
ont oOpenGL,
1.
1 0 Coor dinater eferencef rames,
1.
1 1 Speci fyi
ngt wo- di mensi onalwor ldcoordinateref
erencef
ramesi
nOpenGL,
1.
1 2 OpenGLpoi ntf unct ions,
1.
1 3 OpenGLl i
nef unct i
ons, pointattri
butes,
1.
1 4 Li neat tr
ibutes,
1.
1 5 Cur veattributes,
1.
1 6 OpenGLpoi ntat tribut ef uncti
ons,
1.
1 7 OpenGLl i
neat t
ribut ef unct i
ons,
1.
1 8 Li nedr awingal gor it
hms( DDA, Bresenham’ s)
,
1.
1 9 Ci rclegener at i
onal gor ithms( Bresenham’ s).

1.
1Basi
csofComput
erGr
aphi
cs
Comput
ergr
aphi
csi
sanar
tofdr
awi
ngpi
ctur
es,
li
nes,
char
ts,
etc.usi
ngcomput
erswi
th
t
hehel
pofpr
ogr
ammi
ng.Comput
ergr
aphi
csi
magei
smadeupofnumberofpi
xel
s.
Pi
xel
ist
hesmal
l
estaddr
essabl
egr
aphi
cal
uni
trepr
esent
edont
hecomput
erscr
een.

DEPARTMENTOFCSE,
BRCE 1
COMPUTERGRAPHI
CSANDVI
SUALI
ZATI
ON(
18CS62)

1.
2Appl
i
cat
ionsofComput
erGr
aphi
cs
a.
GraphsandChar
ts

 Anear
lyappl
i
cat
ionf
orcomput
ergr
aphi
csi
sthedi
spl
ayofsi
mpl
edat
agr
aphs
usual
l
ypl
ott
edonachar
act
erpr
int
er.Dat
apl
ott
ingi
sst
il
loneoft
hemost
commongr
aphi
csappl
i
cat
ion.
 Gr
aphs & char
ts ar
e commonl
y used t
o summar
ize f
unct
ional
,st
ati
sti
cal
,
mat
hemat
ical
,engi
neer
ingandeconomi
cdat
aforr
esear
chr
epor
ts,manager
ial
summar
iesandot
hert
ypesofpubl
i
cat
ions.
 Ty
pical
l
yexampl
esofdat
apl
otsar
eli
negr
aphs,barchar
ts,pi
echar
ts,sur
face
gr
aphs,
cont
ourpl
otsandot
herdi
spl
aysshowi
ngr
elat
ionshi
psbet
weenmul
ti
ple
par
amet
ersi
ntwodi
mensi
ons,
thr
eedi
mensi
ons,
orhi
gher
-di
mensi
onal
spaces

b.
Comput
er-
AidedDesi
gn

 Amaj
oruseofcomput
ergr
aphi
csi
sindesi
gnpr
ocesses-
par
ti
cul
arl
yfor
engi
neer
ingandar
chi
tect
ural
syst
ems.

DEPARTMENTOFCSE,
BRCE 2
COMPUTERGRAPHI
CSANDVI
SUALI
ZATI
ON(
18CS62)

 CAD,
comput
er-
aideddesi
gnorCADD,
comput
er-
aideddr
aft
inganddesi
gn
met
hodsar
enowr
out
inel
yusedi
ntheaut
omobi
l
es,
air
craf
t,spacecr
aft
,
comput
ers,
homeappl
i
ances.
 Ci
rcui
tsandnet
wor
ksf
orcommuni
cat
ions,
wat
ersuppl
yorot
herut
il
it
iesar
e
const
ruct
edwi
thr
epeat
edpl
acementofaf
ewgeogr
aphi
cal
shapes.
 Ani
mat
ionsar
eof
tenusedi
nCADappl
i
cat
ions.Real
-t
ime,
comput
erani
mat
ions
usi
ngwi
re-
fr
ameshapesar
eusef
ulf
orqui
ckl
ytest
ingt
heper
for
manceofa
v
ehi
cleorsy
stem.

c.
Vir
tual
-Real
it
yEnvi
ronment
s

 Ani
mat
ions i
nvi
rt
ual
-r
eal
i
ty env
ironment
s ar
e of
ten used t
otr
ain heav
y-
equi
pment oper
ator
s or t
o anal
yze t
he ef
fect
iveness of v
ari
ous cabi
n
conf
igur
ati
onsandcont
rol
placement
s.
 Wi
thv
irt
ual
-r
eal
i
tysy
stems,desi
gner
sandot
her
scanmov
eaboutandi
nter
act
wi
thobj
ect
sinv
ari
ousway
s.Ar
chi
tect
uraldesi
gnscanbeexami
nedbyt
aki
ng
si
mul
ated“
wal
k”t
hrought
her
oomsorar
oundt
heout
sidesofbui
l
dingst
obet
ter
appr
eci
atet
heov
eral
lef
fectofapar
ti
cul
ardesi
gn.
 Wi
thaspeci
algl
ove,wecanev
en“
grasp”obj
ect
sinasceneandt
urnt
hem ov
eror
move
t
hem f
rom onepl
acet
oanot
her
.
d.
Dat
aVi
sual
izat
ions
 Pr
oduci
nggr
aphi
calr
epr
esent
ati
onsf
orsci
ent
if
ic,engi
neer
ingandmedi
caldat
a
set
sandpr
ocessesi
sanot
herf
air
lynewappl
i
cat
ionofcomput
ergr
aphi
cs,
whi
ch
i
s gener
all
yref
err
ed t
o as sci
ent
if
icv
isual
i
zat
ion.And t
he t
erm busi
ness

DEPARTMENTOFCSE,
BRCE 3
COMPUTERGRAPHI
CSANDVI
SUALI
ZATI
ON(
18CS62)

v
isual
i
zat
ioni
susedi
nconnect
ionwi
thdat
aset
srel
atedt
ocommer
ce,i
ndust
ry
andot
hernonsci
ent
if
icar
eas.

DEPARTMENTOFCSE,
BRCE 4
COMPUTERGRAPHI
CSANDVI
SUALI
ZATI
ON(
18CS62)

 Ther
ear
emanydi
ff
erentki
ndsofdat
aset
sandef
fect
ivev
isual
i
zat
ionschemes
dependont
hechar
act
eri
sti
csoft
hedat
a.Acol
l
ect
ionofdat
acancont
ainscal
ar
v
alues,
vect
orsorhi
gher
-or
dert
ensor
s.

e.
Educat
ionandTr
aini
ng

 Comput
ergener
ated model
s ofphy
sical
,
financi
al,
pol
i
tical
,
soci
al,
economi
c&
ot
hersy
stemsar
eof
tenusedaseducat
ional
aids.
 Model
sofphy
sicalpr
ocessesphy
siol
ogi
calf
unct
ions,
equi
pment
,suchast
he
col
orcodeddi
agr
am asshowni
nthef
igur
e,canhel
ptr
aineest
ounder
standt
he
oper
ati
onofasy
stem.
 Forsomet
rai
ningappl
i
cat
ions,
speci
alhar
dwar
esy
stemsar
edesi
gned.
Exampl
es
ofsuchspeci
ali
zedsy
stemsar
ethesi
mul
ator
sforpr
act
icesessi
ons,
ai
rcr
aft
pi
l
ots,
ai
rtr
aff
ic-cont
rol
per
sonnel
.
 Somesi
mul
ator
shav
eno v
ideo scr
eens,
foreg:f
li
ghtsi
mul
atorwi
th onl
ya
cont
rol
panel
fori
nst
rumentf
lyi
ng

DEPARTMENTOFCSE,
BRCE 5
COMPUTERGRAPHI
CSANDVI
SUALI
ZATI
ON(
18CS62)

f
.Comput
erAr
t

 Thepi
ctur
eisusual
l
ypai
ntedel
ect
roni
cal
l
yonagr
aphi
cst
abl
etusi
ngast
ylus,
whi
chcansi
mul
atedi
ff
erentbr
ushst
rokes,
brushwi
dthsandcol
ors.
 Fi
near
ti
stsuseav
ari
etyofot
hercomput
ert
echnol
ogi
est
opr
oducei
mages.To
cr
eat
epi
ctur
est
hear
ti
stusesacombi
nat
ionof3Dmodel
i
ngpackages,t
ext
ure
mappi
ng,
drawi
ngpr
ogr
amsandCADsof
twar
eet
c.
 Commer
cialar
tal
sousest
heses“
pai
nti
ng”t
echni
quesf
orgener
ati
ngl
ogos&
ot
herdesi
gns,pagel
ayout
scombi
ningt
ext&gr
aphi
cs,TVadv
ert
isi
ngspot
s&
ot
herappl
i
cat
ions.
 Acommongr
aphi
csmet
hodempl
oyedi
nmanyt
elev
isi
oncommer
cial
sis
mor
phi
ng,
wher
eoneobj
ecti
str
ansf
ormedi
ntoanot
her
.

g.
Ent
ert
ainment

 Tel
evi
sionpr
oduct
ion,
mot
ionpi
ctur
es,
andmusi
cvi
deosr
out
inel
yacomput
er
gr
aphi
csmet
hods.
 Somet
imesgr
aphi
csi
magesar
ecombi
nedal
i
veact
orsandscenesand
somet
imest
hef
il
msar
ecompl
etel
ygener
atedacomput
err
ender
ingand
ani
mat
iont
echni
ques.

DEPARTMENTOFCSE,
BRCE 6
COMPUTERGRAPHI
CSANDVI
SUALI
ZATI
ON(
18CS62)

 Somet
elev
isi
onpr
ogr
amsal
souseani
mat
iont
echni
quest
ocombi
necomput
er
gener
atedf
igur
esofpeopl
e,ani
mal
s,orcar
toonchar
act
erswi
tht
heact
ori
na
sceneort
otr
ansf
orm anact
or’
sfacei
ntoanot
hershape.

h.I
magePr
ocessi
ng

 Themodi
fi
cat
ionori
nter
pret
ati
onofexi
sti
ngpi
ctur
es,
suchasphot
ogr
aphsand
TVscansi
scal
l
edi
magepr
ocessi
ng.
 Met
hodsusedi
ncomput
ergr
aphi
csandi
magepr
ocessi
ngov
erl
ap,
thet
wo
ar
easar
econcer
nedwi
thf
undament
all
ydi
ff
erentoper
ati
ons.
 I
magepr
ocessi
ngmet
hodsar
eusedt
oimpr
ovepi
ctur
equal
i
ty,
anal
yzei
mages,
orr
ecogni
zev
isual
pat
ter
nsf
orr
obot
icsappl
i
cat
ions.
 I
magepr
ocessi
ngmet
hodsar
eof
tenusedi
ncomput
ergr
aphi
cs,
andcomput
er
gr
aphi
csmet
hodsar
efr
equent
lyappl
i
edi
nimagepr
ocessi
ng.
 Medi
cal
appl
i
cat
ionsal
somakeext
ensi
veuseofi
magepr
ocessi
ngt
echni
ques
f
orpi
ctur
eenhancement
sint
omogr
aphyandi
nsi
mul
ati
onsandsur
gical
oper
ati
ons.
 I
t i
s al
so used i
n comput
ed X-
ray t
omogr
aphy
(CT)
,posi
ti
on
emi
ssi
ont
omogr
aphy
(PET)
,andcomput
edaxi
alt
omogr
aphy
(CAT)
.

i
.Gr
aphi
calUserI
nter
faces
 I
tiscommonnowf
orappl
i
cat
ionssof
twar
etopr
ovi
degr
aphi
cal
useri
nter
face(
GUI
).
 Amaj
orcomponentofgr
aphi
cal
int
erf
acei
sawi
ndowmanagert
hatal
l
owsa
usert
odi
spl
aymul
ti
ple,
rect
angul
arscr
eenar
eascal
l
eddi
spl
aywi
ndows.

DEPARTMENTOFCSE,
BRCE 7
COMPUTERGRAPHI
CSANDVI
SUALI
ZATI
ON(
18CS62)

 Eachscr
eendi
spl
ayar
eacancont
ainadi
ff
erentpr
ocess,showi
nggr
aphi
calor
non-gr
aphi
cali
nfor
mat
ion,andv
ari
ousmet
hodscanbeused t
o act
ivat
ea
di
spl
aywi
ndow.
 Usi
ngani
nter
act
ivepoi
nti
ngdev
ice,suchasmouse,wecanact
iveadi
spl
ay
wi
ndow onsomesy
stemsbyposi
ti
oni
ngt
hescr
eencur
sorwi
thi
nthewi
ndow
di
spl
ayar
eaandpr
essi
ngt
hel
eftmousebut
ton.

1.
3Vi
deoDi
spl
ayDev
ices
 Thepr
imar
yout
putdev
icei
nagr
aphi
cssy
stem i
sav
ideomoni
tor
.
 Hi
stor
ical
l
y,t
heoper
ati
onofmostv
ideomoni
tor
swasbasedont
hest
andar
d
cat
hoder
ayt
ube(
CRT)desi
gn,
butsev
eral
othert
echnol
ogi
esexi
st.
 I
nrecenty
ear
s,f
lat
-panel
displ
ayshav
ebecomesi
gni
fi
cant
lymor
epopul
ardue
t
othei
rreducedpowerconsumpt
ionandt
hinnerdesi
gns.

Ref
reshCat
hode-
RayTubes

DEPARTMENTOFCSE,
BRCE 8
COMPUTERGRAPHI
CSANDVI
SUALI
ZATI
ON(
18CS62)

 Abeam ofel
ect
rons,emi
tt
edbyanel
ect
rongun,passest
hroughf
ocusi
ngand
def
lect
ion sy
stems t
hatdi
rectt
he beam t
owar
d speci
fi
ed posi
ti
ons on t
he
phosphor
-coat
edscr
een.
 Thephosphort
henemi
tsasmal
lspotofl
i
ghtateachposi
ti
oncont
act
edbyt
he
el
ect
ronbeam andt
hel
i
ghtemi
tt
edbyt
hephosphorf
adesv
eryr
api
dly
.
 Onewayt
omai
ntai
nthescr
eenpi
ctur
eist
ost
oret
hepi
ctur
einf
ormat
ionasa
char
gedi
str
ibut
ionwi
thi
ntheCRTi
nor
dert
okeept
hephosphor
sact
ivat
ed.
 Themostcommonmet
hodnow empl
oyedf
ormai
ntai
ningphosphorgl
ow i
sto
r
edr
aw t
hepi
ctur
erepeat
edl
ybyqui
ckl
ydi
rect
ingt
heel
ect
ronbeam backov
er
t
hesamescr
eenpoi
nts.Thi
sty
peofdi
spl
ayi
scal
l
edar
efr
eshCRT.
 Thef
requencyatwhi
chapi
ctur
eisr
edr
awnont
hescr
eeni
sref
err
edt
oast
he
r
efr
eshr
ate.

Oper
ati
onofanel
ect
rongunwi
thanaccel
arat
inganode

 Thepr
imar
ycomponent
sofanel
ect
ronguni
naCRTar
etheheat
edmet
al
cat
hodeandacont
rol
gri
d.
 Theheati
ssuppl
i
edt
othecat
hodebydi
rect
ingacur
rentt
hroughacoi
lofwi
re,
cal
l
edt
hef
il
ament
,insi
det
hecy
li
ndr
ical
cat
hodest
ruct
ure.
 Thi
scausesel
ect
ronst
obe“
boi
l
edof
f”t
hehotcat
hodesur
face.
 I
nsi
det
heCRTenv
elope,
thef
ree,
negat
ivel
ychar
gedel
ect
ronsar
ethen
accel
erat
edt
owar
dthephosphorcoat
ingbyahi
ghposi
ti
vev
olt
age.

DEPARTMENTOFCSE,
BRCE 9
COMPUTERGRAPHI
CSANDVI
SUALI
ZATI
ON(
18CS62)

 I
ntensi
tyoft
heel
ect
ronbeam i
scont
rol
l
edbyt
hev
olt
ageatt
hecont
rol
gri
d.
 Si
ncet
heamountofl
i
ghtemi
tt
edbyt
hephosphorcoat
ingdependsont
he
numberofel
ect
ronsst
ri
ki
ngt
hescr
een,t
hebr
ight
nessofadi
spl
aypoi
nti
s
cont
rol
l
edbyv
ary
ingt
hev
olt
ageont
hecont
rol
gri
d.
 Thef
ocusi
ngsy
stem i
naCRTf
orcest
heel
ect
ronbeam t
oconv
erget
oasmal
l
cr
osssect
ionasi
tst
ri
kest
hephosphorandi
tisaccompl
i
shedwi
thei
ther
el
ect
ri
cormagnet
icf
iel
ds.
 Wi
thel
ect
rost
ati
cfocusi
ng,t
heel
ect
ronbeam i
spassedt
hroughaposi
ti
vel
y
char
gedmet
alcy
li
ndersot
hatel
ect
ronsal
ongt
hecent
erl
i
neoft
hecy
li
nderar
e
i
nequi
l
ibr
ium posi
ti
on.
 Deflect
ionoft
heel
ect
ronbeam canbecont
rol
l
edwi
thei
therel
ect
ri
cormagnet
ic
fi
elds.
 Cat
hode-
rayt
ubesar
ecommonl
yconst
ruct
edwi
tht
wopai
rsofmagnet
ic-
def
lect
ion
coi
l
s
 Onepai
rismount
edont
het
opandbot
tom oft
heCRTneck,andt
heot
her
pai
rismount
edonopposi
tesi
desoft
heneck.
 Themagnet
icf
iel
dpr
oducedbyeachpai
rofcoi
l
sresul
tsi
nat
rav
ersedef
lect
ion
f
orcet
hati
sper
pendi
cul
art
obot
hthedi
rect
ionoft
hemagnet
icf
iel
dandt
he
di
rect
ionoft
rav
eloft
heel
ect
ronbeam.
 Hor
izont
alandv
ert
ical
def
lect
ionsar
eaccompl
i
shedwi
tht
hesepai
rofcoi
l
s

El
ect
rost
ati
cdef
lect
ionoft
heel
ect
ronbeam i
naCRT
 Whenel
ect
rost
ati
cdef
lect
ioni
sused,t
wopai
rsofpar
all
elpl
atesar
emount
ed
i
nsi
det
heCRTenv
elopewher
e,onepai
rofpl
atesi
smount
edhor
izont
all
yto
cont
rolv
ert
icaldef
lect
ion,andt
heot
herpai
rismount
edv
ert
ical
l
ytocont
rol
hor
izont
aldef
lect
ion.
 Spot
sofl
i
ghtar
epr
oducedont
hescr
eenbyt
het
ransf
eroft
heCRTbeam ener
gy
t
othephosphor
.
 Whent
heel
ect
ronsi
nthebeam col
l
idewi
tht
hephosphorcoat
ing,t
heyar
e
st
oppedandt
hei
rki
net
icener
gyi
sabsor
bedbyt
hephosphor
.
 Par
toft
hebeam ener
gyi
sconv
ert
edbyt
hef
ri
cti
oni
ntot
heheatener
gy,
andt
he
r
emai
ndercausesel
ect
rosi
nthephosphorat
omst
omov
eupt
ohi
gherquant
um-
ener
gyl
evel
s.

DEPARTMENTOFCSE,
BRCE 10
COMPUTERGRAPHI
CSANDVI
SUALI
ZATI
ON(
18CS62)

 Af
terashor
tti
me,t
he“
exci
ted”phosphorel
ect
ronsbegi
ndr
oppi
ngbackt
othei
r
st
abl
egr
oundst
ate,
giv
ingupt
hei
rext
raener
gyassmal
lquant
um ofl
i
ghtener
gy
cal
l
edphot
ons.

Cat
hodeRayTube

 Whatweseeont
hescr
eeni
sthecombi
nedef
fectofal
ltheel
ect
ronsl
i
ght
emi
ssi
ons:agl
owi
ngspott
hatqui
ckl
yfadesaf
teral
ltheexci
tedphosphor
el
ect
ronshav
eret
urnedt
othei
rgr
oundener
gyl
evel
.
 Thef
requencyoft
hel
i
ghtemi
tt
edbyt
hephosphori
spr
opor
ti
onalt
otheener
gy
di
ff
erencebet
weent
heexci
tedquant
um st
ateandt
hegr
oundst
ate.
 Lowerper
sist
encephosphor
srequi
redhi
gherr
efr
eshr
atest
omai
ntai
napi
ctur
e
ont
hescr
eenwi
thoutf
li
cker
.
 Themaxi
mum numberofpoi
ntst
hatcanbedi
spl
ayedwi
thoutov
erl
aponaCRT
i
sref
err
edt
oasar
esol
uti
on.
 Resol
uti
onofaCRTi
sdependentont
het
ypeofphosphor
,thei
ntensi
tyt
o
bedi
spl
ayed,
andt
hef
ocusi
nganddef
lect
ionsy
stems.
 Hi
gh-
resol
uti
onsy
stemsar
eof
tenr
efer
redt
oashi
gh-
def
ini
ti
onsy
stems.

DEPARTMENTOFCSE,
BRCE 11
COMPUTERGRAPHI
CSANDVI
SUALI
ZATI
ON(
18CS62)

1.
3.1Rast
er-
ScanDi
spl
aysandRandom ScanDi
spl
ays
i
)Rast
er-
ScanDi
spl
ays
 Theel
ect
ronbeam i
ssweptacr
osst
hescr
eenoner
owatat
imef
rom t
opt
obot
tom.
 Asi
tmov
esacr
osseachr
ow,
thebeam i
ntensi
tyi
stur
nedonandof
ftocr
eat
ea
pat
ter
nofi
l
lumi
nat
edspot
s.
 Thi
sscanni
ngpr
ocessi
scal
l
edr
efr
eshi
ng.Eachcompl
etescanni
ngofascr
een
i
snor
mal
l
ycal
l
edaf
rame.
 Ther
efr
eshi
ngr
ate,
cal
l
edt
hef
ramer
ate,
isnor
mal
l
y60t
o80f
ramespersecond,
ordescr
ibedas60Hzt
o80Hz.
 Pi
ctur
edef
ini
ti
oni
sst
oredi
namemor
yar
eacal
l
edt
hef
ramebuf
fer
.
 Thi
sfr
amebuf
ferst
orest
hei
ntensi
tyv
aluesf
oral
lthescr
eenpoi
nts.Each
scr
eenpoi
nti
scal
l
edapi
xel
(pi
ctur
eel
ement
).
 Pr
oper
tyofr
ast
erscani
sAspectr
ati
o,whi
chdef
inedasnumberofpi
xel
col
umnsdi
vi
dedbynumberofscanl
i
nest
hatcanbedi
spl
ayedbyt
hesy
stem.

Case1:I
ncaseofbl
ackandwhi
tesy
stems
 Onbl
ackandwhi
tesy
stems,
thef
ramebuf
ferst
ori
ngt
hev
aluesoft
hepi
xel
sis
cal
l
edabi
tmap.
 Eachent
ryi
nthebi
tmapi
sa1-
bitdat
awhi
chdet
ermi
net
heon(
1)andof
f(0)of
t
hei
ntensi
tyoft
hepi
xel
.

DEPARTMENTOFCSE,
BRCE 12
COMPUTERGRAPHI
CSANDVI
SUALI
ZATI
ON(
18CS62)

Case2:I
ncaseofcol
orsy
stems
 Oncol
orsy
stems,t
hef
ramebuf
ferst
ori
ngt
hev
aluesoft
hepi
xel
siscal
l
eda
pi
xmap(
Thoughnowaday
smanygr
aphi
csl
i
brar
iesnamei
tasbi
tmapt
oo)
.
 Eachent
ryi
nthepi
xmapoccupi
esanumberofbi
tst
orepr
esentt
hecol
oroft
he
pi
xel
.Forat
ruecol
ordi
spl
ay,t
henumberofbi
tsf
oreachent
ryi
s24(
8bi
tsper
r
ed/
green/
bluechannel
,eachchannel28=256l
evel
sofi
ntensi
tyv
alue,i
e.256
v
olt
ageset
ti
ngsf
oreachoft
her
ed/
green/
blueel
ect
ronguns)
.

i
i)
.Random-
ScanDi
spl
ays
 Whenoper
atedasar
andom-
scandi
spl
ayuni
t,aCRThast
heel
ect
ronbeam
di
rect
edonl
ytot
hosepar
tsoft
hescr
eenwher
eapi
ctur
eist
obedi
spl
ayed.
 Pi
ctur
esar
egener
atedasl
i
nedr
awi
ngs,
wit
htheel
ect
ronbeam t
raci
ngoutt
he
componentl
i
nesoneaf
tert
heot
her
.
 Fort
hisr
eason,
random-
scanmoni
tor
sar
eal
sor
efer
redt
oasv
ect
ordi
spl
ays(
or
st
rokewr
it
ingdi
spl
aysorcal
l
igr
aphi
cdi
spl
ays)
.
 Thecomponentl
i
nesofapi
ctur
ecanbedr
awnandr
efr
eshedbyar
andom-
scan
sy
stem i
nanyspeci
fi
edor
der

 Apenpl
ott
eroper
atesi
nasi
mil
arwayandi
sanexampl
eofar
andom-
scan,
har
d-
copydev
ice.

DEPARTMENTOFCSE,
BRCE 13
COMPUTERGRAPHI
CSANDVI
SUALI
ZATI
ON(
18CS62)

 Ref
reshr
ateonar
andom-
scansy
stem dependsont
henumberofl
i
nest
obe
di
spl
ayedont
hatsy
stem.
 Pi
ctur
edef
ini
ti
oni
snowst
oredasasetofl
i
ne-
drawi
ngcommandsi
nanar
eaof
memor
yref
err
edt
oast
hedi
spl
ayl
i
st,
ref
reshdi
spl
ayf
il
e,v
ect
orf
il
e,ordi
spl
ay
pr
ogr
am
 Todi
spl
ayaspeci
fi
edpi
ctur
e,t
hesy
stem cy
clest
hrought
hesetofcommandsi
n
t
hedi
spl
ayf
il
e,dr
awi
ngeachcomponentl
i
nei
ntur
n.
 Af
teral
ll
ine-
drawi
ngcommandshav
ebeenpr
ocessed,
thesy
stem cy
clesbackt
o
t
hef
ir
stl
i
necommandi
nthel
i
st.
 Random-
scandi
spl
aysar
edesi
gnedt
odr
awal
lthecomponentl
i
nesofapi
ctur
e30
to60
t
imeseachsecond,
wit
hupt
o100,
000“
shor
t”l
i
nesi
nthedi
spl
ayl
i
st.
 Whenasmal
lsetofl
i
nesi
stobedi
spl
ayed,
eachr
efr
eshcy
clei
sdel
ayedt
o
av
oidv
eryhi
ghr
efr
eshr
ates,
whi
chcoul
dbur
noutt
hephosphor
.

Di
ff
erencebet
weenRast
erscansy
stem andRandom scansy
stem
Baseof
Rast
erScanSy
stem Random ScanSy
stem
Di
ff
erence
Theel
ect
ronbeam i
sswept Theel
ect
ronbeam i
sdi
rect
ed
onl
y
El
ectr
on acr
osst
hescr
een,
oner
ow
Beam t
othepar
tsofscr
een
atat
ime,
from t
opt
o
wher
eapi
ctur
eist
obe
bot
tom
dr
awn
I
tsr
esol
uti
oni
spoor I
tsresol
uti
oni
sgoodbecause
becauser
ast
ersy
stem i
n t
hissy
stem pr
oducessmoot
h
Resol
uti
on
cont
rastpr
oduceszi
gzag l
i
nesdr
awi
ngsbecauseCRT
l
i
nest
hatar
e beam
pl
ottedasdiscret
epointset
s. di
rect
lyf
oll
owst
hel
i
nepat
h.
Pi
cturedef
init
ionisst
ored
Pi
ctur
edef
ini
ti
oni
sst
oredasa
Pi
ctur
e asasetofi
ntensi
tyv
alues
setofl
i
nedr
awi
ngi
nst
ruct
ions
Def
ini
ti
on f
oral
lscr
eenpoi
nts,
cal
l
ed
i
nadi
spl
ayf
il
e.
pi
xel
s
i
nar
efr
eshbuf
ferar
ea.

DEPARTMENTOFCSE,
BRCE 14
COMPUTERGRAPHI
CSANDVI
SUALI
ZATI
ON(
18CS62)

Thecapabi
l
ityoft
his
Thesesy
stemsar
e
Real
i
sti sy
stem t
ost
orei
ntensi
ty
desi
gnedf
orl
i
ne-
drawi
ng
c v
aluesf
orpi
xel
makesi
t
andcan’
tdi
spl
ayr
eal
i
sti
c
Di
spl
ay wel
lsui
tedf
or
shadedscenes.
t
her
eal
i
sti
cdi
spl
ayofscenes

DEPARTMENTOFCSE,
BRCE 15
COMPUTERGRAPHI
CSANDVI
SUALI
ZATI
ON(
18CS62)

cont
ainshadowandcol
or
pat
ter
n.
Scr
eenpoi
nts/
pixel
sar
eused Mat
hemat
ical
funct
ionsar
eused
Dr
awanI
mage t
o
t
odr
awani
mage
dr
awani
mage

1.
3.2Col
orCRTMoni
tor
s
 ACRTmoni
tordi
spl
ayscol
orpi
ctur
esbyusi
ngacombi
nat
ionofphosphor
sthat
emi
tdi
ff
erent
-col
oredl
i
ght
.
 I
tpr
oducesr
angeofcol
orsbycombi
ningt
hel
i
ghtemi
tt
edbydi
ff
erentphosphor
s.
 Ther
ear
etwobasi
ctechni
quesf
orcol
ordi
spl
ay:
1.Beam-
penet
rat
iont
echni
que
2.Shadow-
maskt
echni
que
1)Beam-
penet
rat
iont
echni
que:
 Thi
stechni
quei
susedwi
thr
andom scanmoni
tor
s.
 I
nthi
stechni
quei
nsi
deofCRTcoat
edwi
tht
wophosphorl
ayer
susual
l
yredand
gr
een.
 Theout
erl
ayerofr
edandi
nnerl
ayerofgr
eenphosphor
.
 Thecol
ordependsonhowf
art
heel
ect
ronbeam penet
rat
esi
ntot
hephosphorl
ayer
.
 Abeam off
astel
ect
ronpenet
rat
esmor
eandexci
tesi
nnergr
eenl
ayerwhi
l
esl
ow
el
etr
onexci
tesout
err
edl
ayer
.
 Ati
nter
medi
atebeam speedwecanpr
oducecombi
nat
ionofr
edandgr
eenl
i
ght
s
whi
chemi
taddi
ti
onal
twocol
orsor
angeandy
ell
ow.
 Thebeam accel
erat
ionv
olt
agecont
rol
sthespeedoft
heel
ect
ronsandhence
col
orofpi
xel
.
Di
sadvant
ages:
 I
tisal
owcostt
echni
quet
opr
oducecol
ori
nrandom scanmoni
tor
s.
 I
tcandi
spl
ayonl
yfourcol
ors.
 Qual
i
tyofpi
ctur
eisnotgoodcompar
edt
oot
hert
echni
ques.

2) Shadow-
maskt
echni
que
 I
tpr
oduceswi
der
angeofcol
orsascompar
edt
obeam-
penet
rat
iont
echni
que.
 Thi
stechni
quei
sgener
all
yusedi
nrast
erscandi
spl
ays.I
ncl
udi
ngcol
orTV.

DEPARTMENTOFCSE,
BRCE 16
COMPUTERGRAPHI
CSANDVI
SUALI
ZATI
ON(
18CS62)

 I
nthi
stechni
queCRThast
hreephosphorcol
ordot
sateachpi
xel
posi
ti
on.
 Onedotf
orr
ed,
onef
orgr
eenandonef
orbl
uel
i
ght
.Thi
siscommonl
yknownas
Dott
ri
angl
e.
 Her
einCRTt
her
ear
ethr
eeel
ect
rongunspr
esent
,onef
oreachcol
ordot
.Anda
shadowmaskgr
idj
ustbehi
ndt
hephosphorcoat
edscr
een.
 Theshadowmaskgr
idconsi
stsofser
iesofhol
esal
i
gnedwi
tht
hephosphordot
pat
ter
n.
 Thr
eeel
ect
ronbeamsar
edef
lect
edandf
ocusedasagr
oupont
otheshadow
maskandwhent
heypasst
hroughahol
etheyexci
teadott
ri
angl
e.
 I
ndott
ri
angl
ethr
eephosphordot
sar
ear
rangedsot
hateachel
ect
ronbeam can
act
ivat
eonl
yit
scor
respondi
ngcol
ordotwheni
tpassest
hrought
heshadow
mask.
 Adott
ri
angl
ewhenact
ivat
edappear
sasasmal
ldotont
hescr
eenwhi
chhas
col
orofcombi
nat
ionoft
hreesmal
ldot
sint
hedott
ri
angl
e.
 Bychangi
ngt
hei
ntensi
tyoft
het
hreeel
ect
ronbeamswecanobt
aindi
ff
erent
col
orsi
ntheshadowmaskCRT.

1.
3.3 Fl
atPanelDi
spl
ay
 Thet
ermf
latpanel
displ
ayr
efer
stoacl
assofv
ideodev
icet
hathav
ereduced
v
olume,
wei
ght&powerr
equi
rementcompar
edt
oaCRT.
 Asf
latpanel
displ
ayi
sthi
nnert
hanCRTs,
wecanhangt
hem onwal
l
sorwearonour

DEPARTMENTOFCSE,
BRCE 17
COMPUTERGRAPHI
CSANDVI
SUALI
ZATI
ON(
18CS62)

wr
ist
s.

DEPARTMENTOFCSE,
BRCE 18
COMPUTERGRAPHI
CSANDVI
SUALI
ZATI
ON(
18CS62)

 Si
ncewecanev
enwr
it
eonsomef
latpanel
displ
ayst
heywi
l
lsoonbeav
ail
abl
eas
pocketnot
epads.
 Wecansepar
atef
latpanel
displ
ayi
ntwocat
egor
ies:
1.Emi
ssi
vedi
spl
ays:-t
heemi
ssi
vedi
spl
ayoremi
tt
ersar
edev
icest
hat
conv
ertel
ect
ri
calener
gy i
ntol
i
ght
.ForEx.Pl
asma panel
,thi
nfi
l
m
el
ect
rol
umi
nescentdi
spl
aysandl
i
ghtemi
tt
ingdi
odes.
2.Nonemi
ssi
vedi
spl
ays:-nonemi
ssi
vedi
spl
ayornonemi
tt
ersuse
opt
icalef
fect
stoconv
ertsunl
i
ghtorl
i
ghtf
rom someot
hersour
cei
nto
gr
aphi
cspat
ter
ns.ForEx.LCD(
Liqui
dCr
yst
alDi
spl
ay)
.

a)Pl
asmaPanel
sdi
spl
ays
Thi
sisal
socal
l
edgasdi
schar
gedi
spl
ays.
I
tisconst
ruct
edbyf
il
li
ngt
her
egi
onbet
weent
wogl
asspl
ateswi
thami
xtur
eof
gasest
hatusual
l
yincl
udesneon.
Aser
iesofv
ert
ical
conduct
ingr
ibbonsi
spl
acedononegl
asspanel
andasetof
hor
izont
alr
ibboni
sbui
l
tint
otheot
hergl
asspanel
.

Fi
ri
ngv
olt
agei
sappl
i
edt
oapai
rofhor
izont
alandv
ert
icalconduct
orscauset
he
gasatt
hei
nter
sect
ionoft
het
woconduct
orst
obr
eakdowni
ntogl
owi
ngpl
asma
ofel
ect
ronsandi
ons.
Pi
ctur
edef
ini
ti
oni
sst
oredi
nar
efr
eshbuf
ferandt
hef
ir
ingv
olt
agesar
eappl
i
edt
o
r
efr
esht
hepi
xel
posi
ti
ons,
60t
imespersecond.

DEPARTMENTOFCSE,
BRCE 19
COMPUTERGRAPHI
CSANDVI
SUALI
ZATI
ON(
18CS62)

Al
ter
nat
ingcur
rentmet
hodsar
eusedt
opr
ovi
def
ast
erappl
i
cat
ionoff
ir
ing
v
olt
agesandt
husbr
ight
erdi
spl
ays.
Separ
ati
onbet
weenpi
xel
sispr
ovi
dedbyt
heel
ect
ri
cfi
eldofconduct
or.
Onedi
sadv
ant
ageofpl
asmapanel
sist
heywer
est
ri
ctl
ymonochr
omat
icdev
icet
hat
meansshowsonl
yonecol
orot
hert
hanbl
ackl
i
kebl
ackandwhi
te.

b) Thi
nFi
lm El
ect
rol
umi
nescentDi
spl
ays
I
tissi
mil
art
opl
asmapanel
displ
aybutr
egi
onbet
weent
hegl
asspl
atesi
sfi
l
ledwi
th
phosphor
ssuchasdopedwi
thmagnesi
um i
nst
eadofgas.
Whensuf
fi
cientv
olt
agei
sappl
i
edt
hephosphor
sbecomesaconduct
ori
nar
eaof
i
nter
sect
ionoft
het
woel
ect
rodes.
El
ect
ri
cal
ener
gyi
sthenabsor
bedbyt
hemanganeseat
omswhi
cht
henr
eleaset
he
ener
gyasaspotofl
i
ghtsi
mil
art
othegl
owi
ngpl
asmaef
fecti
npl
asmapanel
.
I
trequi
resmor
epowert
hanpl
asmapanel
.
I
nthi
sgoodcol
orandgr
ayscal
edi
ff
icul
ttoachi
eve.

c.Li
ghtEmi
tt
ingDi
ode(
LED)
I
nthi
sdi
spl
ayamat
ri
xofmul
ti
-col
orl
i
ghtemi
tt
ingdi
odei
sar
rangedt
ofor
mthe
pi
xel
posi
ti
oni
nthedi
spl
ayandt
hepi
ctur
edef
ini
ti
oni
sst
oredi
nref
reshbuf
fer
.
Si
mil
art
oscanl
i
ner
efr
eshi
ngofCRTi
nfor
mat
ioni
sreadf
rom t
her
efr
eshbuf
fer
andconv
ert
edt
ovol
tagel
evel
sthatar
eappl
i
edt
othedi
odest
opr
oducet
hel
i
ght
pat
ter
nont
hedi
spl
ay.

DEPARTMENTOFCSE,
BRCE 20
COMPUTERGRAPHI
CSANDVI
SUALI
ZATI
ON(
18CS62)

d)
Liqui
dCr
yst
alDi
spl
ay(
LCD)
Thi
snonemi
ssi
vedev
icepr
oducepi
ctur
ebypassi
ngpol
ari
zedl
i
ghtf
rom t
he
sur
roundi
ngorf
rom ani
nter
nall
i
ghtsour
cet
hroughl
i
qui
dcr
yst
almat
eri
alt
hat
canbeal
i
gnedt
oei
therbl
ockort
ransmi
tthel
i
ght
.
The l
i
qui
d cr
yst
alr
efr
eshes t
ofactt
hatt
hese compounds hav
e cr
yst
all
i
ne
ar
rangementofmol
ecul
est
henal
sof
lowsl
i
kel
i
qui
d.
I
tconsi
stsoft
wogl
asspl
ateseachwi
thl
i
ghtpol
ari
zeratr
ightangl
est
oeachot
her
sandwi
cht
hel
i
qui
dcr
yst
almat
eri
albet
weent
hepl
ates.
Rowsofhor
izont
alt
ranspar
entconduct
orsar
ebui
l
tint
oonegl
asspl
ate,and
col
umnofv
ert
ical
conduct
orsar
eputi
ntot
heot
herpl
ates.
Thei
nter
sect
ionoft
woconduct
orsdef
inesapi
xel
posi
ti
on.
I
ntheONst
atepol
ari
zedl
i
ghtpassi
ngt
hroughmat
eri
ali
stwi
stedsot
hati
twi
l
l
passt
hrought
heopposi
tepol
ari
zer
.
I
ntheOFFst
atei
twi
l
lref
lectbackt
owar
dssour
ce.

Thr
ee-Di
mensi
onalVi
ewi
ngDevi
ces
Gr
aphi
csmoni
tor
sfort
hedi
spl
ayoft
hree-
dimensi
onalsceneshav
ebeendev
ised
usi
ngat
echni
quet
hatr
efl
ect
saCRTi
magef
rom av
ibr
ati
ng,f
lexi
blemi
rr
orAs
t
hev
ari
focal
mir
rorv
ibr
ates,
itchangesf
ocal
lengt
h.

DEPARTMENTOFCSE,
BRCE 21
COMPUTERGRAPHI
CSANDVI
SUALI
ZATI
ON(
18CS62)

Thesev
ibr
ati
onsar
esy
nchr
oni
zedwi
tht
hedi
spl
ayofanobj
ectonaCRTsot
hat
eachpoi
ntont
heobj
ecti
sref
lect
edf
rom t
hemi
rr
ori
ntoaspat
ialposi
ti
on
cor
respondi
ngt
othedi
stanceoft
hatpoi
ntf
rom aspeci
fi
edv
iewi
ngl
ocat
ion.
Thi
sal
l
owsust
owal
kar
oundanobj
ectorsceneandv
iewi
tfr
om di
ff
erentsi
des.

1.
4Rast
er-
ScanSy
stems
I
nter
act
iver
ast
er-
graphi
cssy
stemst
ypi
cal
l
yempl
oysev
eral
processi
nguni
ts.
 I
naddi
ti
ont
othecent
ralpr
ocessi
nguni
t(CPU)
,aspeci
al-
pur
posepr
ocessor
,
cal
l
edt
hev
ideocont
rol
l
erordi
spl
aycont
rol
l
er,
isusedt
ocont
rolt
heoper
ati
onof
t
hedi
spl
aydev
ice.
 Or
gani
zat
ionofasi
mpl
erast
ersy
stem i
sshowni
nbel
owFi
gur
e.

 Her
e,t
hef
ramebuf
fercanbeany
wher
eint
hesy
stem memor
y,andt
hev
ideo
cont
rol
l
eraccessest
hef
ramebuf
fert
oref
resht
hescr
een.

DEPARTMENTOFCSE,
BRCE 22
COMPUTERGRAPHI
CSANDVI
SUALI
ZATI
ON(
18CS62)

I
naddi
ti
ont
othev
ideocont
rol
l
er,
rast
ersy
stemsempl
oyot
herpr
ocessor
sas
copr
ocessor
sandaccel
erat
orst
oimpl
ementv
ari
ousgr
aphi
csoper
ati
ons.

1.
4.1Vi
deocont
rol
ler
:
 Thef
igur
ebel
owshowsacommonl
yusedor
gani
zat
ionf
orr
ast
ersy
stems.
 Af
ixedar
eaoft
hesy
stem memor
yisr
eser
vedf
ort
hef
ramebuf
fer
,andt
he
v
ideocont
rol
l
eri
sgi
vendi
rectaccesst
othef
rame-
buf
fermemor
y.
 Fr
ame-
buf
ferl
ocat
ions,
andt
hecor
respondi
ngscr
eenposi
ti
ons,
arer
efer
enced
i
ntheCar
tesi
ancoor
dinat
es.

Car
tesi
anr
efer
encef
rame:
 Fr
ame-
buf
ferl
ocat
ionsandt
hecor
respondi
ngscr
eenposi
ti
ons,
arer
efer
encedi
n
Car
tesi
ancoor
dinat
es.
 I
n an appl
i
cat
ion (
user
)pr
ogr
am,weuset
hecommandswi
thi
n a gr
aphi
cs
sof
twar
epackaget
osetcoor
dinat
eposi
ti
onsf
ordi
spl
ayedobj
ect
srel
ati
vet
othe
or
igi
noft
he
 Thecoor
dinat
eor
igi
nisr
efer
encedatt
hel
ower
-l
eftcor
nerofascr
eendi
spl
ay
ar
eabyt
hesof
twar
ecommands,al
thoughwecant
ypi
cal
l
ysett
heor
igi
natany
conv
eni
entl
ocat
ionf
orapar
ti
cul
arappl
i
cat
ion.

DEPARTMENTOFCSE,
BRCE 23
COMPUTERGRAPHI
CSANDVI
SUALI
ZATI
ON(
18CS62)

Wor
king:
 Fi
gur
eshowsat
wo-
dimensi
onal
Car
tesi
anr
efer
encef
ramewi
tht
heor
igi
natt
he
l
ower
lef
tscr
eencor
ner
.

 The scr
een sur
face i
sthen r
epr
esent
ed as t
he f
ir
stquadr
antofa t
wo-
di
mensi
onalsy
stem wi
thposi
ti
vexandyv
aluesi
ncr
easi
ngf
rom l
eftt
ori
ghtand
bot
tom oft
hescr
eent
othet
opr
espect
ivel
y.
 Pi
xelposi
ti
onsar
ethenassi
gnedi
ntegerxv
aluest
hatr
angef
rom 0t
oxmax
acr
osst
hescr
een,l
eftt
ori
ght
,andi
ntegeryv
aluest
hatv
aryf
rom 0t
oymax,
bot
tom t
otop.

Basi
cVi
deoCont
rol
lerRef
reshOper
ati
ons
 Thebasi
cref
reshoper
ati
onsoft
hev
ideocont
rol
l
erar
edi
agr
ammed

 Twor
egi
ster
sar
eusedt
ost
oret
hecoor
dinat
eval
uesf
ort
hescr
eenpi
xel
s.

DEPARTMENTOFCSE,
BRCE 24
COMPUTERGRAPHI
CSANDVI
SUALI
ZATI
ON(
18CS62)

 I
nit
ial
l
y,t
hexr
egi
steri
ssett
o0andt
heyr
egi
steri
ssett
othev
aluef
ort
het
opscan
l
i
ne.
 Thecont
ent
soft
hef
ramebuf
feratt
hispi
xel
posi
ti
onar
ethenr
etr
iev
edandused
t
osett
hei
ntensi
tyoft
heCRTbeam.
 Thent
hexr
egi
steri
sincr
ement
edby1,andt
hepr
ocessi
srepeat
edf
ort
henext
pi
xel
ont
het
opscanl
i
ne.
 Thi
spr
ocedur
econt
inuesf
oreachpi
xel
alongt
het
opscanl
i
ne.
 Af
tert
hel
astpi
xel
ont
het
opscanl
i
nehasbeenpr
ocessed,
thexr
egi
steri
sreset
t
o0andt
heyr
egi
steri
ssett
othev
aluef
ort
henextscanl
i
nedownf
rom t
het
op
oft
hescr
een.
 Thepr
ocedur
eisr
epeat
edf
oreachsuccessi
vescanl
i
ne.
 Af
tercy
cli
ngt
hroughal
lpi
xel
sal
ongt
hebot
tom scanl
i
ne,t
hev
ideocont
rol
l
er
r
eset
sther
egi
ster
stot
hef
ir
stpi
xelposi
ti
onont
het
opscanl
i
neandt
her
efr
esh
pr
ocessst
art
sov
er
a.
Speeduppi
xelposi
ti
onpr
ocessi
ngofv
ideocont
rol
ler
:
 Si
ncet
hescr
eenmustber
efr
eshedatar
ateofatl
east60f
ramespersecond,
the
si
mpl
epr
ocedur
eil
l
ust
rat
edi
nabov
efi
gur
emaynotbeaccommodat
edbyRAM
chi
psi
fthecy
clet
imei
stoosl
ow.
 Tospeeduppi
xelpr
ocessi
ng,v
ideocont
rol
l
erscanr
etr
iev
emul
ti
plepi
xelv
alues
f
rom t
her
efr
eshbuf
feroneachpass.
 Whengr
oupofpi
xel
shasbeenpr
ocessed,t
henextbl
ockofpi
xelv
aluesi
s
r
etr
iev
edf
rom t
hef
ramebuf
fer
.
Adv
ant
agesofv
ideocont
rol
ler
:
 Av
ideocont
rol
l
ercanbedesi
gnedt
oper
for
m anumberofot
heroper
ati
ons.
 Forv
ari
ousappl
i
cat
ions,
thev
ideocont
rol
l
ercanr
etr
iev
epi
xel
val
uesf
rom
di
ff
erentmemor
yar
easondi
ff
erentr
efr
eshcy
cles.
 Thi
spr
ovi
desaf
astmechani
sm f
orgener
ati
ngr
eal
-t
imeani
mat
ions.
 Anot
herv
ideo-
cont
rol
l
ert
aski
sthet
ransf
ormat
ionofbl
ocksofpi
xel
s,sot
hat
scr
eenar
eascanbeenl
arged,r
educed,ormov
edf
rom onel
ocat
iont
oanot
her
dur
ingt
her
efr
eshcy
cles.
 I
naddi
ti
on,
thev
ideocont
rol
l
erof
tencont
ainsal
ookupt
abl
e,sot
hatpi
xelv
alues
i
nthef
ramebuf
ferar
eusedt
oaccesst
hel
ookupt
abl
e.Thi
spr
ovi
desaf
ast
met
hodf
orchangi
ngscr
eeni
ntensi
tyv
alues.
DEPARTMENTOFCSE,
BRCE 25
COMPUTERGRAPHI
CSANDVI
SUALI
ZATI
ON(
18CS62)

 Fi
nal
l
y,somesy
stemsar
edesi
gnedt
oal
l
ow t
hev
ideocont
rol
l
ert
omi
xthe
f
ramebuf
feri
magewi
thani
nputi
magef
rom at
elev
isi
oncamer
aorot
heri
nput
dev
ice

b)Rast
er-
ScanDi
spl
ayPr
ocessor
 Fi
gur
eshowsonewayt
oor
gani
zet
hecomponent
sofar
ast
ersy
stem t
hat
cont
ainsasepar
atedi
spl
aypr
ocessor
,somet
imesr
efer
redt
oasagr
aphi
cs
cont
rol
l
eroradi
spl
aycopr
ocessor
.

 Thepur
poseoft
hedi
spl
aypr
ocessori
stof
reet
heCPUf
rom t
hegr
aphi
cschor
es.
 I
naddi
ti
ont
othesy
stem memor
y,asepar
atedi
spl
ay-
processormemor
yar
ea
canbepr
ovi
ded.
Scanconver
sion:
 Amaj
ort
askoft
hedi
spl
aypr
ocessori
sdi
git
izi
ngapi
ctur
edef
ini
ti
ongi
veni
nan
appl
i
cat
ionpr
ogr
am i
ntoasetofpi
xel
val
uesf
orst
oragei
nthef
ramebuf
fer
.
 Thi
sdi
git
izat
ionpr
ocessi
scal
l
edscanconv
ersi
on.
Exampl
e1:di
spl
ayi
ngal
ine
 Gr
aphi
cscommandsspeci
fyi
ngst
rai
ghtl
i
nesandot
hergeomet
ri
cobj
ect
sar
e
scanconv
ert
edi
ntoasetofdi
scr
etepoi
nts,
cor
respondi
ngt
oscr
eenpi
xel
posi
ti
ons.

DEPARTMENTOFCSE,
BRCE 26
COMPUTERGRAPHI
CSANDVI
SUALI
ZATI
ON(
18CS62)

 Scanconv
ert
ingast
rai
ght
-l
inesegment
.

DEPARTMENTOFCSE,
BRCE 27
COMPUTERGRAPHI
CSANDVI
SUALI
ZATI
ON(
18CS62)

Exampl
e2:di
spl
ayi
ngachar
act
er
 Char
act
erscanbedef
inedwi
thr
ect
angul
arpi
xel
gri
ds
 Thear
raysi
zef
orchar
act
ergr
idscanv
aryf
rom about5by7t
o9by12ormor
e
f
orhi
gher
-qual
i
tydi
spl
ays.
 Achar
act
ergr
idi
sdi
spl
ayedbysuper
imposi
ngt
her
ect
angul
argr
idpat
ter
nint
othe
f
ramebuf
ferataspeci
fi
edcoor
dinat
eposi
ti
on.

Usi
ngout
li
ne:
 Forchar
act
erst
hatar
edef
inedasout
li
nes,
theshapesar
escan-
conv
ert
edi
nto
t
hef
ramebuf
ferbyl
ocat
ingt
hepi
xel
posi
ti
onscl
osestt
otheout
li
ne.

Addi
ti
onaloper
ati
onsofDi
spl
aypr
ocessor
s:
 Di
spl
aypr
ocessor
sar
eal
sodesi
gnedt
oper
for
m anumberofaddi
ti
onal
oper
ati
ons.
 Thesef
unct
ionsi
ncl
udegener
ati
ngv
ari
ousl
i
nest
yles(
dashed,
dot
ted,
orsol
i
d),
di
spl
ayi
ngcol
orar
eas,
andappl
yi
ngt
ransf
ormat
ionst
otheobj
ect
sinascene.
 Di
spl
aypr
ocessor
sar
ety
pical
l
ydesi
gnedt
oint
erf
acewi
thi
nter
act
ivei
nput
dev
ices,
suchasamouse.

Met
hodst
oreducememor
yrequi
rement
sindi
spl
aypr
ocessor
:
I
nanef
for
ttor
educememor
yrequi
rement
sinr
ast
ersy
stems,
met
hodshav
e
beendev
isedf
oror
gani
zi
ngt
hef
ramebuf
ferasal
i
nkedl
i
standencodi
ngt
he
col
ori
nfor
mat
ion.
 Oneor
gani
zat
ionschemei
stost
oreeachscanl
i
neasasetofnumberpai
rs.

DEPARTMENTOFCSE,
BRCE 28
COMPUTERGRAPHI
CSANDVI
SUALI
ZATI
ON(
18CS62)

 Encodi
ngmet
hodscanbeusef
uli
nthedi
git
alst
orageandt
ransmi
ssi
onof
pi
ctur
einf
ormat
ion
i
)Run-
lengt
hencodi
ng:
Thef
ir
stnumberi
neachpai
rcanbear
efer
encet
oacol
orv
alue,andt
hesecond
numbercanspeci
fyt
henumberofadj
acentpi
xel
sont
hescanl
i
net
hatar
etobe
di
spl
ayedi
nthatcol
or.
Thi
stechni
que,cal
l
edr
un-
lengt
hencodi
ng,canr
esul
tinaconsi
der
abl
esav
ingi
n
st
oragespacei
fapi
ctur
eist
obeconst
ruct
edmost
lywi
thl
ongr
unsofasi
ngl
e
col
oreach.
Asi
mil
arappr
oachcanbet
akenwhenpi
xel
col
orschangel
i
near
ly.
i
i)Cel
lencodi
ng:
Anot
herappr
oachi
stoencodet
her
ast
erasasetofr
ect
angul
arar
eas(
cel
lencodi
ng)
.

Di
sadv
ant
agesofencodi
ng:
 Thedi
sadv
ant
agesofencodi
ngr
unsar
ethatcol
orchangesar
edi
ff
icul
ttor
ecor
d
andst
orager
equi
rement
sincr
easeast
hel
engt
hsoft
her
unsdecr
ease.
 I
naddi
ti
on,
iti
sdi
ff
icul
tfort
hedi
spl
aycont
rol
l
ert
opr
ocesst
her
ast
erwhen
manyshor
trunsar
einv
olv
ed.
 Mor
eov
er,
thesi
zeoft
hef
ramebuf
feri
snol
ongeramaj
orconcer
n,becauseof
shar
pdecl
i
nesi
nmemor
ycost
s

1.
4.3Gr
aphi
cswor
kst
ati
onsandvi
ewi
ngsy
stems
 Mostgr
aphi
csmoni
tor
stodayoper
ateasr
ast
er-
scandi
spl
ays,
andbot
hCRTand
f
latpanel
syst
emsar
eincommonuse.
 Gr
aphi
cswor
kst
ati
onr
angef
rom smal
lgener
al-
pur
posecomput
ersy
stemst
o
mul
timoni
torf
aci
l
iti
es,
oft
enwi
thul
tr
a–l
argev
iewi
ngscr
eens.
 Hi
gh-
def
ini
ti
ongr
aphi
cssy
stems,
wit
hresol
uti
onsupt
o2560by2048,
are
commonl
yusedi
nmedi
cal
imagi
ng,
air
-t
raf
fi
ccont
rol
,si
mul
ati
on,
andCAD.
 Manyhi
gh-
endgr
aphi
cswor
kst
ati
onsal
soi
ncl
udel
argev
iewi
ngscr
eens,
oft
en
wi
thspeci
ali
zedf
eat
ures.

DEPARTMENTOFCSE,
BRCE 29
COMPUTERGRAPHI
CSANDVI
SUALI
ZATI
ON(
18CS62)

 Mul
ti
-panel
displ
ayscr
eensar
eusedi
nav
ari
etyofappl
i
cat
ionst
hatr
equi
re“
wal
l
-
si
zed”v
iewi
ng ar
eas.These sy
stems ar
e desi
gned f
orpr
esent
ing gr
aphi
cs
di
spl
aysatmeet
ings,
conf
erences,
conv
ent
ions,
tradeshows,
ret
ail
stor
eset
c.
 Amul
ti
-paneldi
spl
aycanbeusedt
oshow al
argev
iew ofasi
ngl
esceneor
sev
erali
ndi
vi
duali
mages.Eachpaneli
nthesy
stem di
spl
aysonesect
ionoft
he
ov
eral
lpi
ctur
e
 Al
arge,cur
ved-
scr
eensy
stem canbeusef
ulf
orv
iewi
ngbyagr
oupofpeopl
e
st
udy
ingapar
ti
cul
argr
aphi
csappl
i
cat
ion.
 A360degr
eepanel
edv
iewi
ngsy
stem i
ntheNASAcont
rol
-t
owersi
mul
ator
,whi
ch
i
susedf
ort
rai
ningandf
ort
est
ingway
stosol
veai
r-
tr
aff
icandr
unwaypr
obl
ems
atai
rpor
ts.

1.
5InputDev
ices
 Gr
aphi
cswor
kst
ati
onsmakeuseofv
ari
ousdev
icesf
ordat
ainput
.Mostsy
stems
hav
e key
boar
ds and mouses,
whi
l
e some ot
her sy
stems hav
e
t
rackbal
l
,spacebal
l
,j
oyst
ick,
but
tonboxes,
touchpanel
s,
imagescanner
sandv
oice
sy
stems.
Key
boar
d:
 Key
boar
dongr
aphi
cssy
stem i
susedf
orent
eri
ngt
extst
ri
ngs,
i
ssui
ngcer
tai
n
commandsandsel
ect
ingmenuopt
ions.
 Key
boar
dscanal
sobepr
ovi
dedwi
thf
eat
uresf
orent
ryofscr
een
coor
dinat
es,
menusel
ect
ionsorgr
aphi
csf
unct
ions.
 Gener
alpur
posekey
boar
dusesf
unct
ionkey
sandcur
sor
-cont
rol
key
s.
 Funct
ionkey
sal
l
owusert
osel
ectf
requent
lyaccessedoper
ati
onswi
thasi
ngl
e
key
str
oke.
Cur
sor
-cont
rolkey
sar
eusedf
orsel
ect
ingadi
spl
ayedobj
ectora
l
ocat
ionbyposi
ti
oni
ngt
hescr
eencur
sor
.

But
tonBoxesandDi
als:
 But
tonsar
eof
tenusedt
oinputpr
edef
inedf
unct
ions.
Dial
sar
ecommondev
ices
f
orent
eri
ngscal
arv
alues.
 Numerical
val
ueswi
thi
nsomedef
inedr
angear
esel
ect
edf
ori
nputwi
thdi
al
r
otat
ions.

DEPARTMENTOFCSE,
BRCE 30
COMPUTERGRAPHI
CSANDVI
SUALI
ZATI
ON(
18CS62)

MouseDevi
ces:
 Mousei
sahand-
hel
ddev
ice,
usual
l
ymov
edar
oundonaf
latsur
facet
oposi
ti
on
t
hescr
eencur
sor
.wheel
erorr
ool
ersont
hebot
tom oft
hemouseusedt
orecor
d
t
heamountanddi
rect
ionofmov
ement
.
 Someoft
hemousesusesopt
icalsensor
s,whi
chdet
ect
smov
ementacr
osst
he
hor
izont
alandv
ert
ical
gri
dli
nes.
 Si
nceamousecanbepi
ckedupandputdown,
i
tisusedf
ormaki
ngr
elat
ive
changesi
ntheposi
ti
onoft
hescr
een.
 Mostgener
alpur
posegr
aphi
cssy
stemsnowi
ncl
udeamouseandakey
boar
das
t
hepr
imar
yinputdev
ices.

Tr
ackbal
lsandSpacebal
ls:
 At
rackbal
li
sabal
ldev
icet
hatcanber
otat
edwi
tht
hef
inger
sorpal
m oft
he
handt
opr
oducescr
eencur
sormov
ement
.
 Lapt
opkey
boar
dsar
eequi
ppedwi
that
rackbal
ltoel
i
minat
etheext
raspace
r
equi
redbyamouse.
 Spacebal
li
sanext
ensi
onoft
wo-
dimensi
onal
trackbal
lconcept
.
 Spacebal
l
sar
eusedf
ort
hree-
dimensi
onal
posi
ti
oni
ngandsel
ect
ionoper
ati
ons
i
nvi
rt
ual
-real
i
tysy
stems,
model
i
ng,
ani
mat
ion,
CADandot
herappl
i
cat
ions.

Joy
sti
cks:
 Joy
sti
cki
susedasaposi
ti
oni
ngdev
ice,
whi
chusesasmal
lver
ti
call
ever
(st
ick)
moundedonabase.
Iti
susedt
ost
eert
hescr
eencur
sorar
oundandsel
ect
scr
eenposi
ti
onwi
tht
hest
ickmov
ement
.
 Apushorpul
lont
hest
icki
smeasur
edwi
thst
rai
ngaugesandconv
ert
edt
o
mov
ementoft
hescr
eencur
sori
nthedi
rect
ionoft
heappl
i
edpr
essur
e.

Dat
aGl
oves:
 Dat
agl
ovecanbeusedt
ogr
aspav
irt
ual
obj
ect
.Thegl
ovei
sconst
ruct
edwi
tha
ser
iesofsensor
sthatdet
ecthandandf
ingermot
ions.
 I
nputf
rom t
hegl
ovei
susedt
oposi
ti
onormani
pul
ateobj
ect
sinav
irt
ual
scene.

DEPARTMENTOFCSE,
BRCE 31
COMPUTERGRAPHI
CSANDVI
SUALI
ZATI
ON(
18CS62)

Di
git
izer
s:
 Di
git
izeri
sacommondev
icef
ordr
awi
ng,
pai
nti
ngorsel
ect
ingposi
ti
ons.
 Gr
aphi
cst
abl
eti
sonet
ypeofdi
git
izer
,whi
chi
susedt
oinput2-
dimensi
onal
coor
dinat
esbyact
ivat
ingahandcur
sororst
ylusatsel
ect
edposi
ti
onsonaf
lat
sur
face.
 Ahandcur
sorcont
ainscr
osshai
rsf
orsi
ght
ingposi
ti
onsandst
ylusi
sapenci
l
-
shapeddev
icet
hati
spoi
ntedatposi
ti
onsont
het
abl
et.

I
mageScanner
s:
 Dr
awi
ngs,
graphs,
phot
ogr
aphsort
extcanbest
oredf
orcomput
erpr
ocessi
ngwi
th
an i
mage scannerby passi
ng an opt
icalscanni
ng mechani
sm ov
ert
he
i
nfor
mat
iont
obest
ored.
 Oncewehav
ether
epr
esent
ati
onoft
hepi
ctur
e,t
henwecanappl
yvar
iousi
mage-
pr
ocessi
ng met
hod t
o modi
fyt
her
epr
esent
ati
on oft
hepi
ctur
eand v
ari
ous
edi
ti
ngoper
ati
onscanbeper
for
medont
hest
oreddocument
s.

TouchPanel
s:
 Touchpanel
sal
l
owdi
spl
ayedobj
ect
sorscr
eenposi
ti
onst
obesel
ect
edwi
tht
he
t
ouchofaf
inger
.
 Touchpanel
isusedf
ort
hesel
ect
ionofpr
ocessi
ngopt
ionst
hatar
erepr
esent
ed
asamenuofgr
aphi
cal
icons.
 Opt
ical
touchpanel
-usesLEDsal
ongonev
ert
ical
andhor
izont
aledgeoft
hef
rame.
 Acoust
ical
touchpanel
sgener
ateshi
gh-
fr
equencysoundwav
esi
nhor
izont
aland
v
ert
ical
dir
ect
ionsacr
ossagl
asspl
ate.

Li
ghtPens:
 Li
ghtpensar
epenci
l
-shapeddev
icesusedt
osel
ectposi
ti
onsbydet
ect
ingt
he
l
i
ghtcomi
ngf
rom poi
ntsont
heCRTscr
een.
 Tosel
ectposi
ti
onsi
nanyscr
eenar
eawi
thal
i
ghtpen,
wemusthav
esome
nonzer
oli
ghti
ntensi
tyemi
tt
edf
rom eachpi
xel
wit
hint
hatar
ea.
 Li
ghtpenssomet
imesgi
vef
alser
eadi
ngsduet
obackgr
oundl
i
ght
ingi
nar
oom.

DEPARTMENTOFCSE,
BRCE 32
COMPUTERGRAPHI
CSANDVI
SUALI
ZATI
ON(
18CS62)

Voi
ceSy
stems:
 Speechr
ecogni
zer
sar
eusedwi
thsomegr
aphi
cswor
kst
ati
onsasi
nputdev
ices
f
orv
oicecommands.
Thev
oicesy
stem i
nputcanbeusedt
oini
ti
ateoper
ati
onsor
t
oent
erdat
a.
 Adi
cti
onar
yissetupbyspeaki
ngcommandwor
dssev
eral
times,
thent
he
sy
stem anal
yseseachwor
dandmat
cheswi
tht
hev
oicecommandt
omat
cht
he
pat
ter
n

1.
6Gr
aphi
csNet
wor
ks
 Sof
ar,
wehav
emai
nlyconsi
der
edgr
aphi
csappl
i
cat
ionsonani
sol
atedsy
stem wi
th
asi
ngl
euser
.
 Mul
ti
userenv
ironment
s&comput
ernet
wor
ksar
enowcommonel
ement
sin
manygr
aphi
csappl
i
cat
ions.
 Var
iousr
esour
ces,
suchaspr
ocessor
s,pr
int
ers,
plot
ter
sanddat
afi
l
escanbe
di
str
ibut
edonanet
wor
k&shar
edbymul
ti
pleuser
s.
 Agr
aphi
csmoni
toronanet
wor
kisgener
all
yref
err
edt
oasagr
aphi
csser
ver
.
 Thecomput
eronanet
wor
kthati
sexecut
ingagr
aphi
csappl
i
cat
ioni
scal
l
edt
he
cl
i
ent.
 Awor
kst
ati
ont
hati
ncl
udespr
ocessor
s,aswel
lasamoni
torandi
nputdev
ices
canf
unct
ionasbot
haser
verandacl
i
ent
.

1.
7Gr
aphi
csonI
nter
net
 Agr
eatdeal
ofgr
aphi
csdev
elopmenti
snowdoneont
heI
nter
net
.
 Comput
ersont
heI
nter
netcommuni
cat
eusi
ngTCP/
IP.
 Resour
cessuchasgr
aphi
csf
il
esar
eident
if
iedbyURL(
Uni
for
mresour
cel
ocat
or)
.
 TheWor
ldWi
deWebpr
ovi
desahy
per
textsy
stem t
hatal
l
owsuser
stol
oacat
e
andv
iewdocument
s,audi
oandgr
aphi
cs.
 EachURLsomet
imesal
socal
l
edasuni
ver
sal
resour
cel
ocat
or.
 TheURLcont
ainst
wopar
tsPr
otocol
-fort
ransf
err
ingt
hedocument
,andSer
ver
-
cont
ainst
hedocument
.

1.
8Gr
aphi
csSof
twar
e

DEPARTMENTOFCSE,
BRCE 33
COMPUTERGRAPHI
CSANDVI
SUALI
ZATI
ON(
18CS62)

 Ther
ear
etwobr
oadcl
assi
fi
cat
ionsf
orcomput
er-
graphi
cssof
twar
e

DEPARTMENTOFCSE,
BRCE 34
COMPUTERGRAPHI
CSANDVI
SUALI
ZATI
ON(
18CS62)

1.Speci
al-
pur
pose packages:Speci
al-
pur
pose packages ar
e desi
gned f
or
nonpr
ogr
ammer
s
Exampl
e:gener
ate pi
ctur
es,gr
aphs,char
ts,pai
nti
ng pr
ogr
ams orCAD
sy
stems i
n some appl
i
cat
ion ar
ea wi
thoutwor
ryi
ng aboutt
he gr
aphi
cs
pr
ocedur
e
2. Gener
alpr
ogr
ammi
ngpackages:gener
alpr
ogr
ammi
ngpackagepr
ovi
desa
l
i
brar
yofgr
aphi
csf
unct
ionst
hatcanbeusedi
napr
ogr
ammi
ngl
anguage
suchasC,
C++,
Jav
a,orFORTRAN.
Exampl
e:GL (
Graphi
cs Li
brar
y),OpenGL,VRML (
Vir
tual
-Real
i
tyModel
i
ng
Language)
,Jav
a2DAndJav
a3D

NOTE:Asetofgr
aphi
csf
unct
ionsi
sof
tencal
ledacomput
er-
graphi
csappl
icat
ion
pr
ogr
ammi
ngi
nter
face(
CGAPI
)

1.
10Coor
dinat
eRepr
esent
ati
ons
 Togener
ateapi
ctur
eusi
ngapr
ogr
ammi
ngpackagewef
ir
stneedt
ogi
vet
he
geomet
ri
cdescr
ipt
ionsoft
heobj
ect
sthatar
etobedi
spl
ayedknownas
coor
dinat
es.
 I
fcoor
dinat
eval
uesf
orapi
ctur
ear
egi
veni
nsomeot
herr
efer
encef
rame
(
spher
ical
,hy
per
bol
i
c,et
c.)
,theymustbeconv
ert
edt
oCar
tesi
ancoor
dinat
es.
 Sev
eral
dif
fer
entCar
tesi
anr
efer
encef
ramesar
eusedi
nthepr
ocessof
const
ruct
inganddi
spl
ayi
ng
 Fi
rstwedef
inet
heshapesofi
ndi
vi
dual
obj
ect
s,suchast
reesorf
urni
tur
e,These
r
efer
encef
ramesar
ecal
l
edmodel
i
ngcoor
dinat
esorl
ocal
coor
dinat
es
 Thenwepl
acet
heobj
ect
sint
oappr
opr
iat
elocat
ionswi
thi
nascener
efer
ence
f
ramecal
l
edwor
ldcoor
dinat
es.
 Af
teral
lpar
tsofascenehav
ebeenspeci
fi
ed,
iti
spr
ocessedt
hroughv
ari
ous
out
put
-dev
icer
efer
encef
ramesf
ordi
spl
ay.Thi
spr
ocessi
scal
l
edt
hev
iewi
ng
pi
pel
i
ne.
 Thescenei
sthenst
oredi
nnor
mal
i
zedcoor
dinat
es.Whi
chr
angef
rom −1t
o1or
fr
om 0
t
o1Nor
mal
i
zedcoor
dinat
esar
eal
sor
efer
redt
oasnor
mal
i
zeddev
icecoor
dinat
es.

DEPARTMENTOFCSE,
BRCE 35
COMPUTERGRAPHI
CSANDVI
SUALI
ZATI
ON(
18CS62)

 Thecoor
dinat
esy
stemsf
ordi
spl
aydev
icesar
egener
all
ycal
l
eddev
ice
coor
dinat
es,
orscr
eencoor
dinat
es.
NOTE:Geomet
ri
cdescr
ipt
ionsi
nmodel
ingcoor
dinat
esandwor
ldcoor
dinat
escanbe
gi
venin

DEPARTMENTOFCSE,
BRCE 36
COMPUTERGRAPHI
CSANDVI
SUALI
ZATI
ON(
18CS62)

f
loat
ing-
poi
ntori
ntegerval
ues.
 Exampl
e:Fi
gur
ebr
ief
lyi
l
lust
rat
est
hesequenceofcoor
dinat
etr
ansf
ormat
ions
f
rom model
i
ngcoor
dinat
est
odev
icecoor
dinat
esf
oradi
spl
ay

1.
11Gr
aphi
csFunct
ions
I
tpr
ovi
desuser
swi
thav
ari
etyoff
unct
ionsf
orcr
eat
ingandmani
pul
ati
ngpi
ctur
es
 Thebasi
cbui
l
dingbl
ocksf
orpi
ctur
esar
eref
err
edt
oasgr
aphi
csout
putpr
imi
ti
ves
 At
tri
but
esar
epr
oper
ti
esoft
heout
putpr
imi
ti
ves
 Wecanchanget
hesi
ze,
posi
ti
on,
oror
ient
ati
onofanobj
ectusi
nggeomet
ri
c
t
ransf
ormat
ions
 Model
i
ngt
ransf
ormat
ions,
whi
char
eusedt
oconst
ructascene.
 Vi
ewi
ngt
ransf
ormat
ionsar
eusedt
osel
ectav
iewoft
hescene,
thet
ypeof
pr
oject
iont
obeusedandt
hel
ocat
ionwher
ethev
iewi
stobedi
spl
ayed.
I
nputf
unct
ionsar
eusedt
ocont
rol
andpr
ocesst
hedat
afl
owf
rom t
hese
i
nter
act
ivedev
ices(
mouse,
tabl
etandj
oyst
ick)
 Gr
aphi
cspackagecont
ainsanumberoft
asks.
Wecanl
umpt
hef
unct
ionsf
or
car
ryi
ngoutmanyt
asksbyundert
heheadi
ngcont
rol
oper
ati
ons.

Sof
twar
eSt
andar
ds
 Thepr
imar
ygoal
ofst
andar
dizedgr
aphi
cssof
twar
eispor
tabi
l
ity
.

DEPARTMENTOFCSE,
BRCE 37
COMPUTERGRAPHI
CSANDVI
SUALI
ZATI
ON(
18CS62)

 I
n1984,
Graphi
cal
Ker
nel
Syst
em (
GKS)wasadopt
edast
hef
ir
stgr
aphi
cs
sof
twar
est
andar
dbyt
heI
nter
nat
ional
Standar
dsOr
gani
zat
ion(
ISO)
 Thesecondsof
twar
est
andar
dtobedev
elopedandappr
ovedbyt
hest
andar
ds
or
gani
zat
ionswasPr
ogr
ammer
’sHi
erar
chi
cal
Int
eract
iveGr
aphi
csSy
stem (
PHI
GS)
.
 Ext
ensi
onofPHI
GS,
cal
l
edPHI
GS+,
wasdev
elopedt
opr
ovi
de3-
Dsur
face
r
ender
ingcapabi
l
iti
esnotav
ail
abl
einPHI
GS.
 Thegr
aphi
cswor
kst
ati
onsf
rom Si
l
iconGr
aphi
cs,
Inc.(
SGI
),camewi
thasetof
r
out
inescal
l
edGL(
Graphi
csLi
brar
y)

Ot
herGr
aphi
csPackages
 Manyot
hercomput
er-
graphi
cspr
ogr
ammi
ngl
i
brar
ieshav
ebeendev
elopedf
or
1.gener
algr
aphi
csr
out
ines
2.Somear
eai
medatspeci
fi
cappl
i
cat
ions(
ani
mat
ion,
vir
tual
r
eal
i
ty,
etc.
)Exampl
e:OpenI
nvent
orVi
rt
ual
-Real
i
tyModel
i
ng
Language(
VRML)
.
Wecancr
eat
e2-
Dsceneswi
thi
nJav
aappl
ets(
jav
a2D,
Jav
a3D)

1.
12I
ntr
oduct
ionToOpenGL
 OpenGLbasi
c(cor
e)l
i
brar
y:-
Abasi
cli
brar
yoff
unct
ionsi
spr
ovi
dedi
nOpenGLf
or
speci
fyi
ng gr
aphi
cspr
imi
ti
ves,at
tri
but
es,geomet
ri
ctr
ansf
ormat
ions,v
iewi
ng
t
ransf
ormat
ions,
andmanyot
heroper
ati
ons.

Basi
cOpenGLSy
ntax
 Funct
ionnamesi
ntheOpenGLbasi
cli
brar
y(al
socal
l
edt
heOpenGLcor
eli
brar
y)ar
e
pr
efi
xedwi
thgl
.Thecomponentwor
dfi
rstl
ett
eri
scapi
tal
i
zed.
 Foreg:
-gl
Begi
n,gl
Clear
,gl
Copy
Pixel
s,gl
Pol
ygonMode
 Symbol
i
cconst
ant
sthatar
eusedwi
thcer
tai
nfunct
ionsaspar
amet
ersar
eal
li
n
capi
tal
l
ett
ers,
precededby“
GL”
,andcomponentar
esepar
atedbyunder
scor
e.
 For eg:
- GL_
2D, GL_
RGB, GL_
CCW, GL_
POLYGON,
GL_
AMBI
ENT_
AND_
DIFFUSE.

DEPARTMENTOFCSE,
BRCE 38
COMPUTERGRAPHI
CSANDVI
SUALI
ZATI
ON(
18CS62)

 TheOpenGLf
unct
ionsal
soexpectspeci
fi
cdat
aty
pes.Forexampl
e,anOpenGL
f
unct
ionpar
amet
ermi
ghtexpectav
aluet
hati
sspeci
fi
edasa32-
biti
nteger
.But
t
hesi
zeofani
ntegerspeci
fi
cat
ioncanbedi
ff
erentondi
ff
erentmachi
nes.
 Toi
ndi
cat
easpeci
fi
cdat
aty
pe,OpenGLusesspeci
albui
l
t-i
n,dat
a-t
ypenames,
suchasGLby
te,
GLshor
t,GLi
nt,
GLf
loat
,GLdoubl
e,Gl
bool
ean

Rel
atedLi
brar
ies
I
naddi
ti
ont
oOpenGLbasi
c(cor
e)l
i
brar
y(pr
efi
xedwi
thgl
),t
her
ear
eanumberof
associ
atedl
i
brar
iesf
orhandl
i
ngspeci
aloper
ati
ons:
-
1)OpenGLUt
il
it
y(GLU)
:-Pr
efi
xedwi
th“
glu”
.Itpr
ovi
desr
out
inesf
orset
ti
ngup
v
iewi
ng and pr
oject
ion mat
ri
ces,descr
ibi
ng compl
ex obj
ect
s wi
thl
i
ne and
pol
ygon appr
oxi
mat
ions, di
spl
ayi
ng quadr
ics and B-
spl
i
nes usi
ng l
i
near
appr
oxi
mat
ions,
processi
ngt
hesur
face-
render
ingoper
ati
ons,
andot
hercompl
ex
t
asks.
-
Ever
yOpenGLi
mpl
ement
ati
oni
ncl
udest
heGLUl
i
brar
y
2)OpenI
nvent
or:
-pr
ovi
desr
out
inesandpr
edef
inedobj
ectshapesf
ori
nter
act
ive
t
hree-di
mensi
onal
appl
i
cat
ionswhi
char
ewr
it
teni
nC++.
3)Wi
ndow-
syst
em l
ibr
ari
es:
-Tocr
eat
egr
aphi
csweneeddi
spl
aywi
ndow.We
cannotcr
eat
ethedi
spl
aywi
ndowdi
rect
lywi
tht
hebasi
cOpenGLf
unct
ionssi
nce
i
t cont
ains onl
y dev
ice-
independent gr
aphi
cs f
unct
ions, and wi
ndow-
managementoper
ati
ons ar
e dev
ice-
dependent
.Howev
er,t
her
e ar
e sev
eral
wi
ndow-
syst
em l
i
brar
ies t
hatsuppor
ts OpenGL f
unct
ions f
ora v
ari
ety of
machi
nes.
Eg:
- Appl
e GL(
AGL)
,Wi
ndows-
to-
OpenGL(
WGL)
,Pr
esent
ati
on Manager t
o
OpenGL(
PGL)
,GLX.
4)OpenGLUt
il
it
yTool
kit
(GLUT)
:-pr
ovi
desal
i
brar
yoff
unct
ionswhi
chact
sas
i
nter
facef
ori
nter
act
ingwi
thanydev
icespeci
fi
cscr
een-
windowi
ngsy
stem,t
hus
maki
ngourpr
ogr
am dev
ice-
independent
.TheGLUTl
i
brar
yfunct
ionsar
epr
efi
xed
wi
th“
glut
”.

HeaderFi
les
 I
nal
lgr
aphi
cspr
ogr
ams,
wewi
l
lneedt
oincl
udet
heheaderf
il
efort
heOpenGL
cor
eli
brar
y.
DEPARTMENTOFCSE,
BRCE 39
COMPUTERGRAPHI
CSANDVI
SUALI
ZATI
ON(
18CS62)

 I
nwi
ndowst
oincl
udeOpenGLcor
eli
brar
iesandGLUwecanuset
hef
oll
owi
ng
headerf
il
es:
-
#i
ncl
ude<wi
ndows.
h>/
/pr
ecedesot
herheaderf
il
esf
ori
ncl
udi
ngMi
crosof
t
wi
ndowsv
erofOpenGLl
i
brar
ies
#i
ncl
ude<GL/
gl.
h>
#i
ncl
ude
<GL/
glu.
h>
 Theabov
eli
nescanber
epl
acedbyusi
ngGLUTheaderf
il
ewhi
chensur
esgl
.h
andgl
u.har
eincl
udedcor
rect
ly,
 #i
ncl
ude<GL/
glut
.h>/
/GLi
nwi
ndows
 I
nAppl
eOSXsy
stems,
theheaderf
il
eincl
usi
onst
atementwi
l
lbe,
 #i
ncl
ude<GLUT/
glut
.h>

Di
spl
ay-
WindowManagementUsi
ngGLUT
 Wecanconsi
derasi
mpl
i
fiedexampl
e,mi
nimal
numberofoper
ati
onsf
or
di
spl
ayi
ngapi
ctur
e.
St
ep1:i
nit
ial
izat
ionofGLUT
Wear
eusi
ngt
heOpenGLUt
il
it
yTool
ki
t,ourf
ir
stst
epi
stoi
nit
ial
i
zeGLUT.
Thi
sini
ti
ali
zat
ionf
unct
ioncoul
dal
sopr
ocessanycommandl
i
near
gument
s,but
wewi
l
lnotneedt
ouset
hesepar
amet
ersf
orourf
ir
stexampl
epr
ogr
ams.
Weper
for
mtheGLUTi
nit
ial
i
zat
ionwi
tht
hest
atement
gl
utI
nit(
&ar
gc,
argv
);
St
ep2:t
it
le
Wecanst
atet
hatadi
spl
aywi
ndowi
stobecr
eat
edont
hescr
eenwi
thagi
ven
capt
ionf
ort
het
it
lebar
.Thi
sisaccompl
i
shedwi
tht
hef
unct
ion
gl
utCr
eat
eWi
ndow(
"AnExampl
eOpenGLPr
ogr
am"
);
wher
ethesi
ngl
ear
gumentf
ort
hisf
unct
ioncanbeanychar
act
erst
ri
ngt
hatwe
wantt
ousef
ort
hedi
spl
ay-
windowt
it
le.
St
ep3:Speci
fi
cat
ionoft
hedi
spl
aywi
ndow
Thenweneedt
ospeci
fywhatt
hedi
spl
aywi
ndowi
stocont
ain.
Fort
his,
wecr
eat
eapi
ctur
eusi
ngOpenGLf
unct
ionsandpasst
hepi
ctur
e
def
ini
ti
ont
otheGLUTr
out
inegl
utDi
spl
ayFunc,
whi
chassi
gnsourpi
ctur
etot
he
di
spl
aywi
ndow.
DEPARTMENTOFCSE,
BRCE 40
COMPUTERGRAPHI
CSANDVI
SUALI
ZATI
ON(
18CS62)

Exampl
e:supposewehav
etheOpenGLcodef
ordescr
ibi
ngal
i
nesegmenti
na
pr
ocedur
ecal
l
edl
i
neSegment
.
Thent
hef
oll
owi
ngf
unct
ioncal
lpassest
hel
i
ne-
segmentdescr
ipt
iont
othedi
spl
ay
wi
ndow:
gl
utDi
spl
ayFunc
(
li
neSegment
);St
ep 4:one mor
e GLUT
f
unct
ion
Butt
hedi
spl
aywi
ndowi
snoty
etont
hescr
een.
Weneedonemor
eGLUTf
unct
iont
ocompl
etet
hewi
ndow-
processi
ngoper
ati
ons.
Af
terexecut
ionoft
hef
oll
owi
ngst
atement
,al
ldi
spl
aywi
ndowst
hatwehav
e
cr
eat
ed,
incl
udi
ngt
hei
rgr
aphi
ccont
ent
,ar
enowact
ivat
ed:
gl
utMai
nLoop()
;
Thi
sfunct
ionmustbet
hel
astonei
nourpr
ogr
am.I
tdi
spl
ayst
hei
nit
ialgr
aphi
cs
andput
sthepr
ogr
am i
ntoani
nfi
nit
eloopt
hatchecksf
ori
nputf
rom dev
ices
suchasamouseorkey
boar
d.
St
ep5:t
hesepar
amet
ersusi
ngaddi
ti
onalGLUTf
unct
ions
Al
thought
hedi
spl
aywi
ndowt
hatwecr
eat
edwi
l
lbei
nsomedef
aul
tlocat
ionand
si
ze,
wecansett
hesepar
amet
ersusi
ngaddi
ti
onal
GLUTf
unct
ions.
GLUTFunct
ion1:
 Weuset
hegl
utI
nit
WindowPosi
ti
onf
unct
iont
ogi
veani
nit
iall
ocat
ionf
ort
he
upperl
eftcor
neroft
hedi
spl
aywi
ndow.
 Thi
sposi
ti
oni
sspeci
fi
edi
nint
egerscr
eencoor
dinat
es,whoseor
igi
nisatt
he
upper
-l
eftcor
neroft
hescr
een.

DEPARTMENTOFCSE,
BRCE 41
COMPUTERGRAPHI
CSANDVI
SUALI
ZATI
ON(
18CS62)

GLUTFunct
ion2:
Af
tert
hedi
spl
aywi
ndowi
sont
hescr
een,
wecanr
eposi
ti
onandr
esi
zei
t.
GLUTFunct
ion3:
 Wecanal
sosetanumberofot
heropt
ionsf
ort
hedi
spl
aywi
ndow,suchas
buf
fer
ingandachoi
ceofcol
ormodes,
wit
hthegl
utI
nit
Displ
ayModef
unct
ion.
 Ar
gument
sfort
hisr
out
inear
eassi
gnedsy
mbol
i
cGLUTconst
ant
s.
 Exampl
e:t
hef
oll
owi
ngcommandspeci
fi
est
hatasi
ngl
eref
reshbuf
feri
stobe
usedf
ort
hedi
spl
aywi
ndowandt
hatwewantt
ouset
hecol
ormodewhi
chuses
r
ed,
green,
andbl
ue(
RGB)component
stosel
ectcol
orv
alues:
gl
utI
nit
Displ
ayMode(
GLUT_
SINGLE|GLUT_
RGB)
;
 Thev
aluesoft
heconst
ant
spassedt
othi
sfunct
ionar
ecombi
nedusi
ngal
ogi
cal
oroper
ati
on.
 Act
ual
l
y,si
ngl
ebuf
fer
ingandRGBcol
ormodear
ethedef
aul
topt
ions.
 Butwewi
l
luset
hef
unct
ionnowasar
emi
ndert
hatt
hesear
etheopt
ionst
hatar
e
setf
orourdi
spl
ay.
 Lat
er,wedi
scusscol
ormodesi
nmor
edet
ail
,aswel
lasot
herdi
spl
ayopt
ions,
suchasdoubl
ebuf
fer
ingf
orani
mat
ionappl
i
cat
ionsandsel
ect
ingpar
amet
ersf
or
v
iewi
ngt
hreedi
mensi
onal
scenes.

ACompl
eteOpenGLPr
ogr
am
 Ther
ear
est
il
laf
ewmor
etaskst
oper
for
m bef
orewehav
eal
lthepar
tst
hatweneed
f
oracompl
etepr
ogr
am.
St
ep1:t
osetbackgr
oundcol
or
 Fort
hedi
spl
aywi
ndow,
wecanchooseabackgr
oundcol
or.
 Usi
ngRGBcol
orv
alues,
wesett
hebackgr
oundcol
orf
ort
hedi
spl
aywi
ndowt
obe
whi
te,
wit
htheOpenGLf
unct
ion:
gl
Clear
Col
or(
1.0,
1.0,
1.0,
0.0)
;
 Thef
ir
stt
hreear
gument
sint
hisf
unct
ionsett
her
ed,
green,
andbl
uecomponent
col
orst
othev
alue1.
0,gi
vi
ngusawhi
tebackgr
oundcol
orf
ort
hedi
spl
aywi
ndow.
I
f,i
nst
eadof1.
0,weseteachoft
hecomponentcol
orst
o0.
0,wewoul
dgetabl
ack
backgr
ound.

DEPARTMENTOFCSE,
BRCE 42
COMPUTERGRAPHI
CSANDVI
SUALI
ZATI
ON(
18CS62)

 Thef
our
thpar
amet
eri
nthegl
Clear
Col
orf
unct
ioni
scal
l
edt
heal
phav
aluef
ort
he
speci
fi
edcol
or.Oneusef
ort
heal
phav
aluei
sasa“
blendi
ng”par
amet
er
 Whenweact
ivat
etheOpenGLbl
endi
ngoper
ati
ons,
alphav
aluescanbeusedt
o
det
ermi
net
her
esul
ti
ngcol
orf
ort
woov
erl
appi
ngobj
ect
s.
 Anal
phav
alueof0.
0indi
cat
esat
otal
l
ytr
anspar
entobj
ect
,andanal
phav
alueof1.
0
i
ndi
cat
esanopaqueobj
ect
.
 Fornow,
wewi
l
lsi
mpl
ysetal
phat
o0.
0.
 Al
thought
hegl
Clear
Col
orcommandassi
gnsacol
ort
othedi
spl
aywi
ndow,
it
doesnotputt
hedi
spl
aywi
ndowont
hescr
een.

St
ep2:t
osetwi
ndowcol
or
 Togett
heassi
gnedwi
ndowcol
ordi
spl
ayed,
weneedt
oinv
oket
hef
oll
owi
ng
OpenGLf
unct
ion:
gl
Clear(
GL_
COLOR_
BUFFER_
BIT)
;
 Thear
gumentGLCOLORBUFFERBI
TisanOpenGLsy
mbol
i
cconst
antspeci
fyi
ng
t
hati
tist
hebi
tval
uesi
nthecol
orbuf
fer(
ref
reshbuf
fer
)thatar
etobesett
othe
v
aluesi
ndi
cat
edi
nthegl
Clear
Col
orf
unct
ion.(
OpenGLhassev
eraldi
ff
erentki
nds
ofbuf
fer
sthatcanbemani
pul
ated.

St
ep3:t
osetcol
ort
oobj
ect
I
naddi
ti
ont
oset
ti
ngt
hebackgr
oundcol
orf
ort
hedi
spl
aywi
ndow,
wecanchoosea
v
ari
etyofcol
orschemesf
ort
heobj
ect
swewantt
odi
spl
ayi
nascene.
 Forouri
nit
ial
progr
ammi
ngexampl
e,wewi
l
lsi
mpl
ysett
heobj
ectcol
ort
obeadar
k
gr
een
gl
Col
or3f(
0.0,
0.4,
0.2)
;
 Thesuf
fi
x3font
hegl
Col
orf
unct
ioni
ndi
cat
est
hatwear
especi
fyi
ngt
het
hreeRGB
col
orcomponent
susi
ngf
loat
ing-
poi
nt(
f)v
alues.
 Thisf
unct
ionr
equi
rest
hatt
hev
aluesbei
nther
angef
rom 0.
0to1.
0,andwehav
e
setr
ed
=0.
0,gr
een=0.
4,andbl
ue=0.
2.

DEPARTMENTOFCSE,
BRCE 43
COMPUTERGRAPHI
CSANDVI
SUALI
ZATI
ON(
18CS62)

Exampl
epr
ogr
am
 Forourf
ir
stpr
ogr
am,
wesi
mpl
ydi
spl
ayat
wo-
dimensi
onal
li
nesegment
.
 Todot
his,weneedt
otel
lOpenGLhowwewantt
o“pr
oject
”ourpi
ctur
eont
othe
di
spl
aywi
ndow becausegener
ati
ng a t
wo-
dimensi
onalpi
ctur
eist
reat
ed by
OpenGLasaspeci
alcaseoft
hree-
dimensi
onal
viewi
ng.
 So,
alt
houghweonl
ywantt
opr
oduceav
erysi
mpl
etwo-
dimensi
onall
i
ne,
OpenGL
pr
ocessesourpi
ctur
ethr
ought
hef
ull
thr
ee-
dimensi
onal
viewi
ngoper
ati
ons.
 Wecansett
hepr
oject
iont
ype(
mode)andot
herv
iewi
ngpar
amet
erst
hatwe
needwi
tht
hef
oll
owi
ngt
wof
unct
ions:
gl
Mat
ri
xMode (
GL_
PROJECTI
ON)
;
gl
uOr
tho2D(
0.0,
200.
0,0.
0,150.
0);
 Thi
sspeci
fi
est
hatanor
thogonalpr
oject
ioni
stobeusedt
omapt
hecont
ent
sof
at
wodi
mensi
onalr
ect
angul
arar
eaofwor
ldcoor
dinat
est
othescr
een,andt
hat
t
hex-coor
dinat
eval
ueswi
thi
nthi
srect
angl
erangef
rom 0.
0to200.
0wi
thy
-
coor
dinat
eval
uesr
angi
ngf
rom 0.
0to150.
0.
 What
everobj
ect
swedef
inewi
thi
nthi
swor
ld-
coor
dinat
erect
angl
ewi
l
lbeshown
wi
thi
nthedi
spl
aywi
ndow.
 Any
thi
ngout
sidet
hiscoor
dinat
erangewi
l
lnotbedi
spl
ayed.
 Ther
efor
e,t
heGLUf
unct
iongl
uOr
tho2Ddef
inest
hecoor
dinat
eref
erencef
rame
wi
thi
nthedi
spl
aywi
ndow t
obe(
0.0,0.
0)att
hel
ower
-l
eftcor
neroft
hedi
spl
ay
wi
ndowand(
200.
0,150.
0)att
heupper
-r
ightwi
ndowcor
ner
.
 Fornow,wewi
l
luseawor
ld-
coor
dinat
erect
angl
ewi
tht
hesameaspectr
ati
oas
t
hedi
spl
aywi
ndow,
sot
hatt
her
eisnodi
stor
ti
onofourpi
ctur
e.
 Fi
nal
l
y,weneedt
ocal
ltheappr
opr
iat
eOpenGLr
out
inest
ocr
eat
eourl
i
nesegment
.
 Thef
oll
owi
ngcodedef
inesat
wo-
dimensi
onal
,st
rai
ght
-l
inesegmentwi
thi
nteger
,
 Car
tesi
anendpoi
ntcoor
dinat
es(
180,
15)and(
10,
145)
.
gl
Begi
n(GL_
LINES)
;
gl
Ver
tex2i(
180,
15)
;
gl
Ver
tex2i(
10,
145)
;gl
End()
;
 Nowwear
ereadyt
oputal
lthepi
ecest
oget
her
:

DEPARTMENTOFCSE,
BRCE 44
COMPUTERGRAPHI
CSANDVI
SUALI
ZATI
ON(
18CS62)

Thef
oll
owi
ngOpenGLpr
ogr
am i
sor
gani
zedi
ntot
hreef
unct
ions.
 ini
t:Wepl
aceal
lini
ti
ali
zat
ionsandr
elat
edone-
ti
mepar
amet
erset
ti
ngsi
nfunct
ion
i
nit
.
l
i
neSegment
:Ourgeomet
ri
cdescr
ipt
ionoft
he“
pict
ure”t
hatwewantt
odi
spl
ayi
s
i
nfunct
ionl
i
neSegment
,whi
chi
sthef
unct
iont
hatwi
l
lber
efer
encedbyt
heGLUT
f
unct
iongl
utDi
spl
ayFunc.
 mai
nfunct
ionmai
nfunct
ioncont
ainst
heGLUTf
unct
ionsf
orset
ti
ngupt
he
di
spl
aywi
ndowandget
ti
ngourl
i
nesegmentont
othescr
een.
 gl
Flush:Thi
sissi
mpl
yar
out
inet
ofor
ceexecut
ionofourOpenGLf
unct
ions,
whi
char
est
oredbycomput
ersy
stemsi
nbuf
fer
sindi
ff
erentl
ocat
ions,
dependi
ng
onhowOpenGLi
simpl
ement
ed.
 Thepr
ocedur
eli
neSegmentt
hatwesetupt
odescr
ibeourpi
ctur
eisr
efer
redt
o
asadi
spl
aycal
l
backf
unct
ion.
 Andt
hispr
ocedur
eisdescr
ibedasbei
ng“
regi
ster
ed”bygl
utDi
spl
ayFuncast
he
r
out
inet
oinv
okewhenev
ert
hedi
spl
aywi
ndowmi
ghtneedt
ober
edi
spl
ayed.
Exampl
e:i
fthedi
spl
aywi
ndowi
smov
ed.
Fol
l
owi
ngpr
ogr
am t
odi
spl
aywi
ndowandl
i
nesegmentgener
atedbyt
his
pr
ogr
am:
#incl
ude<GL/
glut
.h>/
/(orot
her
s,dependi
ngont
hesy
stem i
n
use)
v
oidi
nit(
voi
d)
{
gl
Clear
Col
or(
1.0,
1.0,
1.0,
0.0)
; /
/Setdi
spl
ay-
windowcol
ort
o
whi
te.gl
Mat
ri
xMode(
GL_
PROJECTI
ON)
; /
/Setpr
oject
ion
par
amet
ers.gl
uOr
tho2D(
0.0,
200.
0,0.
0,150.
0);
}
v
oidl
i
neSegment(
voi
d)
{
gl
Clear(
GL_
COLOR_
BUFFER_
BIT)
; /
/Cl
eardi
spl
aywi
ndow.
gl
Col
or3f(
0.0,
0.4,
0.2)
; /
/Setl
i
nesegmentcol
ort
o
gr
een.gl
Begi
n(GL_
LINES)
;
gl
Ver
tex2i
(180,
15)
; /
/Speci
fyl
i
ne-
segment
geomet
ry.gl
Ver
tex2i
(10,
145)
;
gl
End()
;
DEPARTMENTOFCSE,
BRCE 45
COMPUTERGRAPHI
CSANDVI
SUALI
ZATI
ON(
18CS62)

gl
Flush()
;//Pr
ocessal
lOpenGLr
out
inesasqui
ckl
yaspossi
ble.
}
v
oidmai
n(i
ntar
gc,
char
**ar
gv)
{
gl
utI
nit(
&ar
gc,
argv
); /
/Ini
ti
ali
zeGLUT.
gl
utI
nit
Displ
ayMode(
GLUT_
SINGLE|
GLUT_
RGB)
;//Setdi
spl
aymode.
gl
utI
nit
WindowPosi
ti
on(
50,
100)
; /
/Sett
op-
lef
tdi
spl
ay
-
windowposi
ti
on.gl
utI
nit
WindowSi
ze(
400,
300)
; /
/Setdi
spl
ay-
wi
ndowwi
dthandhei
ght
.gl
utCr
eat
eWi
ndow(
"AnExampl
eOpenGL
Pr
ogr
am"
);/
/Cr
eat
edi
spl
aywi
ndow.i
nit()
; /
/Execut
e
i
nit
ial
i
zat
ionpr
ocedur
e.gl
utDi
spl
ayFunc(
li
neSegment
);
/
/Sendgr
aphi
cst
odi
spl
aywi
ndow.gl
utMai
nLoop()
; /
/Di
spl
ay
ev
ery
thi
ngandwai
t.
}

1.
13Coor
dinat
eRef
erenceFr
ames
Todescr
ibeapi
ctur
e,wef
ir
stdeci
deupon
Aconv
eni
entCar
tesi
ancoor
dinat
esy
stem,
cal
l
edt
hewor
ld-
coor
dinat
eref
erence
f
rame,
whi
chcoul
dbeei
ther2Dor3D.
Wet
hendescr
ibet
heobj
ect
sinourpi
ctur
ebygi
vi
ngt
hei
rgeomet
ri
cspeci
fi
cat
ionsi
n
t
ermsofposi
ti
onsi
nwor
ldcoor
dinat
es.
Exampl
e:Wedef
ineast
rai
ght
-l
inesegmentwi
tht
woendpoi
ntposi
ti
ons,
anda
pol
ygoni
sspeci
fi
edwi
thasetofposi
ti
onsf
ori
tsv
ert
ices.
Thesecoor
dinat
eposi
ti
onsar
est
oredi
nthescenedescr
ipt
ional
ongwi
thot
her
i
nfoaboutt
heobj
ect
s,suchast
hei
rcol
orandt
hei
rcoor
dinat
eext
ent
s
Co-
ordi
nat
eext
ent
s:Co-
ordi
nat
eext
ent
sar
ethemi
nimum andmaxi
mum x,
y,andz
v
aluesf
oreachobj
ect
.
Asetofcoor
dinat
eext
ent
sisal
sodescr
ibedasaboundi
ngboxf
oranobj
ect
.
Ex:
Fora2Df
igur
e,t
hecoor
dinat
eext
ent
sar
esomet
imescal
l
edi
tsboundi
ngr
ect
angl
e.
Obj
ect
sar
ethen di
spl
ayed bypassi
ng t
hescenedescr
ipt
ion t
othe v
iewi
ng
r
out
ineswhi
chi
dent
if
yvi
sibl
esur
facesandmapt
heobj
ect
stot
hef
ramebuf
fer
posi
ti
onsandt
henont
hev
ideomoni
tor
.

DEPARTMENTOFCSE,
BRCE 46
COMPUTERGRAPHI
CSANDVI
SUALI
ZATI
ON(
18CS62)

Thescan-
conv
ersi
onal
gor
it
hm st
oresi
nfoaboutt
hescene,suchascol
orv
alues,
att
heappr
opr
iat
elocat
ionsi
nthef
ramebuf
fer
,andt
hent
hescenei
sdi
spl
ayed
ont
heout
putdev
ice.

Scr
eenco-
ordi
nat
es:
 Locat
ionsonav
ideomoni
torar
eref
erencedi
nint
egerscr
eencoor
dinat
es,
whi
ch
cor
respondt
othei
ntegerpi
xel
posi
ti
onsi
nthef
ramebuf
fer
.
 Scan-
li
neal
gor
it
hmsf
ort
hegr
aphi
cspr
imi
ti
vesuset
hecoor
dinat
edescr
ipt
ions
t
odet
ermi
net
hel
ocat
ionsofpi
xel
s
 Exampl
e:gi
vent
heendpoi
ntcoor
dinat
esf
oral
i
nesegment
,adi
spl
ayal
gor
it
hm
mustcal
cul
atet
heposi
ti
onsf
ort
hosepi
xel
sthatl
i
eal
ongt
hel
i
nepat
hbet
ween
t
heendpoi
nts.
 Si
nceapi
xel
posi
ti
onoccupi
esaf
ini
tear
eaoft
hescr
een,
thef
ini
tesi
zeofapi
xel
mustbet
akeni
ntoaccountbyt
hei
mpl
ement
ati
onal
gor
it
hms.
 Fort
hepr
esent
,weassumet
hateachi
ntegerscr
eenposi
ti
onr
efer
encest
he
cent
reofapi
xel
area.
 Oncepi
xel
posi
ti
onshav
ebeeni
dent
if
iedt
hecol
orv
aluesmustbest
oredi
nthe
f
ramebuf
fer

Assumewehav
eav
ail
abl
eal
ow-
lev
elpr
ocedur
eoft
hef
orm
i
)set
Pixel(
x,y
);
 st
orest
hecur
rentcol
orset
ti
ngi
ntot
hef
ramebuf
ferati
ntegerposi
ti
on(
x,y
),
r
elat
ivet
otheposi
ti
onoft
hescr
een-
coor
dinat
eor
igi
n
i
iget
) Pixel
(x,
y,col
or)
;
 Ret
ri
evest
hecur
rentf
rame-
buf
ferset
ti
ngf
orapi
xel
locat
ion;
 Par
amet
ercol
orr
ecei
vesani
ntegerv
aluecor
respondi
ngt
othecombi
nedRGB
bi
tcodesst
oredf
ort
hespeci
fi
edpi
xel
atposi
ti
on(
x,y
).
 Addi
ti
onal
scr
een-
coor
dinat
einf
ormat
ioni
sneededf
or3Dscenes.
 Forat
wo-
dimensi
onal
scene,
all
dept
hval
uesar
e0.

DEPARTMENTOFCSE,
BRCE 47
COMPUTERGRAPHI
CSANDVI
SUALI
ZATI
ON(
18CS62)

Absol
uteandRel
ati
veCoor
dinat
eSpeci
fi
cat
ions
Absol
utecoor
dinat
e:
 Sof
ar,t
hecoor
dinat
eref
erencest
hatwehav
edi
scussedar
est
atedasabsol
ute
coor
dinat
eval
ues.
 Thi
s means t
hatt
he v
alues speci
fi
ed ar
ethe act
ualposi
ti
ons wi
thi
nthe
coor
dinat
esy
stem i
nuse.
Rel
ati
vecoor
dinat
es:
 Howev
er,somegr
aphi
cspackagesal
soal
l
ow posi
ti
onst
obespeci
fi
edusi
ng
r
elat
ivecoor
dinat
es.
 Thi
smet
hod i
susef
ulf
orv
ari
ousgr
aphi
csappl
i
cat
ions,such aspr
oduci
ng
dr
awi
ngswi
thpenpl
ott
ers,ar
ti
st’
sdr
awi
ngandpai
nti
ngsy
stems,andgr
aphi
cs
packagesf
orpubl
i
shi
ngandpr
int
ingappl
i
cat
ions.
 Taki
ngt
hisappr
oach,
wecanspeci
fyacoor
dinat
eposi
ti
onasanof
fsetf
rom t
he
l
astposi
ti
ont
hatwasr
efer
enced(
cal
l
edt
hecur
rentposi
ti
on)
.

Speci
fyi
ngaTwo-
Dimensi
onalWor
ld-
Coor
dinat
eRef
erenceFr
amei
nOpenGL
 Thegl
uOr
tho2Dcommandi
saf
unct
ionwecanuset
osetupany2DCar
tesi
an
r
efer
encef
rames.
 Thear
gument
sfort
hisf
unct
ionar
ethef
ourv
aluesdef
ini
ngt
hexandy
coor
dinat
eli
mit
sfort
hepi
ctur
ewewantt
odi
spl
ay.
 Si
ncet
hegl
uOr
tho2Df
unct
ionspeci
fi
esanor
thogonal
proj
ect
ion,
weneedal
so
t
obesur
ethatt
hecoor
dinat
eval
uesar
epl
acedi
ntheOpenGLpr
oject
ionmat
ri
x.
 I
naddi
ti
on,
wecoul
dassi
gnt
hei
dent
it
ymat
ri
xast
hepr
oject
ionmat
ri
xbef
ore
def
ini
ngt
hewor
ld-
coor
dinat
erange.
 Thi
swoul
densur
ethatt
hecoor
dinat
eval
ueswer
enotaccumul
atedwi
thany
v
alueswemayhav
epr
evi
ousl
ysetf
ort
hepr
oject
ionmat
ri
x.
 Thus,
forouri
nit
ial
two-
dimensi
onal
exampl
es,
wecandef
inet
hecoor
dinat
e
f
ramef
ort
hescr
eendi
spl
aywi
ndowwi
tht
hef
oll
owi
ngst
atement
s
gl
Mat
ri
xMode(
GL_
PROJECTI
ON)
;
gl
LoadI
dent
it
y()
;
gl
uOr
tho2D(
xmi
n,xmax,
ymi
n,y
max)
;

DEPARTMENTOFCSE,
BRCE 48
COMPUTERGRAPHI
CSANDVI
SUALI
ZATI
ON(
18CS62)

 Thedi
spl
aywi
ndow wi
l
lthenber
efer
encedbycoor
dinat
es(
xmi
n,y
min)att
he
l
ower
-l
eftcor
nerandbycoor
dinat
es(
xmax,y
max)att
heupper
-r
ightcor
ner
,as
showni
nFi
gur
ebel
ow

 Wecant
hendesi
gnat
eoneormor
egr
aphi
cspr
imi
ti
vesf
ordi
spl
ayusi
ngt
he
coor
dinat
eref
erencespeci
fi
edi
nthegl
uOr
tho2Dst
atement
.
 I
fthecoor
dinat
eext
ent
sofapr
imi
ti
vear
ewi
thi
nthecoor
dinat
erangeoft
he
di
spl
aywi
ndow,
all
oft
hepr
imi
ti
vewi
l
lbedi
spl
ayed.
 Ot
her
wise,
onl
ythosepar
tsoft
hepr
imi
ti
vewi
thi
nthedi
spl
ay-
windowcoor
dinat
e
l
i
mit
swi
l
lbeshown.
 Al
so,whenwesetupt
hegeomet
rydescr
ibi
ngapi
ctur
e,al
lposi
ti
onsf
ort
he
OpenGLpr
imi
ti
vesmustbegi
veni
nabsol
utecoor
dinat
es,wi
thr
espectt
othe
r
efer
encef
ramedef
inedi
nthegl
uOr
tho2Df
unct
ion.

1.
14OpenGLFunct
ions
Geomet
ri
cPr
imi
ti
ves:
 I
tincl
udespoi
nts,
li
nesegment
s,pol
ygonet
c.
 Thesepr
imi
ti
vespasst
hroughgeomet
ri
cpi
pel
i
newhi
chdeci
deswhet
her
t
hepr
imi
ti
vei
svi
sibl
eornotandal
sohowt
hepr
imi
ti
veshoul
dbev
isi
bleont
he
scr
eenet
c.
 Thegeomet
ri
ctr
ansf
ormat
ionssuchr
otat
ion,scal
i
nget
ccanbeappl
i
edont
he
pr
imi
ti
ves whi
ch ar
e di
spl
ayed on t
he scr
een.
The pr
ogr
ammercan cr
eat
e
geomet
ri
cpr
imi
ti
vesasshownbel
ow:
DEPARTMENTOFCSE,
BRCE 49
COMPUTERGRAPHI
CSANDVI
SUALI
ZATI
ON(
18CS62)

wher
e:
gl
Begi
nindi
cat
est
hebegi
nni
ngoft
heobj
ectt
hathast
obedi
spl
ayed
gl
Endi
ndi
cat
est
heendofpr
imi
ti
ve

1.
15OpenGLPoi
ntFunct
ions
 Thety
pewi
thi
ngl
Begi
n()speci
fi
est
het
ypeoft
heobj
ectandi
tsv
aluecanbeas
fol
l
ows:
GL_
POI
NTS
 Eachv
ert
exi
sdi
spl
ayedasapoi
nt.
 Thesi
zeoft
hepoi
ntwoul
dbeofatl
eastonepi
xel
.
 Thent
hiscoor
dinat
eposi
ti
on,
alongwi
thot
hergeomet
ri
cdescr
ipt
ionswemay
hav
einourscene,
ispassedt
othev
iewi
ngr
out
ines.
 Unl
esswespeci
fyot
herat
tri
but
eval
ues,
OpenGLpr
imi
ti
vesar
edi
spl
ayedwi
tha
def
aul
tsi
zeandcol
or.
 Thedef
aul
tcol
orf
orpr
imi
ti
vesi
swhi
te,
andt
hedef
aul
tpoi
ntsi
zei
sequal
tot
he
si
zeofasi
ngl
escr
eenpi
xel
Sy
ntax:
Case1:
gl
Begi
n(GL_
POI
NTS)
;
gl
Ver
tex2i(
50,
100)
;
gl
Ver
tex2i(
75,
150)
;
gl
Ver
tex2i(
100,
200)
;

DEPARTMENTOFCSE,
BRCE 50
COMPUTERGRAPHI
CSANDVI
SUALI
ZATI
ON(
18CS62)

gl
End()
;
Case2:
 wecoul
dspeci
fyt
hecoor
dinat
eval
uesf
ort
hepr
ecedi
ngpoi
ntsi
nar
ray
s
suchasi
ntpoi
nt1[]={
50,
100}
;
i
ntpoi
nt2[]={
75,
150}
;
i
ntpoi
nt3[]={
100,
200}
;
andcal
ltheOpenGLf
unct
ionsf
orpl
ott
ingt
het
hreepoi
ntsas
gl
Begi
n(GL_
POI
NTS)
;
gl
Ver
tex2i
v(poi
nt1)
;
gl
Ver
tex2i
v(poi
nt2)
;
gl
Ver
tex2i
v(poi
nt3)
;
gl
End()
;
Case3:
 speci
fyi
ngt
wopoi
ntposi
ti
onsi
nat
hreedi
mensi
onal
wor
ldr
efer
encef
rame.I
n
t
hiscase,
wegi
vet
hecoor
dinat
esasexpl
i
citf
loat
ing-
poi
ntv
alues:
gl
Begi
n(GL_
POI
NTS)
;
gl
Ver
tex3f(
-78.
05,
909.
72,
14.
60)
;
gl
Ver
tex3f(
261.
91,
-5200.
67,
188.
33)
;
gl
End()
;

1.
16OpenGLLI
NEFUNCTI
ONS
 Pr
imi
ti
vet
ypei
sGL_
LINES
 Successi
vepai
rsofv
ert
icesar
econsi
der
edasendpoi
ntsandt
heyar
econnect
ed
t
ofor
m ani
ndi
vi
dual
li
nesegment
s.
 Not
ethatsuccessi
vesegment
susual
l
yar
edi
sconnect
edbecauset
hev
ert
ices
ar
epr
ocessedonapai
r-
wisebasi
s.
 weobt
ainonel
i
nesegmentbet
weent
hef
ir
standsecondcoor
dinat
eposi
ti
ons
andanot
herl
i
nesegmentbet
weent
het
hir
dandf
our
thposi
ti
ons.
 i
fthenumberofspeci
fi
edendpoi
ntsi
sodd,
sot
hel
astcoor
dinat
eposi
ti
oni
s
i
gnored.

DEPARTMENTOFCSE,
BRCE 51
COMPUTERGRAPHI
CSANDVI
SUALI
ZATI
ON(
18CS62)

Case1:Li
nes
gl
Begi
n(GL_
LINES)
;
gl
Ver
tex2i
v
(
p1)
;
gl
Ver
tex2i
v
(
p2)
;
gl
Ver
tex2i
v
(
p3)
;
gl
Ver
tex2i
v
(
p4)
;
gl
Ver
tex2i
v
(
p5)
;
gl
End()
;

Case2:GL_
LINE_
STRI
P:
Successi
vev
ert
icesar
econnect
edusi
ngl
i
nesegment
s.Howev
er,
thef
inal
ver
texi
snot
connect
edt
othei
nit
ial
ver
tex.
gl
Begi
n(GL_
LINES_
STRI
P);
gl
Ver
tex2i
v(p1)
;
gl
Ver
tex2i
v(p2)
;
gl
Ver
tex2i
v(p3)
;
gl
Ver
tex2i
v(p4)
;
gl
Ver
tex2i
v(p5)
;
gl
End()
;

Case3:GL_
LINE_
LOOP:
Successi
vev
ert
icesar
econnect
edusi
ngl
i
nesegment
stof
orm acl
osedpat
horl
oop
i
.e.
,fi
nal
ver
texi
sconnect
edt
othei
nit
ial
ver
tex.
gl
Begi
n(GL_
LINES_
LOOP)
;
gl
Ver
tex2i
v(p1)
;
gl
Ver
tex2i
v(p2)
;
gl
Ver
tex2i
v(p3)
;
gl
Ver
tex2i
v(p4)
;
DEPARTMENTOFCSE,
BRCE 52
COMPUTERGRAPHI
CSANDVI
SUALI
ZATI
ON(
18CS62)

gl
Ver
tex2i
v(p5)
;
gl
End()
;

DEPARTMENTOFCSE,
BRCE 53
COMPUTERGRAPHI
CSANDVI
SUALI
ZATI
ON(
18CS62)

1.
16Poi
ntAt
tri
but
es
 Basi
cal
l
y,wecansett
woat
tri
but
esf
orpoi
nts:
col
orandsi
ze.
I
nast
atesy
stem:
Thedi
spl
ayedcol
orandsi
zeofapoi
nti
sdet
ermi
nedbyt
he
cur
rentv
aluesst
oredi
ntheat
tri
but
eli
st.
 Col
orcomponent
sar
esetwi
thRGBv
aluesorani
ndexi
ntoacol
ort
abl
e.
 Forar
ast
ersy
stem:
Poi
ntsi
zei
sani
ntegermul
ti
pleoft
hepi
xel
size,
sot
hata
l
argepoi
nti
sdi
spl
ayedasasquar
ebl
ockofpi
xel
s

OpenglPoi
nt-
Att
ri
but
eFunct
ions
Col
or:
 Thedi
spl
ayedcol
orofadesi
gnat
edpoi
ntposi
ti
oni
scont
rol
l
edbyt
hecur
rentcol
or
v
aluesi
nthest
atel
i
st.
 Al
so,
acol
ori
sspeci
fi
edwi
thei
thert
hegl
Col
orf
unct
ionort
hegl
Indexf
unct
ion.
Si
ze:
 Wesett
hesi
zef
oranOpenGLpoi
ntwi
th
gl
Poi
ntSi
ze(
size)
;
andt
hepoi
nti
sthendi
spl
ayedasasquar
ebl
ockofpi
xel
s.
 Par
amet
ersi
zei
sassi
gnedaposi
ti
vef
loat
ing-
poi
ntv
alue,
whi
chi
sroundedt
oan
i
nteger(
unl
esst
hepoi
nti
stobeant
ial
i
ased)
.
 Thenumberofhor
izont
alandv
ert
ical
pixel
sint
hedi
spl
ayoft
hepoi
nti
s
det
ermi
nedbypar
amet
ersi
ze.
 Thus,
apoi
ntsi
zeof1.
0di
spl
aysasi
ngl
epi
xel
,andapoi
ntsi
zeof2.
0di
spl
aysa2×2
pi
xel
arr
ay.
I
fweact
ivat
etheant
ial
i
asi
ngf
eat
uresofOpenGL,
thesi
zeofadi
spl
ayedbl
ockof
pi
xel
swi
l
lbemodi
fi
edt
osmoot
htheedges.
 Thedef
aul
tval
uef
orpoi
ntsi
zei
s1.
0.

Exampl
epr
ogr
am:
 At
tri
but
efunct
ionsmaybel
i
stedi
nsi
deorout
sideofagl
Begi
n/gl
Endpai
r.
 Exampl
e:t
hef
oll
owi
ngcodesegmentpl
otst
hreepoi
ntsi
nvar
yingcol
orsandsi
zes.

DEPARTMENTOFCSE,
BRCE 54
COMPUTERGRAPHI
CSANDVI
SUALI
ZATI
ON(
18CS62)

 Thef
ir
sti
sast
andar
d-si
zer
edpoi
nt,
thesecondi
sadoubl
e-si
zegr
eenpoi
nt,
and
t
het
hir
disat
ri
ple-
sizebl
uepoi
nt:

Ex:
gl
Col
or3f(
1.0,
0.0,
0.0)
;
gl
Begi
n(GL_
POI
NTS)
;
gl
Ver
tex2i
(50,
100)
;
gl
Poi
ntSi
ze(
2.0)
;
gl
Col
or3f(
0.0,
1.0,
0.0)
;
gl
Ver
tex2i
(75,
150)
;
gl
Poi
ntSi
ze(
3.0)
;
gl
Col
or3f(
0.0,
0.0,
1.0)
;
gl
Ver
tex2i
(100,
200)
;gl
End()
;

1.
17Li
ne-
Att
ri
but
eFunct
ionsOpenGL
I
nOpenGLst
rai
ght
-l
inesegmentwi
tht
hreeat
tri
but
eset
ti
ngs:
li
necol
or,
li
ne-
wi
dth,
andl
i
nest
yle.
 OpenGLpr
ovi
desaf
unct
ionf
orset
ti
ngt
hewi
dthofal
i
neandanot
herf
unct
ionf
or
speci
fyi
ngal
i
nest
yle,
suchasadashedordot
tedl
i
ne.

OpenGLLi
ne-
Widt
hFunct
ion
 Li
newi
dthi
sseti
nOpenGLwi
tht
hef
unct
ion
Sy
ntax:gl
LineWi
dth(
widt
h);
 Weassi
gnaf
loat
ing-
poi
ntv
aluet
opar
amet
erwi
dth,
andt
hisv
aluei
sroundedt
othe
near
estnonnegat
ivei
nteger
.
I
fthei
nputv
aluer
oundst
o0.
0,t
hel
i
nei
sdi
spl
ayedwi
thast
andar
dwi
dthof1.
0,
whi
chi
sthedef
aul
twi
dth.
 Somei
mpl
ement
ati
onsoft
hel
i
ne-
widt
hfunct
ionmi
ghtsuppor
tonl
yal
i
mit
ed
numberofwi
dths,
andsomemi
ghtnotsuppor
twi
dthsot
hert
han1.
0.

DEPARTMENTOFCSE,
BRCE 55
COMPUTERGRAPHI
CSANDVI
SUALI
ZATI
ON(
18CS62)

 Thati
s,t
hemagni
tudeoft
hehor
izont
alandv
ert
icalsepar
ati
onsoft
hel
i
ne
endpoi
nts,del
taxanddel
tay
,ar
ecompar
edt
odet
ermi
newhet
hert
ogener
atea
t
hickl
i
neusi
ngv
ert
ical
pixel
spansorhor
izont
alpi
xel
spans.

OpenGLLi
ne-
Sty
leFunct
ion
 Bydef
aul
t,ast
rai
ght
-l
inesegmenti
sdi
spl
ayedasasol
i
dli
ne.
 Butwecanal
sodi
spl
aydashedl
i
nes,
dot
tedl
i
nes,
oral
i
newi
thacombi
nat
ionof
dashesanddot
s.
 Wecanv
aryt
hel
engt
hoft
hedashesandt
hespaci
ngbet
weendashesordot
s.
 Wesetacur
rentdi
spl
ayst
ylef
orl
i
neswi
tht
heOpenGLf
unct
ion:
Sy
ntax:gl
LineSt
ippl
e(r
epeat
Fact
or,
pat
ter
n);

Pat
ter
n:
 Par
amet
erpat
ter
nisusedt
oref
erencea16-
biti
ntegert
hatdescr
ibeshowt
hel
i
ne
shoul
dbedi
spl
ayed.
 1bi
tint
hepat
ter
ndenot
esan“
on”pi
xel
posi
ti
on,
anda0bi
tindi
cat
esan“
off
”pi
xel
posi
ti
on.
 Thepat
ter
nisappl
i
edt
othepi
xel
sal
ongt
hel
i
nepat
hst
art
ingwi
tht
hel
ow-
order
bi
tsi
nthepat
ter
n.
 Thedef
aul
tpat
ter
nis0xFFFF(
eachbi
tposi
ti
onhasav
alueof1)
,whi
chpr
oducesa
sol
i
dli
ne.

r
epeat
Fact
or
I
ntegerpar
amet
err
epeat
Fact
orspeci
fi
eshowmanyt
imeseachbi
tint
hepat
ter
nis
t
ober
epeat
edbef
oret
henextbi
tint
hepat
ter
nisappl
i
ed.
 Thedef
aul
trepeatv
aluei
s1.

Pol
yl
ine:
 Wi
thapol
yl
ine,
aspeci
fi
edl
i
ne-
sty
lepat
ter
nisnotr
est
art
edatt
hebegi
nni
ngofeach
segment
.

DEPARTMENTOFCSE,
BRCE 56
COMPUTERGRAPHI
CSANDVI
SUALI
ZATI
ON(
18CS62)

I
tisappl
i
edcont
inuousl
yacr
ossal
lthesegment
s,st
art
ingatt
hef
ir
stendpoi
ntoft
he
pol
yl
ineandendi
ngatt
hef
inal
endpoi
ntf
ort
hel
astsegmenti
ntheser
ies.
Exampl
e:
 Forl
i
nest
yle,
supposepar
amet
erpat
ter
nisassi
gnedt
hehexadeci
mal
r
epr
esent
ati
on0x00FFandt
her
epeatf
act
ori
s1.
 Thiswoul
ddi
spl
ayadashedl
i
newi
thei
ghtpi
xel
sineachdashandei
ghtpi
xel
posi
ti
ons
t
hatar
e“of
f”(
anei
ght
-pi
xel
space)bet
weent
wodashes.
 Al
so,
sincel
owor
derbi
tsar
eappl
i
edf
ir
st,
ali
nebegi
nswi
thanei
ght
-pi
xel
dash
st
art
ingatt
hef
ir
stendpoi
nt.
 Thi
sdashi
sfol
l
owedbyanei
ght
-pi
xel
space,
thenanot
herei
ght
-pi
xel
dash,
andso
f
ort
h,unt
ilt
hesecondendpoi
ntposi
ti
oni
sreached.

Act
ivat
ingl
inest
yle:
 Bef
oreal
i
necanbedi
spl
ayedi
nthecur
rentl
i
ne-
sty
lepat
ter
n,wemustact
ivat
e
t
hel
i
ne-st
ylef
eat
ureofOpenGL.
gl
Enabl
e(GL_
LINE_
STI
PPLE)
;
 I
fwef
orgett
oincl
udet
hisenabl
efunct
ion,
sol
i
dli
nesar
edi
spl
ayed;
thati
s,t
he
def
aul
tpat
ter
n0xFFFFi
susedt
odi
spl
ayl
i
nesegment
s.
 Atanyt
ime,
wecant
urnof
fthel
i
ne-
pat
ter
nfeat
urewi
th
gl
Disabl
e(GL_
LINE_
STI
PPLE)
;
 Thi
srepl
acest
hecur
rentl
i
ne-
sty
lepat
ter
nwi
tht
hedef
aul
tpat
ter
n(sol
i
dli
nes)
.

Exampl
eCode:
t
ypedefst
ruct{f
loatx,
y;}
wcPt
2D;
wcPt
2Ddat
aPt
s[5]
;
v
oidl
i
nePl
ot(
wcPt
2Ddat
aPt
s[5]
)
{
i
ntk;
gl
Begi
n(GL_
LINE_
STRI
P);
f
or(
k=0;
k<5;
k++)
gl
Ver
tex2f(
dat
aPt
s[k]
.x,
dat
aPt
s[k]
.y)
;

DEPARTMENTOFCSE,
BRCE 57
COMPUTERGRAPHI
CSANDVI
SUALI
ZATI
ON(
18CS62)

gl
Flush()
;
gl
End()
;
}
/
*Inv
okeapr
ocedur
eher
etodr
awcoor
dinat
eaxes.*
/
gl
Enabl
e(GL_
LINE_
STI
PPLE)
;/*I
nputf
ir
stsetof(
x,y
)dat
aval
ues.
*
/gl
LineSt
ippl
e(1,
0x1C47)
;//Pl
otadash-
dot
,st
andar
d-wi
dth
pol
yl
ine.l
i
nePl
ot(
dat
aPt
s);
/
*Inputsecondsetof(
x,y
)dat
aval
ues.*
/
gl
LineSt
ippl
e(1,
0x00FF)
;//Pl
otadashed,
doubl
e-wi
dthpol
yl
ine.
gl
LineWi
dth(
2.0)
;
l
i
nePl
ot(
dat
aPt
s);
/
*Inputt
hir
dsetof(
x,y
)dat
aval
ues.*
/
gl
LineSt
ippl
e(1,
0x0101)
;//Pl
otadot
ted,
tri
ple-
widt
h
pol
yl
ine.gl
LineWi
dth(
3.0)
;
l
i
nePl
ot(
dat
aPt
s);
gl
Disabl
e(GL_
LINE_
STI
PPLE)
;

1.
18Cur
veAt
tri
but
es
 Par
amet
ersf
orcur
veat
tri
but
esar
ethesameast
hosef
orst
rai
ght
-l
inesegment
s.
 Wecandi
spl
aycur
veswi
thv
ary
ingcol
ors,
widt
hs,
dot
-dashpat
ter
ns,
and
av
ail
abl
epenorbr
ushopt
ions.
 Met
hodsf
oradapt
ingcur
ve-
drawi
ngal
gor
it
hmst
oaccommodat
eat
tri
but
e
sel
ect
ionsar
esi
mil
art
othosef
orl
i
nedr
awi
ng.
 Rast
ercur
vesofv
ari
ouswi
dthscanbedi
spl
ayedusi
ngt
hemet
hodofhor
izont
alor
v
ert
ical
pixel
spans.
Case1:Wher
ethemagni
tudeoft
hecur
vesl
ope|
m|<=1.
0,wepl
otv
ert
ical
spans;
Case2:whent
hesl
opemagni
tude|
m|>1.
0,wepl
othor
izont
alspans.

Di
ff
erentmet
hodst
odr
awacur
ve:
Met
hod1:
Usi
ngci
rcl
esy
mmet
rypr
oper
ty,
wegener
atet
heci
rcl
epat
hwi
thv
ert
ical
spans
i
ntheoct
antf
rom x=0t
ox=y
,andt
henr
efl
ectpi
xel
posi
ti
onsaboutt
hel
i
ney=xt
oy=0

DEPARTMENTOFCSE,
BRCE 58
COMPUTERGRAPHI
CSANDVI
SUALI
ZATI
ON(
18CS62)

Met
hod2:Anot
hermet
hodf
ordi
spl
ayi
ngt
hickcur
vesi
stof
il
lint
hear
eabet
weent
wo
Par
all
elcur
vepat
hs,
whosesepar
ati
ondi
stancei
sequalt
othedesi
redwi
dth.Wecoul
d
dot
hisusi
ngt
hespeci
fi
edcur
vepat
hasoneboundar
yandset
ti
ngupt
hesecond
boundar
yei
theri
nsi
deorout
sidet
heor
igi
nalcur
vepat
h.Thi
sappr
oach,
howev
er,
shi
ft
s
t
heor
igi
nalcur
vepat
hei
theri
nwar
dorout
war
d,dependi
ngonwhi
chdi
rect
ionwe
choosef
ort
hesecondboundar
y.

Met
hod3:
Thepi
xelmasksdi
scussedf
ori
mpl
ement
ingl
i
ne-
sty
leopt
ionscoul
dal
sobe
usedi
nrast
ercur
veal
gor
it
hmst
ogener
atedashedordot
tedpat
ter
ns

Met
hod4:Pen(
orbr
ush)di
spl
aysofcur
vesar
egener
atedusi
ngt
hesamet
echni
ques
di
scussedf
orst
rai
ght
-l
inesegment
s.

Met
hod5:Pai
nti
nganddr
awi
ngpr
ogr
amsal
l
owpi
ctur
est
obeconst
ruct
edi
nter
act
ivel
y
byusi
ngapoi
nti
ngdev
ice,suchasast
ylusandagr
aphi
cst
abl
et,t
osket
chv
ari
ous
cur
veshapes.

1.
19Li
neDr
awi
ngAl
gor
it
hm
 A st
rai
ght
-l
inesegmenti
nascenei
sdef
inedbycoor
dinat
eposi
ti
onsf
ort
he
endpoi
ntsoft
hesegment
.
 Todi
spl
ayt
hel
i
neonar
ast
ermoni
tor
,thegr
aphi
cssy
stem mustf
ir
stpr
ojectt
he
endpoi
ntst
oint
egerscr
een coor
dinat
es and det
ermi
ne t
he near
estpi
xel
posi
ti
onsal
ongt
hel
i
nepat
hbet
weent
het
woendpoi
ntst
hent
hel
i
necol
ori
s
l
oadedi
ntot
hef
ramebuf
feratt
hecor
respondi
ngpi
xel
coor
dinat
es
 TheCar
tesi
ansl
ope-
int
erceptequat
ionf
orast
rai
ghtl
i
nei
s
y
=m *x+b >(
1)
wi
thm ast
hesl
opeoft
hel
i
neandbast
heyi
nter
cept
.
 Gi
vent
hatt
het
woendpoi
ntsofal
i
nesegmentar
especi
fi
edatposi
ti
ons(
x0,
y0)
and(
xend,
yend),
asshowni
nfi
g.

DEPARTMENTOFCSE,
BRCE 59
COMPUTERGRAPHI
CSANDVI
SUALI
ZATI
ON(
18CS62)

 Wedet
ermi
nev
aluesf
ort
hesl
opem andyi
nter
ceptbwi
tht
hef
oll
owi
ngequat
ions:
m=(
yend-y
0)/
(xend-x0) >(
2)
b=y
0-m.
x0 >(
3)
 Al
gor
it
hmsf
ordi
spl
ayi
ngst
rai
ghtl
i
near
ebasedont
hel
i
neequat
ion(
1)and
cal
cul
ati
onsgi
veni
neq(
2)and(
3).
 Forgi
venxi
nter
val
δxal
ongal
i
ne,
wecancomput
ethecor
respondi
ngyi
nter
val
δy
fr
om
eq.
(2)as
δy
=m.δx >(
4)
 Si
mil
arl
y,wecanobt
aint
hexi
nter
val
δxcor
respondi
ngt
oaspeci
fi
edδyas
δx=δy
/m >(
5)
 Theseequat
ionsf
ormt
hebasi
sfordet
ermi
ningdef
lect
ionv
olt
agesi
nanal
og
di
spl
ays,such as v
ect
or-
scan sy
stem,wher
e ar
bit
rar
il
y smal
lchanges i
n
def
lect
ionv
olt
agear
epossi
ble.
 Forl
i
neswi
thsl
opemagni
tudes
|
m|<1,
δxcanbesetpr
opor
ti
onal
toasmal
lhor
izont
aldef
lect
ionv
olt
agewi
tht
he
cor
respondi
ngv
ert
ical
def
lect
ionv
olt
agesetpr
opor
ti
onal
toδyf
rom eq.
(4)
|
m|>1,
δycanbesetpr
opor
ti
onal
toasmal
lver
ti
cal
def
lect
ionv
olt
agewi
tht
he
cor
respondi
nghor
izont
aldef
lect
ionv
olt
agesetpr
opor
ti
onal
toδxf
rom eq.
(5)
|
m|=1,
δx=δyandt
hehor
izont
alandv
ert
ical
def
lect
ionsv
olt
agesar
eequal

DDAAl
gor
it
hm (
DIGI
TALDI
FFERENTI
ALANALYZER)
 TheDDAi
sascan-
conv
ersi
onl
i
neal
gor
it
hm basedoncal
cul
ati
ngei
therδyorδx.

DEPARTMENTOFCSE,
BRCE 60
COMPUTERGRAPHI
CSANDVI
SUALI
ZATI
ON(
18CS62)

 Al
i
nei
ssampl
edatuni
tint
erv
alsi
nonecoor
dinat
eandt
hecor
respondi
ngi
nteger
v
aluesnear
estt
hel
i
nepat
har
edet
ermi
nedf
ort
heot
hercoor
dinat
e
 DDAAl
gor
it
hm hast
hreecasessof
rom equat
ioni
.e.
.,
m=(
yk+1-yk)
/(xk+1-xk)

Case
1:
i
fm<1,
xincr
ementi
nuni
t
i
nter
v si
al .
e..
,
xk+1=xk+1
t
hen,
m=(
yk+1-yk)
/(xk+1-xk)
m=y
k+1-yk

y
k+1=y
k+m >(
1)
 wher
ekt
akesi
ntegerv
aluesst
art
ingf
rom 0,
fort
hef
ir
stpoi
ntandi
ncr
easesby1
unt
ilf
inal
endpoi
nti
sreached.Si
ncem canbeanyr
eal
numberbet
ween0.
0and1.
0,

Case
2:
i
fm>1,
yincr
ementi
nuni
t
i
nter
v si
al .
e..
,yk+1=y
k+1

t
hen,
m=(
yk+1-y
k)/
(xk+1-xk)
m(
xk+1-xk)
=1
xk+1=(
1/m)
+xk (
2)

Case3:
i
fm=1,
bot
hxandyi
ncr
ementi
nuni
tint
erv
als
i
.e.
.,
xk+1=xk+1andy
k+1=y
k+1

Equat
ions(
1)and(
2)ar
ebasedont
heassumpt
iont
hatl
i
nesar
etobepr
ocessedf
rom
t
hel
eftendpoi
ntt
other
ightendpoi
nt.I
fthi
spr
ocessi
ngi
srev
ersed,
sot
hatt
hest
art
ing
endpoi
nti
satt
her
ight
,thenei
therwehav
eδx=-
1and
y
k+1=y
k-m (
3)
or
(whent
hesl
opei
sgr
eat
ert
han1)
wehav
eδy
=-1
wi
thxk+1=xk-(
1/m) (
4)

DEPARTMENTOFCSE,
BRCE 61
COMPUTERGRAPHI
CSANDVI
SUALI
ZATI
ON(
18CS62)

 Si
mil
arcal
cul
ati
onsar
ecar
ri
edoutusi
ngequat
ions(
1)t
hrough(
4)t
odet
ermi
ne
t
hepi
xelposi
ti
onsal
ongal
i
newi
thnegat
ivesl
ope.t
hus,i
ftheabsol
utev
alueof
t
hesl
opei
slesst
han1andt
hest
art
ingendpoi
nti
satl
eft,
wesetδx==1and
cal
cul
ateyv
alueswi
theq(
1).
 whenst
art
ingendpoi
nti
satt
her
ight
(fort
hesamesl
ope)
,wesetδx=-
1andobt
ain
yposi
ti
onsusi
ngeq(
3).
 Thi
sal
gor
it
hm i
ssummar
izedi
nthef
oll
owi
ngpr
ocedur
e,whi
chaccept
sasi
nput
t
woi
ntegerscr
eenposi
ti
onsf
ort
heendpoi
ntsofal
i
nesegment
.
 i
fm<1,
wher
exi
sincr
ement
ing
by1y
k+1=y
k+m

 Soi
nit
ial
l
yx=0,
Assumi
ng(
x0,
y0)
asi
nit
ialpoi
ntassi
gni
ngx=x0,
y=y
0whi
chi
sthe
st
art
ingpoi
nt.
o I
ll
umi
nat
epi
xel
(x,
round(
y))
o x1=x+1,
y1=y+1
o I
ll
umi
nat
epi
xel
(x1,
round(
y1)
)
o x2=x1+1,
y2=y
1+1
o I
ll
umi
nat
epi
xel
(x2,
round(
y2)
)
o Ti
l
litr
eachesf
inal
poi
nt.
i
fm>1,
wher
eyi
sincr
ement
ingby
1xk+1=(
1/m)
+xk
 Soi
nit
ial
l
yy=0,
Assumi
ng(
x0,
y0)
asi
nit
ial
poi
ntassi
gni
ngx=x0,
y=y
0whi
chi
sthe
st
art
ingpoi
nt.
o I
ll
umi
nat
epi
xel
(r
ound(
x),
y)
o x1=x+(1/
m),
y1=y
o I
ll
umi
nat
epi
xel
(r
ound(
x1)
,y1)
o x2=x1+(
1/m),
y2=y
1
o I
ll
umi
nat
epi
xel
(r
ound(
x2)
,y2)
o Ti
l
litr
eachesf
inal
poi
nt.

 TheDDAal
gor
it
hm i
sfast
ermet
hodf
orcal
cul
ati
ngpi
xel
posi
ti
ont
hanonet
hat
di
rect
lyi
mpl
ement
s.

DEPARTMENTOFCSE,
BRCE 62
COMPUTERGRAPHI
CSANDVI
SUALI
ZATI
ON(
18CS62)

 I
tel
i
minat
est
hemul
ti
pli
cat
ionbymaki
nguseofr
ast
erchar
act
eri
sti
cs,sot
hat
appr
opr
iat
eincr
ement
sar
eappl
i
edi
nthexorydi
rect
ionst
ost
epf
rom onepi
xel
posi
ti
ont
oanot
heral
ongt
hel
i
nepat
h.
 Theaccumul
ati
onofr
oundof
fer
rori
nsuccessi
veaddi
ti
onsoft
hef
loat
ingpoi
nt
i
ncr
ement
,howev
ercancauset
hecal
cul
atedpi
xelposi
ti
onst
odr
if
tawayf
rom
t
het
ruel
i
nepat
hforl
ongl
i
nesegment
s.Fur
ther
mor
e,t
her
oundi
ngoper
ati
ons
andf
loat
ingpoi
ntar
it
hmet
ici
nthi
spr
ocedur
ear
est
il
lti
meconsumi
ng.
 wei
mpr
ovet
heper
for
manceofDDAal
gor
it
hm bysepar
ati
ngt
hei
ncr
ement
sm
and1/
mint
oint
egerandf
ract
ionalpar
tssot
hatal
lcal
cul
ati
onsar
ereducedt
o
i
ntegeroper
ati
ons.
#i
ncl
ude
<st
dli
b.h>
#i
ncl
ude
<mat
h.h>
i
nli
nei
ntr
ound(
constf
loata)
{
r
etur
nint(
a+0.
5);
}
v
oidl
i
neDDA(
intx0,
inty
0,i
ntxEnd,
inty
End)
{
i
ntdx=xEnd-x0,
dy=y
End-y
0,st
eps,
k;
f
loatxI
ncr
ement
,yI
ncr
ement
,x=x0,
y=
y
0;i
f(f
abs(
dx)>f
abs(
dy)
)
st
eps=f
abs(
dx)
;
el
se
st
eps=f
abs(
dy)
;
xI
ncr
ement= f
loat(
dx)/f
loat
(
steps)
;yI
ncr
ement=f
loat(
dy)/
f
loat(
steps)
;set
Pixel(
round(
x),
r
ound(
y))
;
f
or(
k=0;
k<st
eps;k++)
{x+=xI
ncr
ement
;
y+=y
Incr
ement
;
DEPARTMENTOFCSE,
BRCE 63
COMPUTERGRAPHI
CSANDVI
SUALI
ZATI
ON(
18CS62)

set
Pixel
(round(
x),
round(
y))
;
}

DEPARTMENTOFCSE,
BRCE 64
COMPUTERGRAPHI
CSANDVI
SUALI
ZATI
ON(
18CS62)

Br
esenham’
sAl
gor
it
hm:
 I
tisanef
fi
cientr
ast
erscangener
ati
ngal
gor
it
hm t
hatusesi
ncr
ement
ali
ntegr
al
cal
cul
ati
ons
 To i
l
lust
rat
e Br
esenham’
s appr
oach,we f
ir
stconsi
dert
he scan-
conv
ersi
on
pr
ocessf
orl
i
neswi
thposi
ti
vesl
opel
esst
han1.
0.
 Pi
xelposi
ti
onsal
ongal
i
nepat
har
ethendet
ermi
nedbysampl
i
ngatuni
tx
i
nter
val
s.St
art
ingf
rom t
hel
eftendpoi
nt(
x0,y
0)ofagi
venl
i
ne,west
ept
oeach
successi
vecol
umn(
xposi
ti
on)andpl
ott
hepi
xelwhosescan-
li
neyv
aluei
s
cl
osestt
othel
i
nepat
h.

 Consi
dert
heequat
ionofast
rai
ghtl
i
ney
=mx+cwher
em=dy
/dx

Br
esenham’
sLi
ne-
Drawi
ngAl
gor
it
hm f
or|
m|<1.
0
1.
Inputt
het
wol
i
neendpoi
ntsandst
oret
hel
eftendpoi
nti
n(x0,
y0)
.
2.
Sett
hecol
orf
orf
rame-
buf
ferposi
ti
on(
x0,
y0)
;i.
e.,
plott
hef
ir
stpoi
nt.
3.Calcul
atet
heconst
ant
s∆x,
∆y,
2∆y
,and2∆y−2∆x,
andobt
aint
hest
art
ingv
alue
for
t
hedeci
sionpar
amet
eras
p0=2∆y−∆x
4.
Ateachxkal
ongt
hel
i
ne,
star
ti
ngatk=0,
per
for
mthef
oll
owi
ngt
est
:
I
fpk<0,
thenextpoi
ntt
opl
oti
s(xk+1,
yk)and
pk+1=pk+2∆y
Ot
her
wise,
thenextpoi
ntt
opl
oti
s(xk+1,
yk+1)and
pk+1=pk+2∆y−2∆x
5.
Repeatst
ep4∆x−1mor
eti
mes.
Not
e:
I
f
|
m|>1.
0
Then
p0=2∆x−∆y
DEPARTMENTOFCSE,
BRCE 65
COMPUTERGRAPHI
CSANDVI
SUALI
ZATI
ON(
18CS62)

and

DEPARTMENTOFCSE,
BRCE 66
COMPUTERGRAPHI
CSANDVI
SUALI
ZATI
ON(
18CS62)

I
fpk<0,
thenextpoi
ntt
opl
oti
s(xk,
yk+1)and
pk+1=pk+2∆x
Ot
her
wise,
thenextpoi
ntt
opl
oti
s(xk+1,
yk+1)and
pk+1=pk+2∆x−2∆y

Code:
#i
ncl
ude
<st
dli
b.h>
#i
ncl
ude
<mat
h.h>
/
*Br
esenham l
i
ne-
drawi
ngpr
ocedur
efor|
m|<
1.
0.*
/voi
dli
neBr
es(
intx0,
inty
0,i
ntxEnd,
int
y
End)
{
i
ntdx=f
abs(
xEnd-x0)
,dy=f
abs(
yEnd-
y
0);
intp=2*dy-dx;
i
ntt
woDy=2*dy
,twoDy
MinusDx=2*(
dy-dx)
;
i
ntx,
y;
/
*Det
ermi
newhi
chendpoi
ntt
ouseasst
art
posi
ti
on.*
/if(
x0>xEnd){
x=xEnd;
y=y
End;
xEnd=x0;
}
el
se
{
x=x0;
y=y
0;

}
set
Pixel
(x,
y);
whi
l
e(x<xEnd){
x++;
DEPARTMENTOFCSE,
BRCE 67
COMPUTERGRAPHI
CSANDVI
SUALI
ZATI
ON(
18CS62)

i
f(p<0)
p+=t
woDy
;

DEPARTMENTOFCSE,
BRCE 68
COMPUTERGRAPHI
CSANDVI
SUALI
ZATI
ON(
18CS62)

el
se
{
y
++;
p+=t
woDy
MinusDx;

}
set
Pixel
(x,
y);
}
}

Pr
oper
ti
esofCi
rcl
es
 Aci
rcl
eisdef
inedast
hesetofpoi
ntst
hatar
eal
latagi
vendi
stancerf
rom acent
er
posi
ti
on(
xc,
yc)
.
 Foranyci
rcl
epoi
nt(
x,y
),t
hisdi
stancer
elat
ionshi
pisexpr
essedbyt
hePy
thagor
ean
t
heor
em i
nCar
tesi
ancoor
dinat
esas

 Wecoul
d uset
hisequat
ion t
o cal
cul
atet
heposi
ti
on ofpoi
ntson aci
rcl
e
ci
rcumf
erencebyst
eppi
ngal
ongt
hexaxi
sinuni
tst
epsf
rom xc−rt
oxc+rand
cal
cul
ati
ngt
hecor
respondi
ngyv
aluesateachposi
ti
onas

 Onepr
obl
em wi
tht
hisappr
oachi
sthati
tinv
olv
esconsi
der
abl
ecomput
ati
onateach
st
ep.
Mor
eov
er,
thespaci
ngbet
weenpl
ott
edpi
xel
posi
ti
onsi
snotuni
for
m.
 Wecoul
dadj
ustt
hespaci
ngbyi
nter
changi
ngxandy(
steppi
ngt
hroughyv
alues
andcal
cul
ati
ngxv
alues)whenev
ert
heabsol
utev
alueoft
hesl
opeoft
heci
rcl
eis
gr
eat
ert
han 1;butt
his si
mpl
yincr
eases t
he comput
ati
on and pr
ocessi
ng
r
equi
redbyt
heal
gor
it
hm.
 Anot
herwayt
oel
i
minat
etheunequal
spaci
ngi
stocal
cul
atepoi
ntsal
ongt
heci
rcul
ar
boundar
yusi
ngpol
arcoor
dinat
esrandθ
 Expr
essi
ngt
heci
rcl
eequat
ioni
npar
amet
ri
cpol
arf
ormy
iel
dst
hepai
rofequat
ions

DEPARTMENTOFCSE,
BRCE 69
COMPUTERGRAPHI
CSANDVI
SUALI
ZATI
ON(
18CS62)

Mi
dpoi
ntCi
rcl
eAl
gor
it
hm
 Mi
dpoi
ntci
rcl
eal
gor
it
hm gener
atesal
lpoi
ntsonaci
rcl
ecent
eredatt
heor
igi
nby
i
ncr
ement
ingal
lthewayar
oundci
rcl
e.
 Thest
rat
egyi
stosel
ectwhi
chof2pi
xel
siscl
osert
otheci
rcl
ebyev
aluat
inga
f
unct
ionatt
hemi
dpoi
ntbet
weent
he2pi
xel
s
 Toappl
ythemi
dpoi
ntmet
hod,
wedef
ineaci
rcl
efunct
ionas

 Tosummar
ize,
ther
elat
iveposi
ti
onofanypoi
nt(
x,y
)canbedet
ermi
nedby
checki
ngt
hesi
gnoft
heci
rcl
efunct
ionasf
oll
ows:

Ei
ghtwaysy
mmet
ry
 Theshapeoft
heci
rcl
eissi
mil
ari
neachquadr
ant
.
 Ther
efor
e,i
fwedet
ermi
net
hecur
veposi
ti
onsi
nthef
ir
stquadr
ant,
wecan
gener
atet
heci
rcl
eposi
ti
onsi
nthesecondquadr
antofxypl
ane.
 Theci
rcl
esect
ionsi
nthet
hir
dandf
our
thquadr
antcanbeobt
ainedf
rom sect
ions
i
nthef
ir
standsecondquadr
antbyconsi
der
ingt
hesy
mmet
ryal
ongXaxi
s

DEPARTMENTOFCSE,
BRCE 70
COMPUTERGRAPHI
CSANDVI
SUALI
ZATI
ON(
18CS62)

 Consi
det
heci
rcl
ecent
eredatt
heor
igi
n,
ift
hepoi
nt(x,
y)i
sont
heci
rcl
e,
thenwe
cancomput
e7ot
herpoi
ntsont
heci
rcl
easshowni
ntheabov
efi
gur
e.
 Ourdeci
sionpar
amet
eri
stheci
rcl
efunct
ionev
aluat
edatt
hemi
dpoi
ntbet
ween
t
heset
wopi
xel
s:

 Successi
vedeci
sionpar
amet
ersar
eobt
ainedusi
ngi
ncr
ement
alcal
cul
ati
ons.
 Weobt
ainar
ecur
siv
eexpr
essi
onf
ort
henextdeci
sionpar
amet
erbyev
aluat
ingt
he
ci
r ef
cl unct
ionatsampl
i
ngposi
ti
onxk+1+1=xk+2:

DEPARTMENTOFCSE,
BRCE 71
COMPUTERGRAPHI
CSANDVI
SUALI
ZATI
ON(
18CS62)

 Thei
nit
ial
deci
sionpar
amet
eri
sobt
ainedbyev
aluat
ingt
heci
rcl
efunct
ionatt
he
st
artposi
ti
on(
x0,
y0)=(
0,r)
:

I
fther
adi
usri
sspeci
fi
edasani
nteger
,wecansi
mpl
yroundp0t
o
p0=1−r(
forrani
nteger
)
becauseal
li
ncr
ement
sar
eint
eger
s.

Mi
dpoi
ntCi
rcl
eAl
gor
it
hm
1.I
nputr usrandci
adi rcl
ecent xc,
er( yc)
,thensett
hecoor
dinat
esf
ort
hef
ir
stpoi
nton
t
heci
rcumf
erenceofaci
rcl
ecent
eredont
heor
igi
nas
(
x0,
y0)=(
0,r)
2.
Cal
cul
atet
hei
nit
ial
val
ueoft
hedeci
sionpar
amet
eras
p0=1-
r
Ateachx
3. kposi
ti
on,
star
tngatk=0,
i per
for
mthef
oll
owi
ngt
est
:
fpk<0,
I thenextpoi
ntal
ongt
heci
rcl
ecent
eredon(
0,0)i
s(xk+1,
yk)and
pk+1=pk+2xk+1+1
Ot
her
wise,
thenextpoi
ntal
ongt
heci
rcl
ei xk+1,
s( yk−1)and
pk+1=pk+2xk+1+1–2y
k+1

e2xk+1=2xk+2and2y
wher k+1=2yk−2.
4.
Det
ermi
nesy
mmet
rypoi
ntsi
ntheot
hersev
enoct
ant
s.
5.Mov
eeachcal
cul
atedpi
xel
posi
ti x,
on( y
)ont
otheci
rcul
arpat
hcent
er xc,
edat( yc)

andpl
ott
hecoor
dinat
eval
uesasf
oll
ows:
x=x+xc,
y=y+y
c

6.
Repeatst
eps3t
hrough5unt
ilx≥y
.

DEPARTMENTOFCSE,
BRCE 72
COMPUTERGRAPHI
CSANDVI
SUALI
ZATI
ON(
18CS62)

Code:
v
oiddr
aw_
pixel
(GLi
ntcx,
GLi
ntcy
)
{
gl
Col
or3f
(0.
5,0.
5,0.
0);
gl
Begi
n(GL_
POI
NTS)
;
gl
Ver
tex2i
(cx,
cy)
;
gl
End(
);
}

v
oidpl
otpi
xel
s(GLi
nth,
GLi
ntk,
GLi
ntx,
GLi
nty
)
{
dr
aw_
pixel
(x+h,
y+k)
;
dr
aw_
pixel
(-
x+h,
y+k)
;
dr
aw_
pixel
(x+h,
-y+k)
;
dr
aw_
pixel
(-
x+h,
-y+k)
;
dr
aw_
pixel
(y+h,
x+k)
;
dr
aw_
pixel
(-
y+h,
x+k)
;
dr
aw_
pixel
(y+h,
-x+k)
;
dr
aw_
pixel
(-
y+h,
-x+k)
;
}

v
oidci
rcl
e_dr
aw(
GLi
ntxc,
GLi
nty
c,GLi
ntr
)
{
GLi
ntd=1-
r,x=0,
y=r
;
whi
l
e(y
>x)
{
pl
otpi
xel
s(xc,
yc,
x,
y
);i
f(
d<0)d+=2*
x+3;
el
se
{

DEPARTMENTOFCSE,
BRCE 73
COMPUTERGRAPHI
CSANDVI
SUALI
ZATI
ON(
18CS62)

d+=2*
(x-
y)+5;
-
-y;

}
++x;
}
pl
otpi
xel
s(xc,
yc,
x,y
);
}

DEPARTMENTOFCSE,
BRCE 74

You might also like