Sei sulla pagina 1di 34

www.BookSpar.

com

Computer Graphics and Visualization Lab

Computer Graphics and Visualization


COURSE OU L!"E

#eek "o
1.

$ro%rams to be co&ered Introduction to OpenGL. Practicing simple programs using OpenGL. Guidelines to carry out mini projects. Program 1 Programs 2 Program 3,8 Program 4 heor' test week Program 5 Program ,! Program ",1# heor' test week $ini Project $ini Project $ini Project heor' test week La% Internals

2. 3. 4. 5. . !. 8. ". 1#. 11. 12. 13. 14. 15.

1 &&&.'oo(spar.com ) *e%site +or ,tudents ) -./ 0 1otes 0 2uestion Papers

www.BookSpar.com

Computer Graphics and Visualization Lab L!S O( $ROGR)*S !" $)R )

1. Program to recursi3ely su%di3ide a tetra4edron to +rom 35 ,ierpins(i gas(et. .4e num%er o+ recursi3e steps is to %e speci+ied %y t4e user. 2. Program to implement Liang0'ars(y line clipping algorit4m. 3. Program to dra& a color cu%e and spin it using OpenGL trans+ormation matrices. 4. Program to create a 4ouse li(e +igure and rotate it a%out a gi3en +i6ed point using OpenGL +unctions. 5. Program to implement t4e 7o4en0,ut4erland line0clipping algorit4m. $a(e pro3ision to speci+y t4e input line, &indo& +or clipping and 3ie& port +or displaying t4e clipped image. . Program to create a cylinder and a parallel piped %y e6truding a circle and 8uadrilateral respecti3ely. 9llo& t4e user to speci+y t4e circle and 8uadrilateral. !. Program using OpenGL +unctions, to dra& a simple s4aded scene consisting o+ a tea pot on a ta%le. 5e+ine suita%ly t4e position and properties o+ t4e lig4t source along &it4 t4e properties o+ t4e sur+aces o+ t4e solid o%ject used in t4e scene. 8. Program to dra& a color cu%e and allo& t4e user to mo3e t4e camera suita%ly to e6periment &it4 perspecti3e 3ie&ing. /se OpenGL +unctions. ". Program to +ill any gi3en polygon using scan0line area +illing algorit4m. :/se appropriate data structures.; 1#. Program to display a set o+ 3alues <+ij= as a rectangular mes4.

2 &&&.'oo(spar.com ) *e%site +or ,tudents ) -./ 0 1otes 0 2uestion Papers

www.BookSpar.com

Computer Graphics and Visualization Lab

Simple steps used to e+ecute an open%l pro%ram in ,e&-Cpp.


Step .> Install 5e307pp so+t&are. 9longside you need a +older glutming. Step /> $a(e sure ?7>@*indo&s@system32 ? +older 4as a +ile ? glut32.dll A. Step 0> Inside ?7>@ 5e307pp@include@GL ? loo( +or ?glut.4 ?. Step 1> Inside ?7>@ 5e307pp@li% ? loo( +or a +ile ?li%glut32.aA : ta(e all t4e a%o3e 3 +iles +rom glutming +older Step 2> 7reate a +older inside 5 dri3e say ?GLprojectA. Step 3> In de30cpp, go +or t4e ne& project :7 project; and sa3e it in a%o3e +older, &it4 a suita%le name. Step 4> Go +or a ne& source +ile, adding to t4e project created in step . Step 5> ,a3e t4at +ile &it4 a .c e6tension. Step 6> Goto project projectoptionsparametersadd library or object and add t4e +iles ? li%opengl32.aA, ?li%glu32.aA, ?li%glut32.aA +rom 7>@5e3.7pp@li% Step .7> &rite t4e code, sa3e it, compile and t4en run. Bou must get proper output.

3 &&&.'oo(spar.com ) *e%site +or ,tudents ) -./ 0 1otes 0 2uestion Papers

www.BookSpar.com

Computer Graphics and Visualization Lab

$ROGR)*S

4 &&&.'oo(spar.com ) *e%site +or ,tudents ) -./ 0 1otes 0 2uestion Papers

www.BookSpar.com

Computer Graphics and Visualization Lab

.. $ro%ram to recursi&el' subdi&ide a tetrahedron to 8orm 0, Sierpinski %asket. number o8 recursi&e steps is to be speci8ied b' the user.

he

Ob9ecti&e: In t4is program, students &ill learn to create &indo& and to dra& 35 ,ierpins(i gas(et using openGL +unctions. $ro%ram: Cinclude DGLEglut.4F Cinclude Dstdli%.4F CincludeDstdio.4F typede+ +loat pointG3HI point 3GHJ< <#.#,#.#,1.#=, <#.#,#."43,0#.33=, <0#.81 ,0#.4!1,0#.33=, <#.81 ,0#.4!1,#.33==I int nI 3oid triangle:point a,point %,point c; < gl'egin:GLKPOLBGO1;I gl1ormal3+3:a;I gl-erte63+3:a;I gl-erte63+3:%;I gl-erte63+3:c;I glLnd:;I = 3oid di3ideKtri:point a,point %,point c,int m; < point 31,32,33I int jI i+ :mF#; < +or:jJ#IjD3IjMM; 31GjHJ:aGjHM%GjH;E2I +or:jJ#IjD3IjMM; 32GjHJ:aGjHMcGjH;E2I +or:jJ#IjD3IjMM; 33GjHJ:%GjHMcGjH;E2I di3ideKtri:a,31,32,m01;I di3ideKtri:c,32,33,m01;I di3ideKtri:%,33,31,m01;I 5 &&&.'oo(spar.com ) *e%site +or ,tudents ) -./ 0 1otes 0 2uestion Papers

www.BookSpar.com = else triangle:a,%,c;I =

Computer Graphics and Visualization Lab

3oid tetra4edron:int m; < gl7olor3+:1.#,#.#,#.#;I di3ideKtri:3G#H,3G1H,3G2H,m;I gl7olor3+:#.#,1.#,#.#;I di3ideKtri:3G3H,3G2H,3G1H,m;I gl7olor3+:#.#,#.#,1.#;I di3ideKtri:3G#H,3G3H,3G1H,m;I gl7olor3+:#.#,#.#,#.#;I di3ideKtri:3G#H,3G2H,3G3H,m;I = 3oid display:3oid; < gl7lear:GLK7OLONK'/OOLNK'I.)GLK5LP.PK'/OOLNK'I.;I glLoadIdentity:;I tetra4edron:n;I glOlus4:;I = 3oid myNes4ape:int &,int 4; < gl-ie&port:#,#,&,4;I gl$atri6$ode:GLKPNOQL7.IO1;I glLoadIdentity:;I i+:&DJ4; glOrt4o:02.#,2.#,02.#R:GL+loat;4E:GL+loat;&,2.#R:GL+loat;4E:GL+loat;&,0 1#.#,1#.#;I else glOrt4o:02.#R:GL+loat;&E:GL+loat;4,2.#R:GL+loat;&E:GL+loat;4,02.#,2.#,01#.#,1#.#;I gl$atri6$ode:GLK$O5LL-IL*;I glutPostNedisplay:;I = int main:int argc,c4ar RRarg3; < print+:?Lnter t4e num%er o+ recursi3e steps you &ant@nA;I scan+:?SdA, Tn;I glutInit:Targc,arg3;I glutInit5isplay$ode:GL/.K,I1GLL)GL/.KNG')GL/.K5LP.P;I

&&&.'oo(spar.com ) *e%site +or ,tudents ) -./ 0 1otes 0 2uestion Papers

www.BookSpar.com glutInit*indo&,iUe:5##,5##;I glut7reate*indo&:V3d gas(etV;I glutNes4apeOunc:myNes4ape;I glut5isplayOunc:display;I glLna%le:GLK5LP.PK.L,.;I gl7lear7olor:1.#,1.#,1.#,1.#;I glut$ainLoop:;I = Output:

Computer Graphics and Visualization Lab

Vi&a ;uestions: 1. L6plain all t4e OpenGL +unctions used in t4is programW 2. *4at is t4e principle o+ ,ierpins(i gas(etW 3. 5i++erence %et&een additi3e and su%tracti3e colorW 4. *4at is t4e Grap4ics 9rc4itecture used in OpenGLW 5. *4at is NasterisationW

2. Program to implement Liang0'ars(y line clipping algorit4m.


Ob9ecti&e : In t4is program t4e students &ill learn to implement Liang0'ars(y Line 7lipping 9lgorit4m &it4 *indo& to 3ie&port $apping &it4 OPL1GL 9PI

! &&&.'oo(spar.com ) *e%site +or ,tudents ) -./ 0 1otes 0 2uestion Papers

www.BookSpar.com

Computer Graphics and Visualization Lab

$ro%ram Cinclude Dstdio.4F Cinclude DGLEglut.4F Cde+ine true 1 Cde+ine +alse # dou%le 6minJ5#,yminJ5#, 6ma6J1##,yma6J1##I EE *indo& %oundaries dou%le 63minJ2##,y3minJ2##,63ma6J3##,y3ma6J3##I EE -ie&port %oundaries EEint 61, 62, y1, y2I int cliptest:dou%le p, dou%le 8, dou%le Rt1, dou%le Rt2; < dou%le tI i+:p; tJ8EpI EE to c4ec( &4et4er p i+:p D #.#; EE potentially entry point, update te < i+: t F Rt1; Rt1JtI i+: t F Rt2; return:+alse;I EE line portion is outside = else i+:p F #.#; EE Potentially lea3ing point, update tl < i+: t D Rt2; Rt2JtI i+: t D Rt1; return:+alse;I EE line portion is outside = else i+:p JJ #.#; < i+: 8 D #.#; return:+alse;I EE line parallel to edge %ut outside = return:true;I = 3oid Liang'ars(yLine7lip9nd5ra& :dou%le 6#, dou%le y#,dou%le 61, dou%le y1; < dou%le d6J6106#, dyJy10y#, teJ#.#, tlJ1.#I i+:cliptest:0d6,6#06min,Tte,Ttl;; EE inside test &rt le+t edge i+:cliptest:d6,6ma606#,Tte,Ttl;; EE inside test &rt rig4t edge i+:cliptest:0dy,y#0ymin,Tte,Ttl;; EE inside test &rt %ottom edge i+:cliptest:dy,yma60y#,Tte,Ttl;; EE inside test &rt top edge < i+: tl D 1.# ; < 61 J 6# M tlRd6I y1 J y# M tlRdyI = 8 &&&.'oo(spar.com ) *e%site +or ,tudents ) -./ 0 1otes 0 2uestion Papers

www.BookSpar.com i+: te F #.# ; < 6# J 6# M teRd6I y# J y# M teRdyI =

Computer Graphics and Visualization Lab

EE *indo& to 3ie&port mappings dou%le s6J:63ma6063min;E:6ma606min;I EE ,cale parameters dou%le syJ:y3ma60y3min;E:yma60ymin;I dou%le 36#J63minM:6#06min;Rs6I dou%le 3y#Jy3minM:y#0ymin;RsyI dou%le 361J63minM:6106min;Rs6I dou%le 3y1Jy3minM:y10ymin;RsyI EEdra& a red colored 3ie&port gl7olor3+:1.#, #.#, #.#;I gl'egin:GLKLI1LKLOOP;I gl-erte62+:63min, y3min;I gl-erte62+:63ma6, y3min;I gl-erte62+:63ma6, y3ma6;I gl-erte62+:63min, y3ma6;I glLnd:;I gl7olor3+:#.#,#.#,1.#;I EE dra& %lue colored clipped line gl'egin:GLKLI1L,;I gl-erte62d :36#, 3y#;I gl-erte62d :361, 3y1;I glLnd:;I = =EE end o+ line clipping 3oid display:; < dou%le 6#J #,y#J2#,61J8#,y1J12#I gl7lear:GLK7OLONK'/OOLNK'I.;I EEdra& t4e line &it4 red color gl7olor3+:1.#,#.#,#.#;I gl'egin:GLKLI1L,;I gl-erte62d :6#, y#;I gl-erte62d :61, y1;I glLnd:;I EEdra& a %lue colored &indo& gl7olor3+:#.#, #.#, 1.#;I gl'egin:GLKLI1LKLOOP;I gl-erte62+:6min, ymin;I gl-erte62+:6ma6, ymin;I gl-erte62+:6ma6, yma6;I gl-erte62+:6min, yma6;I glLnd:;I Liang'ars(yLine7lip9nd5ra&:6#,y#,61,y1;I glOlus4:;I = " &&&.'oo(spar.com ) *e%site +or ,tudents ) -./ 0 1otes 0 2uestion Papers

www.BookSpar.com

Computer Graphics and Visualization Lab

3oid myinit:; < gl7lear7olor:1.#,1.#,1.#,1.#;I gl7olor3+:1.#,#.#,#.#;I glPoint,iUe:1.#;I gl$atri6$ode:GLKPNOQL7.IO1;I glLoadIdentity:;I gluOrt4o25:#.#,4"".#,#.#,4"".#;I = int main:int argc, c4arRR arg3; < EEprint+:VLnter Lnd points>V;I EEscan+:VSdSdSdSdV, T61,T62,Ty1,Ty2;I glutInit:Targc,arg3;I glutInit5isplay$ode:GL/.K,I1GLL)GL/.KNG';I glutInit*indo&,iUe:5##,5##;I glutInit*indo&Position:#,#;I glut7reate*indo&:VLiang 'ars(y Line 7lipping 9lgorit4mV;I glut5isplayOunc:display;I myinit:;I glut$ainLoop:;I = Output

Vi&a ;uestions> 1. *4at do you mean %y clippingW 2. Po& is Liang0'ars(y clipping di++erent +rom 7o4en,ut4erland 7lipping 9lgorit4mW 3. Po& do you set t4e color attri%utes in OpenglW 4. *hat is the command 8or clearscreen< 5. *4at is L3ent call%ac( +unctionW

1# &&&.'oo(spar.com ) *e%site +or ,tudents ) -./ 0 1otes 0 2uestion Papers

www.BookSpar.com

Computer Graphics and Visualization Lab

0. $ro%ram to draw a color cube and spin it usin% openGL trans8ormation matrices. Ob9ecti&e : In t4is program t4e students &ill learn to dra& a color cu%e and spin it using OpenGL +unctions. Cinclude DGLEglut.4F Cinclude Dstdio.4F Cinclude Dstdli%.4F GL+loat 3erticesG HJ< 01.#,01.#,01.#, 1.#,01.#,01.#, 1.#, 1.#,01.#, 0 1.#, 1.#,01.#, 0 1.#,01.#, 1.#, 1.#,01.#, 1.#, 1.#, 1.#, 1.#, 01.#, 1.#, 1.# =I normalsG HJ< 01.#,01.#,01.#, 1.#,01.#,01.#, 1.#, 1.#,01.#, 01.#, 1.#,01.#, 01.#,01.#, 1.#, 1.#,01.#, 1.#, 1.#, 1.#, 1.#, 01.#, 1.#, 1.# =I colorsG HJ< #.#,#.#,#.#, 1.#,#.#,#.#, 1.#,1.#,#.#, #.#,1.#,#.#, #.#,#.#,1.#, 1.#,#.#,1.#, 1.#,1.#,1.#, #.#,1.#,1.#=I

GL+loat

GL+loat

GLu%yte cu%eIndicesGHJ<#,3,2,1, 2,3,!, , #,4,!,3, 1,2, ,5, 4,5, ,!, #,1,5,4 =I static GL+loat t4etaGHJ<#.#,#.#,#.#=I static GLint a6isJ2I 3oid display:3oid; 11 &&&.'oo(spar.com ) *e%site +or ,tudents ) -./ 0 1otes 0 2uestion Papers

www.BookSpar.com <

Computer Graphics and Visualization Lab

gl7lear:GLK7OLONK'/OOLNK'I.)GLK5LP.PK'/OOLNK'I.;I glLoadIdentity:;I glNotate+:t4etaG#H,1.#,#.#,#.#;I glNotate+:t4etaG1H,#.#,1.#,#.#;I glNotate+:t4etaG2H,#.#,#.#,1.#;I gl5ra&Llements:GLK2/95,,24,GLK/1,IG1L5K'B.L,cu%eIndices;I glOlus4:;I glut,&ap'u++ers:;I = 3oid mouse:int %tn,int state,int 6,int y; < i+:%tnJJGL/.KLLO.K'/..O1 TT stateJJGL/.K5O*1;a6isJ#I i+:%tnJJGL/.KNIGP.K'/..O1 TT stateJJGL/.K5O*1; a6isJ1I i+:%tnJJGL/.K$I55LLK'/..O1 TT stateJJGL/.K5O*1; a6isJ2I = 3oid spincu%e:; < t4etaGa6isHMJ2.#I i+:t4etaGa6isHF3 #.#; t4etaGa6isH0J3 #.#I glutPostNedisplay:;I = 3oid myNes4ape:int &,int 4; < gl-ie&port:#,#,&,4;I gl$atri6$ode:GLKPNOQL7.IO1;I glLoadIdentity:;I i+:&DJ4; glOrt4o:02.#,2.#,02.#R:GL+loat;4E:GL+loat;&,2.#R:GL+loat;4E:GL+loat;&,1#.#,1#.#;I else glOrt4o:02.#R:GL+loat;&E:GL+loat;4,2.#R:GL+loat;&E:GL+loat;4,02.#,2.#,01#.#,1#.#;I gl$atri6$ode:GLK$O5LL-IL*;I = int main:int argc,c4ar RRarg3; < glutInit:Targc,arg3;I glutInit5isplay$ode:GL/.K5O/'LL)GL/.KNG')GL/.K5LP.P;I glutInit*indo&,iUe:5##,5##;I glut7reate*indo&:Vcolor cuceV;I glutNes4apeOunc:myNes4ape;I glut5isplayOunc:display;I glut$ouseOunc:mouse;I glutIdleOunc:spincu%e;I glLna%le:GLK5LP.PK.L,.;I 12 &&&.'oo(spar.com ) *e%site +or ,tudents ) -./ 0 1otes 0 2uestion Papers

www.BookSpar.com

Computer Graphics and Visualization Lab

glLna%le7lient,tate:GLK7OLONK9NN9B;I glLna%le7lient,tate:GLK-LN.LXK9NN9B;I glLna%le7lient,tate:GLK1ON$9LK9NN9B;I gl-erte6Pointer:3,GLKOLO9.,#,3ertices;I gl7olorPointer:3,GLKOLO9.,#,colors;I gl1ormalPointer:GLKOLO9.,#,normals;I gl7olor3+:1.#,1.#,1.#;I glut$ainLoop:;I = Output

Vi&a ;uestions> 1. *4at are 3erte6 arraysW 2. Po& are t4e +aces o+ t4e color cu%e modeledW 3. Po& do you consider t4e in&ard and out&ard pointing o+ t4e +acesW 4. L6plain t4e OpenGL +unction used to rotate t4e color cu%eW 5. *4at is t4e di++erence %et&een 25 and 35 ort4ograp4ic projection statementsW 1. $ro%ram to create a house like 8i%ure and rotate about a %i&en 8i+ed point usin% openGL 8unctions. Ob9ecti&e: In t4is program t4e students &ill learn to dra& a 4ouse and use trans+ormation +unctions o+ OpenGL to rotate it a%out a +i6ed point. Cinclude Dstdli%.4F Cinclude Dstdio.4F Cinclude Dmat4.4F Cinclude DGLEglut.4F GL+loat 4ouseG3HG"HJ< <1##.#,1##.#,1!5.#,25#.#,25#.#,15#.#,15#.#,2##.#,2##.#=, <1##.#,3##.#,4##.#,3##.#,1##.#,1##.#,15#.#,15#.#,1##.#=, <1.#, 1.#, 1.#, 1.#, 1.#, 1.#, 1.#, 1.#, 1.# = =I GL+loat rotKmatG3HG3HJ<<#=,<#=,<#==I GL+loat resultG3HG"HJ<<#=,<#=,<#==I GL+loat 4J1##.#I GL+loat (J1##.#,t4etaI 13 &&&.'oo(spar.com ) *e%site +or ,tudents ) -./ 0 1otes 0 2uestion Papers

www.BookSpar.com

Computer Graphics and Visualization Lab

3oid multiply:; < int i,j,lI +or:iJ#IiD3IiMM; +or:jJ#IjD"IjMM; < resultGiHGjHJ#I +or:lJ#IlD3IlMM; resultGiHGjHJresultGiHGjHMrotKmatGiHGlHR4ouseGlHGjHI = = 3oid rotate:; < GL+loat m,nI mJ04R:cos:t4eta;01;M(R:sin:t4eta;;I nJ0(R:cos:t4eta;01;04R:sin:t4eta;;I rotKmatG#HG#HJcos:t4eta;I rotKmatG#HG1HJ0sin:t4eta;I rotKmatG#HG2HJmI rotKmatG1HG#HJsin:t4eta;I rotKmatG1HG1HJcos:t4eta;I rotKmatG1HG2HJnI rotKmatG2HG#HJ#I rotKmatG2HG1HJ#I rotKmatG2HG2HJ1I multiply:;I = 3oid dra&K4ouse:; < gl7olor3+:#.#,#.#,1.#;I gl'egin:GLKLI1LKLOOP;I gl-erte62+:4ouseG#HG#H,4ouseG1HG#H;I gl-erte62+:4ouseG#HG1H,4ouseG1HG1H;I gl-erte62+:4ouseG#HG3H,4ouseG1HG3H;I gl-erte62+:4ouseG#HG4H,4ouseG1HG4H;I glLnd:;I gl7olor3+:1.#,#.#,#.#;I gl'egin:GLKLI1LKLOOP;I gl-erte62+:4ouseG#HG5H,4ouseG1HG5H;I gl-erte62+:4ouseG#HG H,4ouseG1HG H;I gl-erte62+:4ouseG#HG!H,4ouseG1HG!H;I gl-erte62+:4ouseG#HG8H,4ouseG1HG8H;I glLnd:;I gl7olor3+:#.#,#.#,1.#;I gl'egin:GLKLI1LKLOOP;I gl-erte62+:4ouseG#HG1H,4ouseG1HG1H;I gl-erte62+:4ouseG#HG2H,4ouseG1HG2H;I gl-erte62+:4ouseG#HG3H,4ouseG1HG3H;I 14 &&&.'oo(spar.com ) *e%site +or ,tudents ) -./ 0 1otes 0 2uestion Papers

www.BookSpar.com glLnd:;I = 3oid dra&rotated4ouse:; < gl7olor3+:#.#,#.#,1.#;I gl'egin:GLKLI1LKLOOP;I gl-erte62+:resultG#HG#H,resultG1HG#H;I gl-erte62+:resultG#HG1H,resultG1HG1H;I gl-erte62+:resultG#HG3H,resultG1HG3H;I gl-erte62+:resultG#HG4H,resultG1HG4H;I glLnd:;I gl7olor3+:1.#,#.#,#.#;I gl'egin:GLKLI1LKLOOP;I gl-erte62+:resultG#HG5H,resultG1HG5H;I gl-erte62+:resultG#HG H,resultG1HG H;I gl-erte62+:resultG#HG!H,resultG1HG!H;I gl-erte62+:resultG#HG8H,resultG1HG8H;I glLnd:;I gl7olor3+:#.#,#.#,1.#;I gl'egin:GLKLI1LKLOOP;I gl-erte62+:resultG#HG1H,resultG1HG1H;I gl-erte62+:resultG#HG2H,resultG1HG2H;I gl-erte62+:resultG#HG3H,resultG1HG3H;I glLnd:;I = 3oid display:; < gl7lear:GLK7OLONK'/OOLNK'I.;I dra&K4ouse:;I rotate:;I dra&rotated4ouse:;I glOlus4:;I = 3oid myinit:; < gl7lear7olor:1.#,1.#,1.#,1.#;I gl7olor3+:1.#,#.#,#.#;I glPoint,iUe:1.#;I gl$atri6$ode:GLKPNOQL7.IO1;I glLoadIdentity:;I gluOrt4o25:#.#,5##.#,#.#,5##.#;I = int main:int argc,c4ar Rarg3GH; < print+:Venter t4e rotation angle@nV;I scan+:VS+V,Tt4eta;I

Computer Graphics and Visualization Lab

15 &&&.'oo(spar.com ) *e%site +or ,tudents ) -./ 0 1otes 0 2uestion Papers

www.BookSpar.com

Computer Graphics and Visualization Lab

glutInit:Targc,arg3;I glutInit5isplay$ode:GL/.K,I1GLL)GL/.KNG';I glutInit*indo&,iUe:5##,5##;I glutInit*indo&Position:#,#;I glut7reate*indo&:V4ouse rotationV;I glut5isplayOunc:display;I myinit:;I glut$ainLoop:;I = Output

Vi&a ;uestions> 1. *4at is trans+ormationW 2. L6plain t4e OpenGL +unctions used +or translation, rotation and scalingW 3. *4at is t4e order o+ trans+ormationW 4. ,tate t4e di++erence %et&een model3ie& and projectionW 5. *4at is Pomogeneous0coordinate representationW

2. Cohen-Sutherland Line Clippin% )l%orithm with #indow to &iewport *appin% usin% OpenGL )$!. Ob9ecti&e: In t4is program t4e students &ill learn to implement 7o4en0,ut4erland Line 7lipping 9lgorit4m &it4 *indo& to 3ie&port $apping &it4 OpenGL 9PI. Cinclude Dstdio.4F Cinclude DGLEglut.4F Cde+ine outcode int Cde+ine true 1 Cde+ine +alse # dou%le 6minJ5#,yminJ5#, 6ma6J1##,yma6J1##I EE *indo& %oundaries dou%le 63minJ2##,y3minJ2##,63ma6J3##,y3ma6J3##I EE -ie&port %oundaries EEint 61, 62, y1, y2I 1 &&&.'oo(spar.com ) *e%site +or ,tudents ) -./ 0 1otes 0 2uestion Papers

www.BookSpar.com EE%it codes +or t4e rig4t, le+t, top, T %ottom const int NIGP. J 8I const int LLO. J 2I const int .OP J 4I const int 'O..O$ J 1I EEused to compute %it codes o+ a point outcode 7omputeOut7ode :dou%le 6, dou%le y;I

Computer Graphics and Visualization Lab

EE7o4en0,ut4erland clipping algorit4m clips a line +rom EEP# J :6#, y#; to P1 J :61, y1; against a rectangle &it4 EEdiagonal +rom :6min, ymin; to :6ma6, yma6;. 3oid 7o4en,ut4erlandLine7lip9nd5ra& :dou%le 6#, dou%le y#,dou%le 61, dou%le y1; < EEOutcodes +or P#, P1, and &4ate3er point lies outside t4e clip rectangle outcode outcode#, outcode1, outcodeOutI %ool accept J +alse, done J +alseI EEcompute outcodes outcode# J 7omputeOut7ode :6#, y#;I outcode1 J 7omputeOut7ode :61, y1;I do< i+ :Y:outcode# ) outcode1;; EElogical or is # .ri3ially accept T e6it < accept J trueI done J trueI = else i+ :outcode# T outcode1; EElogical and is not #. .ri3ially reject and e6it done J trueI else < EE+ailed %ot4 tests, so calculate t4e line segment to clip EE+rom an outside point to an intersection &it4 clip edge dou%le 6, yI EE9t least one endpoint is outside t4e clip rectangleI pic( it. outcodeOut J outcode#W outcode#> outcode1I EE1o& +ind t4e intersection pointI EEuse +ormulas y J y# M slope R :6 0 6#;, 6 J 6# M :1Eslope;R :y 0 y#; i+ :outcodeOut T .OP; EEpoint is a%o3e t4e clip rectangle < 6 J 6# M :61 0 6#; R :yma6 0 y#;E:y1 0 y#;I y J yma6I = else i+ :outcodeOut T 'O..O$; EEpoint is %elo& t4e clip rectangle < 6 J 6# M :61 0 6#; R :ymin 0 y#;E:y1 0 y#;I y J yminI 1! &&&.'oo(spar.com ) *e%site +or ,tudents ) -./ 0 1otes 0 2uestion Papers

www.BookSpar.com

Computer Graphics and Visualization Lab = else i+ :outcodeOut T NIGP.; EEpoint is to t4e rig4t o+ clip rectangle < y J y# M :y1 0 y#; R :6ma6 0 6#;E:61 0 6#;I 6 J 6ma6I = else EEpoint is to t4e le+t o+ clip rectangle < y J y# M :y1 0 y#; R :6min 0 6#;E:61 0 6#;I 6 J 6minI = EE1o& &e mo3e outside point to intersection point to clip EEand get ready +or ne6t pass. i+ :outcodeOut JJ outcode#; < 6# J 6I y# J yI outcode# J 7omputeOut7ode :6#, y#;I = else < 61 J 6I y1 J yI outcode1 J 7omputeOut7ode :61, y1;I =

= =&4ile :Ydone;I i+ :accept; < EE *indo& to 3ie&port mappings dou%le s6J:63ma6063min;E:6ma606min;I EE ,cale parameters dou%le syJ:y3ma60y3min;E:yma60ymin;I dou%le 36#J63minM:6#06min;Rs6I dou%le 3y#Jy3minM:y#0ymin;RsyI dou%le 361J63minM:6106min;Rs6I dou%le 3y1Jy3minM:y10ymin;RsyI EEdra& a red colored 3ie&port gl7olor3+:1.#, #.#, #.#;I gl'egin:GLKLI1LKLOOP;I gl-erte62+:63min, y3min;I gl-erte62+:63ma6, y3min;I gl-erte62+:63ma6, y3ma6;I gl-erte62+:63min, y3ma6;I glLnd:;I gl7olor3+:#.#,#.#,1.#;I EE dra& %lue colored clipped line gl'egin:GLKLI1L,;I gl-erte62d :36#, 3y#;I gl-erte62d :361, 3y1;I glLnd:;I 18 &&&.'oo(spar.com ) *e%site +or ,tudents ) -./ 0 1otes 0 2uestion Papers

www.BookSpar.com = =

Computer Graphics and Visualization Lab

EE7ompute t4e %it code +or a point :6, y; using t4e clip rectangle EE%ounded diagonally %y :6min, ymin;, and :6ma6, yma6; outcode 7omputeOut7ode :dou%le 6, dou%le y; < outcode code J #I i+ :y F yma6; EEa%o3e t4e clip &indo& code )J .OPI else i+ :y D ymin; EE%elo& t4e clip &indo& code )J 'O..O$I i+ :6 F 6ma6; EEto t4e rig4t o+ clip &indo& code )J NIGP.I else i+ :6 D 6min; EEto t4e le+t o+ clip &indo& code )J LLO.I return codeI = 3oid display:; < dou%le 6#J12#,y#J1#,61J4#,y1J13#I gl7lear:GLK7OLONK'/OOLNK'I.;I EEdra& t4e line &it4 red color gl7olor3+:1.#,#.#,#.#;I EE%res:12#,2#,34#,25#;I gl'egin:GLKLI1L,;I gl-erte62d :6#, y#;I gl-erte62d :61, y1;I gl-erte62d : #,2#;I gl-erte62d :8#,12#;I glLnd:;I EEdra& a %lue colored &indo& gl7olor3+:#.#, #.#, 1.#;I gl'egin:GLKLI1LKLOOP;I gl-erte62+:6min, ymin;I gl-erte62+:6ma6, ymin;I gl-erte62+:6ma6, yma6;I gl-erte62+:6min, yma6;I glLnd:;I 7o4en,ut4erlandLine7lip9nd5ra&:6#,y#,61,y1;I 7o4en,ut4erlandLine7lip9nd5ra&: #,2#,8#,12#;I glOlus4:;I = 3oid myinit:; < gl7lear7olor:1.#,1.#,1.#,1.#;I gl7olor3+:1.#,#.#,#.#;I 1" &&&.'oo(spar.com ) *e%site +or ,tudents ) -./ 0 1otes 0 2uestion Papers

www.BookSpar.com glPoint,iUe:1.#;I gl$atri6$ode:GLKPNOQL7.IO1;I glLoadIdentity:;I gluOrt4o25:#.#,4"".#,#.#,4"".#;I = int main:int argc, c4arRR arg3; <

Computer Graphics and Visualization Lab

EEprint+:VLnter Lnd points>V;I EEscan+:VSdSdSdSdV, T61,T62,Ty1,Ty2;I glutInit:Targc,arg3;I glutInit5isplay$ode:GL/.K,I1GLL)GL/.KNG';I glutInit*indo&,iUe:5##,5##;I glutInit*indo&Position:#,#;I glut7reate*indo&:V7o4en ,uderland Line 7lipping 9lgorit4mV;I glut5isplayOunc:display;I myinit:;I glut$ainLoop:;I = Output

Vi&a ;uestions> 1. *4at is t4e principle o+ 7o4en0,ut4erland 9lgorit4mW 2. ,tate t4e ad3antages and disad3antages o+ 7o4en0,ut4erland 9lgorit4mW 3. *4at is an outcodeW 4. *4at is ,ynt4etic 7amera $odelW 5. *4at are t4e 7amera ,peci+icationsW 3. $ro%ram to create a c'linder and a parallelepiped b' e+trudin% a circle and a =uadrilateral respecti&el'. )llow the user to speci8' the circle and the =uadrilateral. Ob9ecti&e: In t4is program t4e students &ill learn to create a cylinder and a parallelepiped using OpenGL +unctions.

2# &&&.'oo(spar.com ) *e%site +or ,tudents ) -./ 0 1otes 0 2uestion Papers

www.BookSpar.com Cinclude Dstdli%.4F Cinclude Dmat4.4F Cinclude DGLEglut.4F 3oid dra&Kpi6el:GLint c6,GLint cy; < gl7olor3+:1.#,#.#,#.#;I gl'egin:GLKPOI1.,;I gl-erte62+:c6,cy;I glLnd:;I =

Computer Graphics and Visualization Lab

3oid plotKpi6el:GLint 4,GLint (,GLint 6,GLint y; < dra&Kpi6el:6M4,yM(;I dra&Kpi6el:06M4,yM(;I dra&Kpi6el:6M4,0yM(;I dra&Kpi6el:06M4,0yM(;I dra&Kpi6el:yM4,6M(;I dra&Kpi6el:0yM4,6M(;I dra&Kpi6el:yM4,06M(;I dra&Kpi6el:0yM4,06M(;I = 3oid circleKdra&:GLint 4,GLint (,GLint r; < GLint dJ10r,6J#,yJrI &4ile:yF6; < plotKpi6el:4,(,6,y;I i+:dD#; dMJ2R6M3I else < dMJ2R:60y;M5I 00yI = MM6I = plotKpi6el:4,(,6,y;I = 3oid cylinderKdra&:; < GLint 6cJ1##,ycJ1##,rJ5#I GLint i,nJ5#I +or:iJ#IiDnIiMJ3; circleKdra&:6c,ycMi,r;I = 3oid parallelopiped:int 61,int 62,int y1,int y2,int y3,int y4; < 21 &&&.'oo(spar.com ) *e%site +or ,tudents ) -./ 0 1otes 0 2uestion Papers

www.BookSpar.com gl7olor3+:#.#,#.#,1.#;I glPoint,iUe:2.#;I gl'egin:GLKLI1LKLOOP;I gl-erte62+:61,y1;I gl-erte62+:62,y3;I gl-erte62+:62,y4;I gl-erte62+:61,y2;I glLnd:;I =

Computer Graphics and Visualization Lab

3oid parallelopipedKdra&:; < int 61J2##,62J3##,y1J1##,y2J1!5,y3J1##,y4J1!5I GLint i,nJ4#I +or:iJ#IiDnIiMJ2; parallelopiped:61Mi,62Mi,y1Mi,y2Mi,y3Mi,y4Mi;I = 3oid init:3oid; < gl7lear7olor:1.#,1.#,1.#,1.#;I gl$atri6$ode:GLKPNOQL7.IO1;I gluOrt4o25:#.#,4##.#,#.#,3##.#;I = 3oid display:3oid; < gl7lear:GLK7OLONK'/OOLNK'I.;I gl7olor3+:1.#,#.#,#.#;I glPoint,iUe:2.#;I cylinderKdra&:;I parallelopipedKdra&:;I glOlus4:;I = int main:int argc,c4ar Rarg3GH; < glutInit:Targc,arg3;I glutInit5isplay$ode:GL/.K,I1GLL)GL/.KNG';I glutInit*indo&,iUe:5##,5##;I glutInit*indo&Position:#,#;I glut7reate*indo&:Vcylinder and parallelopipedV;I glut5isplayOunc:display;I init:;I glut$ainLoop:;I =

22 &&&.'oo(spar.com ) *e%site +or ,tudents ) -./ 0 1otes 0 2uestion Papers

www.BookSpar.com

Computer Graphics and Visualization Lab

Output

Vi&a ;uestions> 1. L6plain a%out gluLoo(9t:Z;> %l(rustum?@A> %lu$erspecti&e< 2. L6plain t4e di++erent types o+ projectionsW 3. L6plain [0%u++er algorit4mW 4. *4at is antialiasingW 5. *4at is 7OP, ,O$< 4. $ro%ram usin% openGL 8unctions to draw a simple shaded scene consistin% o8 a teapot on a table. ,e8ine suitabl' the positions and properties o8 the li%ht source alon% with the properties o8 the sur8aces o8 the solid ob9ect used in the scene. Ob9ecti&e: In t4is program t4e students &ill learn to dra& teapot &it4 ta%le and sur+aces using OpenGL +unctions. Cinclude DGLEglut.4F Cinclude Dstdio.4F Cinclude Dstdli%.4F 3oid &all:dou%le t4ic(ness; < glPus4$atri6:;I 23 &&&.'oo(spar.com ) *e%site +or ,tudents ) -./ 0 1otes 0 2uestion Papers

www.BookSpar.com

Computer Graphics and Visualization Lab

gl.ranslated:#.5,#.5Rt4ic(ness,#.5;I gl,caled:1.#,t4ic(ness,1.#;I glut,olid7u%e:1.#;I glPop$atri6:;I = 3oid ta%leleg:dou%le t4ic(,dou%le len; < glPus4$atri6:;I gl.ranslated:#,lenE2,#;I gl,caled:t4ic(,len,t4ic(;I glut,olid7u%e:1.#;I glPop$atri6:;I = 3oid ta%le:dou%le top&,dou%le topt,dou%le legt,dou%le legl; < glPus4$atri6:;I gl.ranslated:#,legl,#;I gl,caled:top&,topt,top&;I glut,olid7u%e:1.#;I glPop$atri6:;I dou%le distJ#."5Rtop&E2.#0legtE2.#I glPus4$atri6:;I gl.ranslated:dist,#,dist;I ta%leleg:legt,legl;I gl.ranslated:#,#,02Rdist;I ta%leleg:legt,legl;I gl.ranslated:02Rdist,#,2Rdist;I ta%leleg:legt,legl;I gl.ranslated:#,#,02Rdist;I ta%leleg:legt,legl;I glPop$atri6:;I =

3oid displaysolid:3oid; < GL+loat matKam%ientGHJ<#.!+,#.!+,#.!+,1.#+=I GL+loat matKdi++useGHJ<#.5+,#.5+,#.5+,1.#+=I 24 &&&.'oo(spar.com ) *e%site +or ,tudents ) -./ 0 1otes 0 2uestion Papers

www.BookSpar.com

Computer Graphics and Visualization Lab

GL+loat matKspecularGHJ<1.#+,1.#+,1.#+,1.#+=I GL+loat matKs4ininessGHJ<5#.#+=I gl$aterial+3:GLKONO1.,GLK9$'IL1.,matKam%ient;I gl$aterial+3:GLKONO1.,GLK5IOO/,L,matKdi++use;I gl$aterial+3:GLKONO1.,GLK,PL7/L9N,matKspecular;I gl$aterial+3:GLKONO1.,GLK,PI1I1L,,,matKs4ininess;I GL+loat lig4tintGHJ<#.!+,#.!+,#.!+,1.#+=I GL+loat lig4tposGHJ<2.#+, .#+,3.#+,#.#+=I glLig4t+3:GLKLIGP.#,GLKPO,I.IO1,lig4tpos;I glLig4t+3:GLKLIGP.#,GLK5IOO/,L,lig4tint;I gl$atri6$ode:GLKPNOQL7.IO1;I glLoadIdentity:;I dou%le &in4tJ1.#I glOrt4o:0&in4tR 4E48.#,&in4tR 4E48.#,0&in4t,&in4t,#.1,1##.#;I gl$atri6$ode:GLK$O5LL-IL*;I glLoadIdentity:;I gluLoo(9t:2.3,1.3,2.#,#.#,#.25,#.#,#.#,1.#,#.#;I gl7lear:GLK7OLONK'/OOLNK'I.)GLK5LP.PK'/OOLNK'I.;I glPus4$atri6:;I glNotated:"#.#,#.#,#.#,1.#;I &all:#.#2;I glPop$atri6:;I &all:#.#2;I glPus4$atri6:;I glNotated:0"#.#,1.#,#.#,#.#;I &all:#.#2;I glPop$atri6:;I glPus4$atri6:;I gl.ranslated:#.4,#,#.4;I ta%le:#. ,#.#2,#.#2,#.3;I glPop$atri6:;I

glPus4$atri6:;I gl.ranslated:#. ,#.38,#.5;I glNotated:3#,#,1,#;I glut,olid.eapot:#.#8;I glPop$atri6:;I glOlus4:;I =

25 &&&.'oo(spar.com ) *e%site +or ,tudents ) -./ 0 1otes 0 2uestion Papers

www.BookSpar.com

Computer Graphics and Visualization Lab

int main:int argc,c4arRRarg3; < glutInit:Targc,arg3;I glutInit5isplay$ode:GL/.K,I1GLL)GL/.KNG')GL/.K5LP.P;I glutInit*indo&,iUe:5##,5##;I glutInit*indo&Position:#,#;I glut7reate*indo&:VteapotV;I glut5isplayOunc:displaysolid;I glLna%le:GLKLIGP.I1G;I glLna%le:GLKLIGP.#;I gl,4ade$odel:GLK,$OO.P;I glLna%le:GLK5LP.PK.L,.;I glLna%le:GLK1ON$9LI[L;I gl7lear7olor:#.1,#.1,#.1,#.#;I gl-ie&port:#,#, 4#,48#;I glut$ainLoop:;I = Output

Vi&a ;uestions> 1. L6plain ,pecular, 5i++use and .ranslucent sur+aces. 2. *4at is am%ient lig4tW 3. *4at is um%ra, penum%raW 4. L6plain P4ong lig4ting model. 5. L6plain glLig4t+3:Z;, gl$aterial+3:Z;. 5. $ro%ram to draw a color cube and allow the user to mo&e the camera to e+periment with perspecti&e &iewin% .Use openGL 8unctions. Ob9ecti&e: In t4is program t4e students &ill learn to create color cu%e and per+orming e3ents on t4e color cu%e &it4 mouse and (ey%oard using OpenGL +unctions. Cinclude DGLEglut.4F 2 &&&.'oo(spar.com ) *e%site +or ,tudents ) -./ 0 1otes 0 2uestion Papers

www.BookSpar.com Cinclude Dstdio.4F Cinclude Dstdli%.4F GL+loat 3erticesG HJ< 01.#,01.#,01.#, 1.#,01.#,01.#, 1.#, 1.#,01.#, 0 1.#, 1.#,01.#, 0 1.#,01.#, 1.#, 1.#,01.#, 1.#, 1.#, 1.#, 1.#, 01.#, 1.#, 1.# =I normalsG H J< 01.#,01.#,01.#, 1.#,01.#,01.#, 1.#, 1.#,01.#, 01.#, 1.#,01.#, 01.#,01.#, 1.#, 1.#,01.#, 1.#, 1.#, 1.#, 1.#, 01.#, 1.#, 1.# =I colorsG HJ< #.#,#.#,#.#, 1.#, #.#, #.#, 1.#, 1.#, #.#, #.#, 1.#, #.#, #.#, #.#, 1.#, 1.#, #.#, 1.#, 1.#, 1.#, 1.#, #.#, 1.#, 1.#=I

Computer Graphics and Visualization Lab

GL+loat

GL+loat

GLu%yte cu%eIndicesGHJ<#,3,2,1, 2,3,!, , #,4,!,3, 1,2, ,5, 4,5, ,!, #, 1, 5, 4 =I static GL+loat t4etaGHJ<#.#,#.#,#.#=I static GLint a6isJ2I static GLdou%le 3ie&erGHJ<#.#,#.#,5.#=I 3oid display:3oid; < gl7lear:GLK7OLONK'/OOLNK'I.)GLK5LP.PK'/OOLNK'I.;I glLoadIdentity:;I gluLoo(9t:3ie&erG#H,3ie&erG1H,3ie&erG2H,#.#,#.#,#.#,#.#,1.#,#.#;I glNotate+:t4etaG#H,1.#,#.#,#.#;I glNotate+:t4etaG1H,#.#,1.#,#.#;I glNotate+:t4etaG2H,#.#,#.#,1.#;I gl5ra&Llements:GLK2/95,,24,GLK/1,IG1L5K'B.L,cu%eIndices;I 2! &&&.'oo(spar.com ) *e%site +or ,tudents ) -./ 0 1otes 0 2uestion Papers

www.BookSpar.com

Computer Graphics and Visualization Lab

glOlus4:;I glut,&ap'u++ers:;I = 3oid mouse:int %tn, int state, int 6, int y; < i+:%tnJJGL/.KLLO.K'/..O1 TT stateJJGL/.K5O*1;a6isJ#I i+:%tnJJGL/.KNIGP.K'/..O1 TT stateJJGL/.K5O*1; a6isJ1I i+:%tnJJGL/.K$I55LLK'/..O1 TT stateJJGL/.K5O*1; a6isJ2I t4etaGa6isHMJ2.#I i+:t4etaGa6isHF3 #.#; t4etaGa6isH0J3 #.#I glutPostNedisplay:;I = 3oid (eys:unsigned c4ar (ey, int 6, int y; < i+:(eyJJ\6\; 3ie&erG#H0J1.#I i+:(eyJJ\X\; 3ie&erG#HMJ1.#I i+:(eyJJ\y\; 3ie&erG1H0J1.#I i+:(eyJJ\B\; 3ie&erG1HMJ1.#I i+:(eyJJ\U\; 3ie&erG2H0J1.#I i+:(eyJJ\[\; 3ie&erG2HMJ1.#I glutPostNedisplay:;I = 3oid myNes4ape:int &, int 4; < gl-ie&port:#,#,&,4;I gl$atri6$ode:GLKPNOQL7.IO1;I glLoadIdentity:;I i+:&DJ4; glOrustum:02.#,2.#,02.#R:GL+loat;4E:GL+loat;&,2.#R:GL+loat;4E:GL+loat;&,2.#,2#.#;I else glOrustum:02.#,2.#,02.#R:GL+loat;&E:GL+loat;4,2.#R:GL+loat;&E:GL+loat;4,2.#,2#.#;I gl$atri6$ode:GLK$O5LL-IL*;I = int main:int argc, c4ar RRarg3; < glutInit:Targc,arg3;I glutInit5isplay$ode:GL/.K5O/'LL)GL/.KNG')GL/.K5LP.P;I glutInit*indo&,iUe:5##,5##;I glut7reate*indo&:Vcolor cuceV;I glutNes4apeOunc:myNes4ape;I glut5isplayOunc:display;I glut]ey%oardOunc:(eys;I glut$ouseOunc:mouse;I glLna%le:GLK5LP.PK.L,.;I 28 &&&.'oo(spar.com ) *e%site +or ,tudents ) -./ 0 1otes 0 2uestion Papers

www.BookSpar.com

Computer Graphics and Visualization Lab

glLna%le7lient,tate:GLK7OLONK9NN9B;I glLna%le7lient,tate:GLK-LN.LXK9NN9B;I glLna%le7lient,tate:GLK1ON$9LK9NN9B;I gl-erte6Pointer:3,GLKOLO9.,#,3ertices;I gl7olorPointer:3,GLKOLO9.,#,colors;I gl1ormalPointer:GLKOLO9.,#,normals;I gl7olor3+:1.#,1.#,1.#;I glut$ainLoop:;I = Out$ut:

Vi&a ;uestions> 1. L6plain t4e (ey%oard and mouse e3ents used in t4is programW 2. *4at is Pidden sur+ace Remo&al< Bow do 'ou achie&e this in OpenGL< 3. *4at are t4e +unctions +or creatin% *enus in OpenGL< 4. L6plain a%out +onts in GL/.W 5. L6plain a%out glutPostNedisplay:;W

6. $ro%ram to 8ill an' %i&en pol'%on usin% scan-line area 8illin% al%orithm. ?Use appropriate data structuresA Ob9ecti&e: In t4is program t4e students &ill learn to apply scan0line area +illing algorit4m to +ill a polygon using OpenGL +unctions. EE ,can0Line algorit4m +or +illing a polygon Cinclude Dstdli%.4F Cinclude Dstdio.4F Cinclude DGLEglut.4F +loat 61,62,63,64,y1,y2,y3,y4I 2" &&&.'oo(spar.com ) *e%site +or ,tudents ) -./ 0 1otes 0 2uestion Papers

www.BookSpar.com

Computer Graphics and Visualization Lab

3oid edgedetect:+loat 61,+loat y1,+loat 62,+loat y2,int Rle,int Rre; < +loat m6,6,tempI int iI i+::y20y1;D#; < tempJy1Iy1Jy2Iy2JtempI tempJ61I61J62I62JtempI = i+::y20y1;YJ#; m6J:62061;E:y20y1;I else m6J62061I 6J61I +or:iJy1IiDJy2IiMM; < i+:6D:+loat;leGiH; leGiHJ:int;6I i+:6F:+loat;reGiH; reGiHJ:int;6I 6MJm6I = = 3oid dra&Kpi6el:int 6,int y; < gl7olor3+:1.#,1.#,#.#;I gl'egin:GLKPOI1.,;I gl-erte62i:6,y;I glLnd:;I = 3oid scan+ill:+loat 61,+loat y1,+loat 62,+loat y2,+loat 63,+loat y3,+loat 64,+loat y4; < int leG5##H,reG5##HI int i,yI +or:iJ#IiD5##IiMM; < leGiHJ5##I reGiHJ#I = edgedetect:61,y1,62,y2,le,re;I edgedetect:62,y2,63,y3,le,re;I edgedetect:63,y3,64,y4,le,re;I edgedetect:64,y4,61,y1,le,re;I +or:yJ#IyD5##IyMM; < i+:leGyHDJreGyH; +or:iJ:int;leGyHIiD:int;reGyHIiMM; dra&Kpi6el:i,y;I = 3# &&&.'oo(spar.com ) *e%site +or ,tudents ) -./ 0 1otes 0 2uestion Papers

www.BookSpar.com

Computer Graphics and Visualization Lab

= 3oid display:; < 61J2##.#Iy1J2##.#I62J1##.#Iy2J3##.#I63J2##.#Iy3J4##.#I64J3##.#Iy4J3##.#I gl7lear:GLK7OLONK'/OOLNK'I.;I gl7olor3+:#.#, #.#, 1.#;I gl'egin:GLKLI1LKLOOP;I gl-erte62+:61,y1;I gl-erte62+:62,y2;I gl-erte62+:63,y3;I gl-erte62+:64,y4;I glLnd:;I scan+ill:61,y1,62,y2,63,y3,64,y4;I glOlus4:;I = 3oid myinit:; < gl7lear7olor:1.#,1.#,1.#,1.#;I gl7olor3+:1.#,#.#,#.#;I glPoint,iUe:1.#;I gl$atri6$ode:GLKPNOQL7.IO1;I glLoadIdentity:;I gluOrt4o25:#.#,4"".#,#.#,4"".#;I = int main:int argc, c4arRR arg3; < glutInit:Targc,arg3;I glutInit5isplay$ode:GL/.K,I1GLL)GL/.KNG';I glutInit*indo&,iUe:5##,5##;I glutInit*indo&Position:#,#;I glut7reate*indo&:VOilling a Polygon using ,can0line 9lgorit4mV;I glut5isplayOunc:display;I myinit:;I glut$ainLoop:;I = Output

31 &&&.'oo(spar.com ) *e%site +or ,tudents ) -./ 0 1otes 0 2uestion Papers

www.BookSpar.com

Computer Graphics and Visualization Lab

Vi&a ;uestions> 1. L6plain scanline +illing algorit4mW 2. *4at is 9spectNatio,-ie&portW 3. Po& do you use timerW 4. *4at are t4e di++erent +rames in OpenGLW 5. *4at is +ragment processingW

.7. $ro%ram to displa' a set o8 &alues C8i9D as a rectan%ular mesh . Ob9ecti&e: In t4is program t4e students &ill learn to create rectangular mes4 using OpenGL +unctions. Cinclude Dstdli%.4F Cinclude DGLEglut.4F Cde+ine ma66 2# Cde+ine ma6y 25 Cde+ine d6 15 Cde+ine dy 1# GL+loat 6Gma66HJ<#.#=,yGma6yHJ<#.#=I GL+loat 6#J5#.#,y#J5#.#I GLint i,jI 3oid myinit:; < gl7lear7olor:1.#,1.#,1.#,1.#;I gl7olor3+:1.#,#.#,#.#;I glPoint,iUe:5.#;I gl$atri6$ode:GLKPNOQL7.IO1;I glLoadIdentity:;I gluOrt4o25:#.#,5##.#,#.#,5##.#;I 32 &&&.'oo(spar.com ) *e%site +or ,tudents ) -./ 0 1otes 0 2uestion Papers

www.BookSpar.com glutPostNedisplay:;I =

Computer Graphics and Visualization Lab

3oid display:3oid; < gl7lear:GLK7OLONK'/OOLNK'I.)GLK5LP.PK'/OOLNK'I.;I +or:iJ#IiDma66IiMM; 6GiHJ6#MiRd6I +or:jJ#IjDma6yIjMM; yGjHJy#MjRdyI +or:iJ#IiDma6601IiMM; +or:jJ#IjDma6y01IjMM; < gl'egin:GLKLI1LKLOOP;I gl-erte62+:6GiH,yGjH;I gl-erte62+:6GiH,yGjM1H;I gl-erte62+:6GiM1H,yGjM1H;I gl-erte62+:6GiM1H,yGjH;I glLnd:;I glOlus4:;I = glOlus4:;I = int main:int argc,c4ar RRarg3; < glutInit:Targc,arg3;I glutInit5isplay$ode:GL/.K,I1GLL)GL/.KNG')GL/.K5LP.P;I glutInit*indo&,iUe:5##,5##;I glut7reate*indo&:Vmes4V;I glut5isplayOunc:display;I myinit:;I glut$ainLoop:;I = Output

33 &&&.'oo(spar.com ) *e%site +or ,tudents ) -./ 0 1otes 0 2uestion Papers

www.BookSpar.com

Computer Graphics and Visualization Lab

Vi&a ;uestions> 1. L6plain ,pecular, 5i++use and .ranslucent sur+aces. 2. *4at is am%ient lig4tW 3. *4at is um%ra, penum%raW 4. L6plain P4ong lig4ting modelW 5. L6plain glLig4t+3:Z;, gl$aterial+3:Z;.W

34 &&&.'oo(spar.com ) *e%site +or ,tudents ) -./ 0 1otes 0 2uestion Papers

Potrebbero piacerti anche