Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
0lectron Gun 3 emits electron -eam .hich stri2es the phosphor coating to emit light/
Dept of CS0' C0C ,age A
Computer Graphics and Visualization 10CS65
Deflection ,lates 3 controls the direction of -eam/ )he output of the computer is con+erted -y
digital?to?analog con+erters o +oltages across & " y deflection plates/
8efresh 8ate 3 !n order to +ie. a flic2er free image' the image on the screen has to -e
retraced -y the -eam at a high rate %modern systems operate at
=5:z( ; types of refresh:
@oninterlaced display: ,i&els are displayed ro. -y ro. at the refresh rate/
!nterlaced display: dd ro.s and e+en ro.s are refreshed alternately/
Dept of CS0' C0C ,age 5
Computer Graphics and Visualization 10CS65
UNIT -*
T9E OPEN:L
1. 4it' t'e 'elp !f a /ia&ra$3 /e#"ri7e t'e !pen :L interfa"e. ()%n*+1*, -.
An#5 penG4 pro+ides a po.erful -ut primiti+e set of rendering commands' and all higher?le+el
dra.ing must -e done in terms of these commands/
)he penG4 #tility 4i-rary %G4#( contains se+eral routines that use lo.er?le+el penG4
commands to perform such tas2s as setting up matrices for specific +ie.ing orientations and
pro$ections' performing polygon tessellation' and rendering surfaces/ )his li-rary is pro+ided
as part of e+ery penG4 implementation/
9or e+ery .indo. system' there is a li-rary that e&tends the functionality of that .indo.
system to support penG4 rendering/ 9or machines that use the B Cindo. System' the
penG4 0&tension to the B Cindo. System %G4B( is pro+ided as an ad$unct to penG4/
G4B routines use the prefi& &l;/ 9or 1icrosoft Cindo.s' the CG4 routines pro+ide the
Cindo.s to penG4 interface/
)he penG4 #tility )ool2it %G4#)( is a .indo. system?independent tool2it' .ritten -y
1ar2 Dilgard' to hide the comple&ities of differing .indo. system A,!s/
;/ 4rite explanat!ry n!te# !n5 i, R:B "!l!r $!/el< ii, in/exe/ "!l!r $!/el. ()%n*+1*, 1.
An#5 Colors are indices into ta-les of 8G< +alues
8e*uires less memory
3 indices usually = -its
3 not as important no.
1emory ine&pensi+e
Dept of CS0' C0C ,age 6
Computer Graphics and Visualization 10CS65
@eed more colors for shading
!n inde&ed mode' colors are stored as indices/ !f there are 2 indices then there can -e 2n?1 colors
that could -e got -y com-ining red' green and -lue/ )his yields a huge color palette as compared
to the normal 8G< mode/
2. 4rite an !pen :L re"%r#i0e pr!&ra$ f!r *D #ierpin#8i &a#8et it' rele0ant "!$$ent#.
()%n*+1*, 1+.
An#5 Einclude Fstdaf&/hF
Einclude GG4Hglut/hI
typedef float
pointJ>KL HM initial
tetrahedron MH
point +JK NOO0/0' 0/0' 1/0P'
O0/0' 1/0' ?1/0P' O?1/0'
?1/0' ?1/0P' O1/0' ?1/0'
?1/0PPL
static G4float thetaJK N O0/0'0/0'0/0PL
int nL
+oid triangle% point a' point -' point c(
HM display one triangle using a line loop for .ire frame MH
O
gl<egin%G4Q,4RG@(L
glVerte&>f+%a(L
glVerte&>f+%-(L
glVerte&>f+%c(L
Dept of CS0' C0C ,age S
Computer Graphics and Visualization 10CS65
gl0nd%(L
P
+oid di+ideQtriangle%point a' point -' point c' int m(
O
HM triangle su-di+ision using +erte& num-ers
righthand rule applied to create out.ard pointing faces MH
point +1' +;'
+>L int $L
if%mI0(
O
for%$N0L $G>L $TT( +1J$KN%aJ$KT-J$K(H;L
for%$N0L $G>L $TT( +;J$KN%aJ$KTcJ$K(H;L
for%$N0L $G>L $TT( +>J$KN%-J$KTcJ$K(H;L
di+ideQtriangle%a' +1' +;' m?1(L
di+ideQtriangle%c' +;' +>' m?1(L
di+ideQtriangle%-' +>' +1' m?1(L
P
HM dra. triangle at end of recursion MH
else%triangle%a'-'c((L
P
+oid tetrahedron% int m(
O
HM Apply triangle su-di+ision to faces of tetrahedron/Gi+e
a different color to each face of the tetrahedronMH
glColor>f%1/0'0/0'0/0(L
di+ideQtriangle%+J0K' +J1K' +J;K' m(L
glColor>f%0/0'1/0'0/0(L
di+ideQtriangle%+J>K' +J;K' +J1K' m(L
glColor>f%0/0'0/0'1/0(L
di+ideQtriangle%+J0K' +J>K' +J1K' m(L
glColor>f%0/0'0/0'0/0(L
di+ideQtriangle%+J0K' +J;K' +J>K' m(L
P
Dept of CS0' C0C ,age =
Computer Graphics and Visualization 10CS65
+oid display%+oid(
O
glClear%G4QC48Q<#9908Q<!) U
G4QD0,):Q<#9908Q<!)(L gl4oad!dentity%(L
tetrahedron%n(L
gl9lush%(L
P
+oid my8eshape%int .' int h(
O
glVie.port%0' 0' .' h(L
gl1atri&1ode%G4Q,850C)!@(L
gl4oad!dentity%(L
HM code to maintain the aspect
ratioMH HM Chen .idth -ecomes less
than height' ad$ust the -ottom'top parameters
to maintain the aspect ratioMH
if %. GN h(
glrtho%?;/0' ;/0' ?;/0 M %G4float( h H %G4float(
.' ;/0 M %G4float( h H %G4float( .' ?10/0' 10/0(L
HM Chen height -ecomes less
than .idth' ad$ust the left'right parameters to
maintain the aspect ratioMH
else
glrtho%?;/0 M %G4float( . H %G4float( h'
;/0 M %G4float( . H %G4float( h' ?;/0' ;/0'
?10/0' 10/0(L
gl1atri&1ode%G4Q1D04V!0C(L
glut,ost8edisplay%(L
P
+oid main%int argc' char MMarg+(
O
printf%Fenter the no of di+ision :
F(L scanf%FVdF'"n(L
glut!nit%"argc' arg+(L
glut!nitDisplay1ode%G4#)QS!@G40 U G4#)Q8G< U G4#)QD0,):(L
glut!nitCindo.Size%6A0' A=0(L
glutCreateCindo.%F>D Gas2etF(L
glut8eshape9unc%my8eshape(L
Dept of CS0' C0C ,age W
Computer Graphics and Visualization 10CS65
glutDisplay9unc%display(L
gl0na-le%G4QD0,):Q)0S)(L
glClearColor %1/0' 1/0' 1/0' 1/0(L
glut1ain4oop%(L
P
-. 4it' a neat /ia&ra$3 /i#"%## t'e "!l!r f!r$ati!n. Explain t'e a//iti0e an/ #%7tra"ti0e
"!l!r#3 in/exe/ "!l!r an/ "!l!r #!li/ "!n"ept. (De"*+11, 1*.
An#5
A +isi-le color can -e characterized -y the function C%X(
)ristimulus +alues 3 responses of the > types of cones to the colors/
> color theory 3 6!f ; colors produce the same tristimulus +alues' then they are +isually
indistinguisha-le/7
Additi+e color model 3 Adding together the primary colors to get the percie+ed colors/
0/g/ C8)/
Su-tracti+e color model 3 Colored pigments remo+e color components from light that is
stri2ing the surface/ :ere the primaries are the complimentary colors : cyan' magenta and
yello.
R:B "!l!r
0ach color component is stored separately in the frame
-uffer #sually = -its per component in -uffer
@ote in &lC!l!r2f the color +alues range from 0/0 %none( to 1/0 %all(' .hereas in
&lC!l!r2%7 the +alues range from 0 to ;55
)he color as set -y &lC!l!r -ecomes part of the state and .ill -e used until changed
Dept of CS0' C0C ,age 10
Computer Graphics and Visualization 10CS65
3 Colors and other attri-utes are not part of the o-$ect -ut are assigned .hen the
o-$ect is rendered
Ce can create conceptual vertex colors -y code such as
&lC!l!r
&lVertex
&lC!l!r
&lVertex
8G<A color system :
Scale: ,f N S ` ,
&
f
N s& M &
o
y
f
N sy M y
o
*. 4'at i# "!n"atenati!n tran#f!r$ati!n= Explain r!tati!n a7!%t a fixe/ p!int. ()%n*+1*,
>.
Ans: 8otate a house a-out the origin
8otate the house a-out one of its corners
translate so that a corner of the house is at the origin
rotate the house a-out the origin
translate so that the corner returns to its original position
Dept of CS0' C0C ,age >;
Computer Graphics and Visualization 10CS65
2. 4'at are J%aterni!n#= 4it' an exa$ple3 explain it# $at'e$ati"al repre#entati!n#.
(De"*+11, 1+.
Ans: A *uaternion is an element of a A dimensional +ector?space/ !t_s defined as . T &i T y$ T
z2 .here i' $ and 2 are imaginary num-ers/ Alternati+ely' a *uaternion is .hat you get .hen
you add a scalar and a >d +ector/ )he math -ehind *uaternions is only slightly harder than the
math -ehind +ectors/
void Camera::movex(float xmmod)
{
pos += rotation * Vector3(xmmod, 0.0f, 0.0f);
else
trian5le (a,0,c); /* dra4 trian5le at end of rec%rsion */
void m!init ()
{
<8float matCspec%lar=>={0.B, 0.0, 0.0,
&.0; <8float matCdiff%se=>={&.0, 0.0, 0.0,
&.0; <8float matCam0ient=>={&.0, 0.0, 0.0,
&.0; <8float matCs1ininess={&00.0;
<8float li51tCam0ient=>={0.0, 0.0, 0.0, &.0;
<8float li51tCdiff%se=>={&.0, &.0, &.0, &.0;
<8float li51tCspec%lar=>={&.0, &.0, &.0, &.0;
/* set %p am0ient, diff%se, and spec%lar components for li51t 0 */
5l8i51tfv (<8C8(<J30, <8CRGH(*N3, li51tCam0ient);
5l8i51tfv (<8C8(<J30, <8CF(MM7L*, li51tCdiff%se);
5l8i51tfv (<8C8(<J30, <8CL'*C78R+, li51tCspec%lar);
/* define material proerties for front face of all pol!5ons */
5lGaterialfv (<8CM+)N3, <8CL'*C78R+, matCspec%lar);
5lGaterialfv (<8CM+)N3, <8CRGH(*N3, matCam0ient);
5lGaterialfv (<8CM+)N3, <8CF(MM7L*, matCdiff%se);
5lGaterialf (<8CM+)N3, <8CLJ(N(N*LL,
matCs1ininess); 5l*na0le (<8CLG))3J); /*ena0le
smoot1 s1adin5 */ 5l*na0le (<8C8(<J3(N<); /* ena0le
li51tin5 */ 5l*na0le (<8C8(<J30); /* ena0le li51t 0
*/ 5l*na0le (<8CF*'3JC3*L3); /* ena0le # 0%ffer */
5lClearColor (&.0, &.0, &.0, &.0);
5lColor3f (0.0, 0.0, 0.0);