COMSATS Institute Of Information And Technology Lahore, Pakistan
2013
COMSATS Institute Of Information And Technology Lahore, Pakistan
Waheed Abbas
DDP-BCS-FA11-088
Section “B”
Submitted To: Miss Nosheen Majeed
Waheed Abbas
DDP-BCS-FA11-088
Section “B”
Submitted To: Miss Nosheen Majeed
1. Draw a triangle strip with different colors for each triangle.
#include<GL\glut.h>
void Display(){ glClear(GL_COLOR_BUFFER_BIT); glBegin(GL_TRIANGLE_STRIP); glColor3f(255,255,0);//yellow glVertex2f(-0.5,0.9); glVertex2f(0.5,0.6); glVertex2f(-0.5,0.3); glColor3f(255,0,255);//pink glVertex2f(0.5,0.0); glColor3f(255,0,0);//green glVertex2f(-0.5,-0.3); glColor3f(0,255,255); glVertex2f(0.5,-0.6); glColor3f(0,255,0); glVertex2f(-0.5,-0.9); glEnd(); glFlush();
}
void main(int argc, char** argv){ glutInit(&argc, argv); glutInitWindowPosition(0,0); glutInitWindowSize(400,600); glutCreateWindow("My Program!"); glutDisplayFunc(Display); glClearColor(1.0,1.0,1.0,0.0); glutMainLoop();
}
2. Draw a circle with the help of triangle fan.
#include<GL\glut.h>
#include<math.h> void Display(){ int section=100; float radius=1.0; float twoPi=2.0*3.14; glClear(GL_COLOR_BUFFER_BIT); glBegin(GL_TRIANGLE_FAN); glVertex2f(0.0,0.0); for(int i=0; i<=section; i++){ glVertex2f(radius*cos(i*twoPi/section),radius*sin(i*twoPi/section)); if(i%8==0) glColor3f(0.0,0.0,0.0); if(i%8==1) glColor3f(0.0,0.0,1.0); if(i%8==2) glColor3f(0.0,1.0,0.0); if(i%8==3) glColor3f(0.0,1.0,1.0); if(i%8==4) glColor3f(1.0,0.0,0.0); if(i%8==5) glColor3f(1.0,0.0,1.0); if(i%8==6) glColor3f(1.0,1.0,0.0); if(i%8==7) glColor3f(1.0,1.0,1.0);
}
glEnd(); glFlush(); }
void main(int argc, char** argv){ glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowPosition(0,0); glutInitWindowSize(600,600);