CG lab manual for 6th sem

The Eduladder is a community of students, teachers, and programmers just interested to make you pass any exams. So we solve previous year question papers for you.
See Our team
Wondering how we keep quality?
Got unsolved questions?

You are here:Open notes-->VTU-->CG-lab-manual-for-6th-sem

# How to study this subject

#include

#include

typedef float point[3];

point v[]={{0.0,0.0,-1.0},{0.0,0.9428,-0.3333},{-0.8164,-0.4714,-0.3333}, {0.8164,-0.4714,-0.5}};

int n;

void tri(point a,point b,point c) {

glBegin(GL_POLYGON);

glVertex3fv(a);

glVertex3fv(b);

glVertex3fv(c);

glEnd();

}

void devide_tri(point a,point b,point c,int m) {

point v1,v2,v3;

if(m>0) {

for(int j=0;j<3;j++) {

v1[j]=(a[j]+b[j])/2; v2[j]=(a[j]+c[j])/2; v3[j]=(b[j]+c[j])/2;

}

devide_tri(a,v1,v2,m-1);

devide_tri(c,v2,v3,m-1);

devide_tri(b,v3,v1,m-1);

}

else tri(a,b,c);

}

void tet(int m) {

glColor3f(1,0,0);

devide_tri(v[0],v[1],v[2],m);

glColor3f(0,1,0);

devide_tri(v[3],v[2],v[1],m); glColor3f(0,0,1);

devide_tri(v[0],v[3],v[1],m); glColor3f(0,0,0);

devide_tri(v[0],v[2],v[3],m);

}

void display() {

glViewport(0,0,700,700);

glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

tet(n);

glFlush();

}

void main() {

printf("Enter Devisions: ");

scanf("%d",&n);

glutInitWindowSize(700,700);

glEnable(GL_DEPTH_TEST);

glutDisplayFunc(display);

glClearColor(1,1,1,1);

glutMainLoop();

}

# 3.Rotating Color Cube

#include float v[]={-0.5,-0.5,-0.5, -0.5,0.5,-0.5, 0.5,0.5,-0.5, 0.5,-0.5,-0.5, -0.5,-0.5,0.5, -0.5,0.5,0.5, 0.5,0.5,0.5, 0.5,-0.5,0.5}; float c[]={0,0,0, 1,0,0, 1,1,0, 0,1,0, 0,0,1, 1,0,1, 1,1,1, 0,1,1,};

GLubyte d[]={

0,1,2,3, 2,3,7,6, 4,5,6,7, 4,5,1,0, 5,6,2,1, 0,3,7,4

};

int gx=0,gy=0,gz=1;

void display() {

glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

glRotated(0.6,gx,gy,gz);

glFlush();

}

void mouse(int btn,int state,int x,int y) { if(btn==GLUT_LEFT_BUTTON&&state==GLUT_DOWN) {gx=1; gy=0; gz=0;} if(btn==GLUT_MIDDLE_BUTTON&&state==GLUT_DOWN) {gx=0; gy=1; gz=0;} if(btn==GLUT_RIGHT_BUTTON&&state==GLUT_DOWN) {gx=0; gy=0; gz=1;}

}

void main() {

glutCreateWindow("cube");

glutDisplayFunc(display);

glutIdleFunc(display);

glutMouseFunc(mouse);

glEnableClientState(GL_VERTEX_ARRAY);

glEnableClientState(GL_COLOR_ARRAY);

glVertexPointer(3,GL_FLOAT,0,v);

glColorPointer(3,GL_FLOAT,0,c);

glEnable(GL_DEPTH_TEST);

glutMainLoop();

}

# 4.Rotate House problem

#include

#include

float v[]={0,0.6, 0.25,0.9, 0.5,0.6, 0,0.6, 0.5,0.6, 0.5,0, 0.32,0, 0.32,0.1, 0.16,0.1, 0.16,0, 0.32,0, 0,0, 0,0.6};

GLubyte list[]={0,1,2,3,4,5,6,7,8,9,10,11,12};

int g=0;

void dis() {

glClear(GL_COLOR_BUFFER_BIT);

glViewport(-100,-100,700,700); glDrawElements(GL_LINE_LOOP,13,GL_UNSIGNED_BYTE,list);

glRotated(g,0,0,1);

glDrawElements(GL_LINE_LOOP,13,GL_UNSIGNED_BYTE,list);

glFlush();

}

void main() {

glutInitWindowSize(700,700);

printf("Enter Rotation Angle:");

scanf("%d",&g);

glutCreateWindow("House Optimized by R.Ganesh");

glutDisplayFunc(dis);

glEnableClientState(GL_VERTEX_ARRAY);

glVertexPointer(2,GL_FLOAT,0,v);

glutMainLoop(); }

//this is 1st SHORTEST program , programmend by R.Ganesh 6.cylinder & parallelpiped by extruding circle & rectangle respectively.

#include

#include

void objects(float cx,float cy,float r,int nums) {

glColor3f(1,0,0);

glBegin(GL_LINE_LOOP);

//circle

for(int ii=0;ii void obj(double tx,double ty,double tz,double sx,double sy,double sz) {

glRotated(50,0,1,0);

glRotated(10,-1,0,0);

glRotated(11.7,0,0,-1);

glTranslated(tx,ty,tz);

glScaled(sx,sy,sz);

glutSolidCube(1);

}

void display() {

glViewport(0,0,700,700);

glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

obj(0,0,0.5,1,1,0.04);

// three walls

obj(0,-0.5,0,1,0.04,1);

obj(-0.5,0,0,0.04,1,1);

obj(0,-0.3,0,0.02,0.2,0.02);

// four table legs

obj(0,-0.3,-0.4,0.02,0.2,0.02);

obj(0.4,-0.3,0,0.02,0.2,0.02);

obj(0.4,-0.3,-0.4,0.02,0.2,0.02);

obj(0.2,-0.18,-0.2,0.6,0.02,0.6);

// table top

glRotated(50,0,1,0);

glRotated(10,-1,0,0);

glRotated(11.7,0,0,-1);

glTranslated(0.3,-0.1,-0.3);

glutSolidTeapot(0.09);

glFlush();

}

void main() {

float ambient[]={1,1,1,1};

float light_pos[]={27,80,2,3};

glutInitWindowSize(700,700);

glutCreateWindow("scene");

glutDisplayFunc(display);

glEnable(GL_LIGHTING);

glEnable(GL_LIGHT0);

glMaterialfv(GL_FRONT,GL_AMBIENT,ambient); glLightfv(GL_LIGHT0,GL_POSITION,light_pos);

glEnable(GL_DEPTH_TEST);

glutMainLoop();

}

# 8.Perspectibve View of color cube

#include

float v[]={-1,-1,-1, -1,1,-1, 1,1,-1, 1,-1,-1, -1,-1,1, -1,1,1, 1,1,1, 1,-1,1};

float c[]={0,0,0, 1,0,0, 1,1,0, 0,1,0, 0,0,1, 1,0,1, 1,1,1, 0,1,1,};

GLubyte list[]={0,1,2,3, 2,3,7,6, 4,5,6,7, 4,5,1,0, 5,6,2,1, 0,3,7,4};

int gx=0,gy=0,gz=1;

static GLfloat theta[] = {0.0,0.0,0.0};

static GLint axis = 2;

static GLdouble viewer[]= {0.0, 0.0, 5.0};

void display(void) {