Computer Graphics Lab Manual

Embed Size (px)

Citation preview

  • engineerportal.blogspot.in computer graphics lab manual

    1.Bresenhams line drawing algorithm :ALGORITHM :Step 1 : Start.Step 2 : Initialize the graphics header files and functions.Step 3 : Declare the required variables and functions.Step 4 : Get the four points for drawing a line namely x1,x2,y1,y2.Step 5 : Draw the line using the algorithm.Step 6 : Display the output.Step 7 : stop.PROGRAM :#include "stdio.h"#include "conio.h"#include "math.h"#include "graphics.h"main(){

    int gd=DETECT,gm;int xa,xb,ya,yb;int dx,dy,x,y,xend,p;initgraph(&gd,&gm,"c:\\tc\\bgi");printf("Enter The Two Left

    Endpoints(xa,ya):\n");scanf("%d%d",&xa,&ya);printf("Enter The Two Right

    Endpoints(xb,yb):\n");scanf("%d%d",&xb,&yb);dx=abs(xa-xb);dy=abs(ya-yb);p=2*dy-dx;if(xa>xb){x=xb;y=yb;xend=xa;

    }

    else{

    x=xa;y=ya;xend=xb;

    }putpixel(x,y,6);while(x

  • engineerportal.blogspot.in computer graphics lab manual

    Bresenhams circle drawing algorithmALGORITHM :Step 1 : Start.Step 2 : Initialize the graphics header files and functions.Step 3 : Declare the required variables and functions.Step 4 : Get the co-ordinates and radius of the circle.Step 5 : Draw the circle using the algorithm.Step 6 : Display the output.Step 7 : stop.PROGRAM :#include "stdio.h"#include "conio.h"#include "math.h"#include "graphics.h"main(){int gd=DETECT,gm;int xcenter,ycenter,radius;int p,x,y;initgraph(&gd,&gm,"c:\\tc\\bgi");x=0;printf("Enter The Radius Value:\n");scanf("%d",&radius);y=radius;printf("Enter The xcenter and

    ycenter Values:\n");scanf("%d%d",&xcenter,&ycenter);plotpoints(xcenter,ycenter,x,y);p=1-radius;while(x

  • engineerportal.blogspot.in computer graphics lab manual

    Bresenhams ellipse drawing algorithm:ALGORITHM :Step 1 : Start.Step 2 : Initialize the graphics header files and functions.Step 3 : Declare the required variables and functions.Step 4 : Get the co-ordinates and radius of the ellipse.Step 5 : Draw the ellipse using the algorithm.Step 6 : Display the output.Step 7 : stop.PROGRAM :#include "stdio.h"#include "conio.h"#include "math.h"#include "graphics.h"main(){

    int gd=DETECT,gm;int xcenter,ycenter,rx,ry;int p,x,y,px,py,rx1,ry1,rx2,ry2;initgraph(&gd,&gm,"c:\\tc\\bgi");printf("Enter The Radius Value:\n");scanf("%d%d",&rx,&ry);printf("Enter The xcenter and ycenter

    Values:\n");scanf("%d%d",&xcenter,&ycenter);ry1=ry*ry;rx1=rx*rx;ry2=2*ry1;rx2=2*rx1;x=0;y=ry;plotpoints(xcenter,ycenter,x,y);p=(ry1-rx1*ry+(0.25*rx1));px=0;py=rx2*y;while(px=0)y=y-1;py=py-rx2;if(p0){y=y-1;py=py-rx2;if(p0)

    p=p+rx1-py;elsep=p+rx1-py+px;

    plotpoints(xcenter,ycenter,x,y);}

    }getch();return(0);

    }int plotpoints(int xcenter,int ycenter,intx,int y){

    putpixel(xcenter+x,ycenter+y,6);putpixel(xcenter-x,ycenter+y,6);putpixel(xcenter+x,ycenter-y,6);putpixel(xcenter-x,ycenter-y,6);

    }OUTPUT :Enter The Radius Value(Rx,Ry) : 10 30Enter The xcenter and ycenter Values : 300 150

  • engineerportal.blogspot.in computer graphics lab manual

    2D transformationsa.Translation, Reflection, and Shearb. Rotation (With and without pivotpoint), Scaling (With and without pivotpoint)c. Translation, Scaling, Rotationd. fixed point scaling, fixed pointrotation

    #include#include#include#includevoid translation(x,y,x1,y1,x2,y2){int tx,ty,xx,yy;printf("Enter transformational values:");scanf("%d%d",&tx,&ty);line(x+tx,y+ty,x1+tx,y1+ty);line(x1+tx,y1+ty,x2+tx,y2+ty);line(x2+tx,y2+ty,x+tx,y+ty);

    }void scaling(x,y,x1,y1,x2,y2){

    float sx,sy;printf("Enter the scaling vertices:");scanf("%f%f",&sx,&sy);line(x*sx,y*sy,x1*sx,y1*sy);line(x1*sx,y1*sy,x2*sx,y2*sy);line(x2*sx,y2*sy,x*sx,y*sy);

    }void scalingpivot(x,y,x1,y1,x2,y2){

    float sx,sy,xf,yf;int xp,yp,xp1,yp1,xp2,yp2;printf("Enter the scaling vertices:");scanf("%f%f",&sx,&sy);printf("Enter the scaling pivot points:");scanf("%f%f",&xf,&yf);xp=(x*sx)+xf*(1-sx);yp=(y*sy)+yf*(1-sy);xp1=(x1*sx)+xf*(1-sx);yp1=(y1*sy)+yf*(1-sy);

    xp2=(x2*sx)+xf*(1-sx);yp2=(y2*sy)+yf*(1-sy);line(x+xp,y+yp,x1+xp1,y1+yp1);line(x1+xp1,y1+yp1,x2+xp2,y2+yp2);line(x2+xp2,y2+yp2,x+xp,y+yp);

    }void rotation(x,y,x1,y1,x2,y2){

    int the,xr,yr,xr1,yr1,xr2,yr2;float rad;printf("Enter the theta value:");scanf("%d",&the);rad=the*(3.14/180);xr=x*cos(rad)-y*sin(rad);yr=x*sin(rad)+y*cos(rad);xr1=x1*cos(rad)-y1*sin(rad);yr1=x1*sin(rad)+y1*cos(rad);xr2=x2*cos(rad)-y2*sin(rad);yr2=x2*sin(rad)+y2*cos(rad);line(x+xr,y+yr,x1+xr1,y1+yr1);line(x1+xr1,y1+yr1,x2+xr2,y2+yr2);line(x2+xr2,y2+yr2,x+xr,y+yr);

    }void rotationpivot(x,y,x1,y1,x2,y2){

    int the,xr,yr,xr1,yr1,xr2,yr2,xf,yf;float rad;printf("Enter the theta value:");scanf("%d",&the);printf("\n Enter the pivot points:");scanf("%d%d",&xf,&yf);rad=the*(3.14/180);xr=xf+(x-xf)*cos(rad)-(y-yf)*sin(rad);yr=yf+(x-xf)*sin(rad)-(y-yf)*cos(rad);xr1=xf+(x1-xf)*cos(rad)-(y1-

    yf)*sin(rad);yr1=yf+(x1-xf)*sin(rad)-(y1-

    yf)*cos(rad);xr2=xf+(x2-xf)*cos(rad)-(y2-

    yf)*sin(rad);yr2=yf+(x2-xf)*sin(rad)-(y2-

    yf)*cos(rad);line(x+xr,y+yr,x1+xr1,y1+yr1);

  • engineerportal.blogspot.in computer graphics lab manual

    line(x1+xr1,y1+yr1,x2+xr2,y2+yr2);line(x2+xr2,y2+yr2,x+xr,y+yr);

    }void reflection(x,y,x1,y1,x2,y2){

    line(y,x,y1,x1);line(y1,x1,y2,x2);line(y2,x2,y,x);

    }void shear(x,y,x1,y1,x2,y2){

    int s;//x+=100; y+=100;//x1+=100; y1+=100;//x2+=100; y2+=100;printf("Enter the shear value about x:");scanf("%d",&s);line(x,y,x1+s,y1);line(x1+s,y1,x2,y2);line(x2,y2,x,y);

    }void main(){

    int gd,gm,x,y,c,tx,ty,x1,y1,x2,y2;detectgraph(&gd,&gm);initgraph(&gd,&gm,"C:\\TC\\BGI");printf("Enter the 6 values:");

    scanf("%d%d%d%d%d%d",&x,&y,&x1,&y1,&x2,&y2);

    printf("Actual polygon");line(x,y,x1,y1);line(x1,y1,x2,y2);line(x2,y2,x,y);do{

    printf("\nMenu\n 1.Translation\n2.Scaling\n 3.Scaling with pivot\n");

    printf(" 4.Rotation\n 5.Rotationwith pivot\n 6.Reflection\n");

    printf(" 7.Shearing\n 8.Exit\n");printf("Enter ur choice:");scanf("%d",&c);switch(c){

    case 1:

    translation(x,y,x1,y1,x2,y2);break;

    case 2:scaling(x,y,x1,y1,x2,y2);break;

    case 3:

    scalingpivot(x,y,x1,y1,x2,y2);break;

    case 4:rotation(x,y,x1,y1,x2,y2);break;

    case 5:

    rotationpivot(x,y,x1,y1,x2,y2);break;

    case 6:reflection(x,y,x1,y1,x2,y2);break;

    case 7:shear(x,y,x1,y1,x2,y2);break;

    case 8:exit(0);break;

    }}while(c

  • engineerportal.blogspot.in computer graphics lab manual

    Implementation of Cohen-Sutherland Line Clipping AlgorithmProgram:#include#include#includetypedef struct coderegion{

    int x,y;char code[4];

    }CR;CR setregioncode(CR c){

    CR ctemp;int

    xmin=100,xmax=500,ymin=150,ymax=400;if(c.xxmax){

    ctemp.code[1]='1';printf("\nbit2= %c",ctemp.code[1]);

    }else{

    ctemp.code[1]='0';printf("\nbit2= %c",ctemp.code[1]);

    }if(c.yymax){

    ctemp.code[3]='1';printf("\nbit4= %c",ctemp.code[3]);

    }

    else{

    ctemp.code[3]='0';printf("\nbit4= %c",ctemp.code[3]);

    }ctemp.x=c.x;ctemp.y=c.y;return(ctemp);

    }

    int objectvisibility(CR c1,CR c2){

    int i,flag=0;for(i=0;i

  • engineerportal.blogspot.in computer graphics lab manual

    {y=ymin;

    }if((c1.code[3]=='1')||(c1.code[2]=='1')){

    m=(float)(c2.y-c1.y)/(c2.x-c1.x);printf("\n slope value = %f",m);k=(float)c1.x+(float)(y-c1.y)/m;printf("\n x value = %f",k);temp.x=k;temp.y=y;for(i=0;i

  • engineerportal.blogspot.in computer graphics lab manual

    Sutherland-Hodgeman Polygon clipping Algorithm//Program:

    #include#include#include#includeenum area{left,right,top,bottom};typedef struct{

    double x,y;} points;points outvertex[10];points vertex[10];int max=0;int n;enum area id;void sutherclip(int,int,int,int);points intersect(int,points,points);int inside(int,points);

    int inside(int clipbound,points s){int pos=0;switch(id)

    {case left:

    if(s.x>clipbound)pos=1;

    break;case right:

    if(s.xclipbound)pos=1;

    break;case bottom:

    if(s.y

  • engineerportal.blogspot.in computer graphics lab manual

    {temp=intersect(xmin,s,p);outvertex[max++]=temp;

    }}n=max;for(i=0;i

  • engineerportal.blogspot.in computer graphics lab manual

    Implementation of 3D Transformations

    Program:#include#include#include#includevoid draw(float x1,float y1,floatx2,float y2,float z){

    bar3d(x1,y1,x2,y2,z,1);}void z_rotate(float x1,float y1,floatx2,float y2,float z,float r){

    float a,b,c,d;a=(x1*cos(r))-(y1*sin(r));b=(x2*cos(r))-(y2*sin(r));c=(x1*sin(r))+(y1*cos(r));d=(x2*sin(r))+(y2*cos(r));draw(a,c,b,d,z);

    }void main(){int gd,gm,s,ch;detectgraph(&gd,&gm);initgraph(&gd,&gm,"E:\\TC\\BGI");do{

    floatx1=200,x2=300,y1=200,y2=300,z=100,tx,ty,sx,sy,sz,o,r;

    clrscr();printf("\n\n\n\t\t 3D

    Transformations");

    printf("\n\n1.3DTranslation\n2.3D Scaling\n3.3DRotation \n4.Exit");

    printf("\n\nEnter UrOption:");

    scanf("%d",&ch);clrscr();switch(ch){

    case 1:printf("\n\nEnter TranslationValues(tx,ty):");scanf("%f %f",&tx,&ty);printf("\nBefore Translation");setcolor(10);draw(x1,y1,x2,y2,z);sleep(3);printf("\nAfter Translation");setcolor(12);draw(x1+tx,y1+ty,x2+tx,y2+ty,z);break;

    case 2:printf("\n\nEnter the scalingValues(sx,sy,sz):");scanf("%f %f %f",&sx,&sy,&sz);printf("\nBefore Scaling");setcolor(4);draw(x1,y1,x2,y2,z);sleep(3);printf("\nAfter Scaling");

    x1*=sx;y1*=sy;x2*=sx;y2*=sy;z*=sz;

    setcolor(6);

  • engineerportal.blogspot.in computer graphics lab manual

    draw(x1,y1,x2,y2,z);break;

    case 3:printf("\n\nEnter the rotationangle:");scanf("%f",&o);printf("\nBefore Rotation");draw(x1,y1,x2,y2,z);sleep(3);printf("\nAfter Rotation");

    r=(o*3.14)/180;z_rotate(x1,y1,x2,y2,z,r);

    break;

    case 4:exit(0);

    default:printf("\n\nEnter

    a valid choice");}printf("\n\nPress 1 to

    continue:");scanf("%d",&s);

    }while(s==1);getch();closegraph();}

    Output:

    Enter the optin translation

    Scaling rotation

  • engineerportal.blogspot.in computer graphics lab manual

    Implementation of composite 3D Transformations

    Program:#include#include#include#includestruct pt{

    float x;float y;};

    float thematrix[3][3];void print(float t[][3]){int i,j;for(i=0;i

  • engineerportal.blogspot.in computer graphics lab manual

    float rad;int a;printf("\nEnter rotation angle");scanf("%d",&a);rad=a*(3.14/180);matrixsetidentity(m);m[0][0]=cos(rad);m[0][1]=-sin(rad);m[1][0]=sin(rad);m[1][1]=cos(rad);premul(m,thematrix);

    }

    void transformpts(int npts,struct pt *p1){int k;float tmp;for(k=0;k

  • engineerportal.blogspot.in computer graphics lab manual

    transformpts(3,p1);d3d(p1,z);break;case 4:

    break;

    }}while(ch

  • engineerportal.blogspot.in computer graphics lab manual

    Projection 3dProgram:#include#include#include#include

    void main(){

    int gd,gm;int tlx,tly,brx,bry,d;detectgraph(&gd,&gm);initgraph(&gd,&gm,"e:\\tc\\

    bgi");printf("Enter the input for 3D

    object");scanf("%d %d %d %d

    %d",&tlx,&tly,&brx,&bry,&d);bar3d(tlx,tly,brx,bry,d,1);

    sleep(3);//getch();cleardevice();printf("Front View");bar3d(tlx,tly,brx,bry,0,0);sleep(3);//getch();cleardevice();printf("Top view");bar3d(tlx,tly-d,brx,tly,0,0);sleep(3);//getch();cleardevice();printf("Side View");bar3d(brx,tly,brx+d,bry,0,0);getch();closegraph();

    }

    Output:

  • engineerportal.blogspot.in computer graphics lab manual

    //chain of diamonds#include typedef struct diamond{

    GLint x,y;}center;void myInit(void){

    glClearColor(1.0,1.0,1.0,0.0);glColor3f(0.0f,0.0f,0.0f);glPointSize(4.0);glMatrixMode(GL_PROJECTION);glLoadIdentity();gluOrtho2D(0.0,640.0,0.0,480.0);

    }void myDisplay(void){

    int size=50,n=5,i;glClear(GL_COLOR_BUFFER_BIT);center cen;cen.x=26,cen.y=30;for(i=0;i

  • engineerportal.blogspot.in computer graphics lab manual

    //chessboard#includevoid myInit(void){glClearColor(1.0,1.0,1.0,1.0);glColor3f(0.0f,0.0f,0.0f);glPointSize(4.0);glMatrixMode(GL_PROJECTION);glLoadIdentity();gluOrtho2D(0.0,480.0,0.0,480.0);}void board(int size){int i=0,k=0;for(i=0;i

  • engineerportal.blogspot.in computer graphics lab manual

    CODING:#include#includevoid myInit(void){

    glClearColor(1.0,1.0,1.0,0.0);glColor3f(0.0f,0.0f,0.0f);glPointSize(4.0);glMatrixMode(GL_PROJECTION);glLoadIdentity();gluOrtho2D(0.0,640.0,0.0,480.0);

    }int random(int m){

    return rand()%m;}void myDisplay(void){

    //int i;//int j=300,k=200;glClear(GL_COLOR_BUFFER_BIT);glBegin(GL_LINE_LOOP);

    glVertex2i(0,0);glVertex2i(0,400);glVertex2i(500,400);glVertex2i(500,0);

    glEnd();

    int tx[3];//={200,500,200};int ty[3];//={400,50,50};int index=random(500);int pointx;//=tx[index];int pointy;//=ty[index];for(int i=0,j=0;i

  • engineerportal.blogspot.in computer graphics lab manual

    DRAWING RANDOM DIAMONDSUSING OPEN GL#include#includestruct point{

    int x,y;}centre={100,100};int random(int n){

    return rand()%n;}void myinit(void){

    glClearColor(1.0,1.0,1.0,0.0);glColor3f(0.0f,0.0f,0.0f);glPointSize(4.0);glMatrixMode(GL_PROJECTIO

    N);glLoadIdentity();gluOrtho2D(0.0,640.0,0.0,480.0);

    }void myDisplay(void){

    GLint size=100;glClear(GL_COLOR_BUFFER_B

    IT);for(int i=0;i

  • engineerportal.blogspot.in computer graphics lab manual

    // Simple OpenGL ProgramSierpinski gasketProgram:#include#includestruct GLintPoint{public:GLint x,y;}tri;void myInit(){glClearColor(1.0,1.0,1.0,1.0);glColor3f(0.0f,0.0f,0.0f);glPointSize(4.0);glMatrixMode(GL_PROJECTION);glLoadIdentity();gluOrtho2D(0.0,640.0,0.0,480.0);}int random(int m){return (rand() % m );}void myDisplay(){glClear(GL_COLOR_BUFFER_BIT);int r=random(6);for(int j=0; j

  • engineerportal.blogspot.in computer graphics lab manual

    Village of houses#include#includetypedef struct village{

    int x,y;}house;house peak;void myInit(){glClearColor(1.0,1.0,1.0,0.0);glColor3f(0.0f,0.0f,0.0f);glPointSize(3.0);glMatrixMode(GL_PROJECTION);glLoadIdentity();gluOrtho2D(0.0,640.0,0.0,480.0);

    }int random(int r){

    return rand()%r;}void parameterizedHouse(GLint width,GLintheight){peak.x=random(300);peak.y=random(500);glBegin(GL_LINE_STRIP);glVertex2i(peak.x-width/2,peak.y-height);glVertex2i(peak.x-width/2,peak.y-3*height/8);glVertex2i(peak.x,peak.y);glVertex2i(peak.x+width/2,peak.y-3*height/8);glVertex2i(peak.x+width/2,peak.y-height);glVertex2i(peak.x-width/2,peak.y-height);glEnd();

    glBegin(GL_LINE_STRIP);glVertex2i(((peak.x-width/2)+(.3*width)),peak.y-height);glVertex2i(((peak.x-width/2)+(.3*width)),((peak.y-3*height/8)-(.35*height)));glVertex2i(((peak.x-width/2)+(.7*width)),((peak.y-3*height/8)-(.35*height)));glVertex2i(((peak.x-width/2)+(.7*width)),peak.y-height);glEnd();glBegin(GL_LINES);glVertex2i(peak.x-width/2,peak.y-3*height/8);glVertex2i(peak.x+width/2,peak.y-3*height/8);glEnd();}void myDisplay(){glClear(GL_COLOR_BUFFER_BIT);glBegin(GL_POINTS);for(int i=0;i

  • engineerportal.blogspot.in computer graphics lab manual

    3d objects#include #include#include#include#includevoid axis(double length){glPushMatrix();glBegin(GL_LINES);glVertex3d(0,0,0);glVertex3d(0,0,length);glEnd();glTranslated(0,0,length-0.2);glutWireCone(0.04,0.2,12,9);glPopMatrix();

    }void display(void){glMatrixMode(GL_PROJECTION);glLoadIdentity();glOrtho(-2.0*64/48.0,2.0*64/48.0,-2.0,2.0,0.1,100);glMatrixMode(GL_MODELVIEW);glLoadIdentity();gluLookAt(2.0,2.0,2.0,0.0,0.0,0.0,0.0,1.0,0.0);glClear(GL_COLOR_BUFFER_BIT);glColor3d(0,0,0);axis(0.5);glPushMatrix();glRotated(90,0,1.0,0);axis(0.5);glRotated(-90.0,1,0,0);axis(0.5);glPopMatrix();

    //BIG CUBEglPushMatrix();glTranslated(0.5,0.5,0.5);glutWireCube(1.0);glPopMatrix();glPushMatrix();glTranslated(1,1,0);glutWireSphere(0.25,10,8);glPopMatrix();glPushMatrix();glTranslated(1,0,1);

    glutWireCone(0.2,0.5,10,8);glPopMatrix();glPushMatrix();glTranslated(1,1,1);glutWireTeapot(0.1);glPopMatrix();glPushMatrix();glTranslated(0,1,0);glRotated(90,1,0,0);glutWireTorus(0.1,0.3,10,10);glPopMatrix();glPushMatrix();glTranslated(1,0,0);glScaled(0.15,0.15,0.15);glutWireDodecahedron();glPopMatrix();glPushMatrix();glTranslated(0,1,1);glutWireCube(0.25);glPopMatrix();glPushMatrix();glTranslated(0,0,1);GLUquadricObj *q;q=gluNewQuadric();gluQuadricDrawStyle(q,GLU_LINE);gluCylinder(q,0.2,0.2,0.4,8,8);glPopMatrix();glFlush();}

    int main(int argc, char** argv){glutInit(&argc, argv);glutInitDisplayMode(GLUT_SINGLE |

    GLUT_RGB);glutInitWindowSize(640,480);glutInitWindowPosition(100,100);glutCreateWindow("OpenGL Windows

    Application with GLUT");glutDisplayFunc(display);glClearColor(1.0,1.0,1.0,0.0);glViewport(0,0,640,480);glutMainLoop();

    return 0;}

  • engineerportal.blogspot.in computer graphics lab manual

    3d scenes#include void wall(double thickness){glPushMatrix();glTranslated(0.5,0.5*thickness,0.5);glScaled(1.0,thickness,1.0);glutSolidCube(1.0);glPopMatrix();}void tableleg(double thick,double len){glPushMatrix();glTranslated(0,len/2,0);glScaled(thick,len,thick);glutSolidCube(1.0);glPopMatrix();}void jackpart(){glPushMatrix();glScaled(0.2,0.2,1.0);glutSolidSphere(1,15,15);glPopMatrix();glPushMatrix();glTranslated(0,0,1.2);glutSolidSphere(0.2,15,15);glTranslated(0,0,-2.4);glutSolidSphere(0.2,15,15);glPopMatrix();

    }void jack(){glPushMatrix();jackpart();glRotated(90.0,0,1,0);jackpart();glRotated(90.0,1,0,0);jackpart();glPopMatrix();}void table(double topwid,doubletopthick,double legthick,double leglen){glPushMatrix();

    glTranslated(0,leglen,0);glScaled(topwid,topthick,topwid);glutSolidCube(1.0);glPopMatrix();double dist=0.95*topwid/2.0-legthick/2.0;glPushMatrix();glTranslated(dist,0,dist);tableleg(legthick,leglen);glTranslated(0,0,-2*dist);tableleg(legthick,leglen);glTranslated(-2*dist,0,2*dist);tableleg(legthick,leglen);glTranslated(0,0,-2*dist);tableleg(legthick,leglen);glPopMatrix();}

    void display(void){GLfloatmat_ambient[]={0.7f,0.7f,0.7f,1.0f};GLfloat mat_diffuse[]={0.6f,0.6f,0.6f,1.0f};GLfloatmat_specular[]={1.0f,1.0f,1.0f,1.0f};GLfloat mat_shininess[]={50.0f};glMaterialfv(GL_FRONT,GL_AMBIENT,mat_ambient);glMaterialfv(GL_FRONT,GL_DIFFUSE,mat_diffuse);glMaterialfv(GL_FRONT,GL_SPECULAR,mat_specular);glMaterialfv(GL_FRONT,GL_SHININESS,mat_shininess);GLfloatlightIntensity[]={0.7f,0.7f,0.7f,1.0f};GLfloatlight_position[]={2.0f,6.0f,3.0f,0.0f};glLightfv(GL_LIGHT0,GL_POSITION,light_position);glLightfv(GL_LIGHT0,GL_DIFFUSE,lightIntensity);glMatrixMode(GL_PROJECTION);glLoadIdentity();double winHt=1.0;

  • engineerportal.blogspot.in computer graphics lab manual

    glOrtho(-winHt*64/48.0,winHt*64/48.0,-winHt,winHt,0.1,100.0);glMatrixMode(GL_MODELVIEW);glLoadIdentity();gluLookAt(2.3,1.3,2,0,0.25,0,0.0,1.0,0.0);glClear(GL_COLOR_BUFFER_BIT |GL_DEPTH_BUFFER_BIT);glPushMatrix();glTranslated(0.4,0.4,0.6);glRotated(45,0,0,1);glScaled(0.08,0.08,0.08);jack();glPopMatrix();glPushMatrix();glTranslated(0.6,0.38,0.5);glRotated(30,0,1,0);glutSolidTeapot(0.08);glPopMatrix();glPushMatrix();glTranslated(0.25,0.42,0.35);glutSolidSphere(0.1,15,15);glPopMatrix();glPushMatrix();glTranslated(0.4,0,0.4);table(0.6,0.02,0.02,0.3);glPopMatrix();wall(0.02);glPushMatrix();glRotated(90.0,0.0,0.0,1.0);wall(0.02);glPopMatrix();

    glPushMatrix();glRotated(-90.0,1.0,0.0,0.0);wall(0.02);glPopMatrix();glFlush();}

    int main(int argc, char** argv){glutInit(&argc, argv);glutInitDisplayMode(GLUT_SINGLE |

    GLUT_RGB | GLUT_DEPTH);glutInitWindowSize(640,480);glutInitWindowPosition(100,100);

    glutCreateWindow("OpenGL WindowsApplication with GLUT");glutDisplayFunc(display);

    glEnable(GL_LIGHTING);glEnable(GL_LIGHT0);glShadeModel(GL_SMOOTH);glEnable(GL_DEPTH_TEST);glEnable(GL_NORMALIZE);

    glClearColor(1.0,1.0,1.0,0.0);

    glViewport(0,0,640,480);glutMainLoop();return 0;

    }

  • engineerportal.blogspot.in computer graphics lab manual

    Colour models

    #include void display(void){float r,g,b,c,m,y;glClear(GL_COLOR_BUFFER_BIT);r=1;g=0;b=0;c=1-r;m=1-g;y=1-b;glColor3f(r,g,b);int i;{

    for(i=0;i

  • engineerportal.blogspot.in computer graphics lab manual

    Window to viewport#include void display(void){GLint i,j;glClear(GL_COLOR_BUFFER_BIT);

    glViewport(0,0,640,440);glBegin(GL_TRIANGLES);

    glVertex2i(300,300);glVertex2i(250,350);glVertex2i(350,350);

    glEnd();glColor3f(1.0,0.0,0.0);for(i=0;i

  • engineerportal.blogspot.in computer graphics lab manual

    //JULIA sets#include int dwell(double sx,double sy){int iteration,itermax=100;double dx,dy,tmp,fsq,cx=-0.5,cy=0.5;dx = sx; dy = sy;fsq=sx*sx+sy*sy;for (iteration=1;iteration

  • engineerportal.blogspot.in computer graphics lab manual

    Mandelbort Set#include int dwell(double cx,double cy){

    int iteration,itermax=100;double dx,dy,tmp,fsq;dx = 0; dy = 0;fsq=cx*cx+cy*cy;for (iteration=1;iteration