Time Table

Only available on StudyMode
  • Topic: Main function, Triangle fan, Command-line argument
  • Pages : 5 (518 words )
  • Download(s) : 90
  • Published : March 3, 2013
Open Document
Text Preview
2013
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);
glutCreateWindow("My Program!");
glutDisplayFunc(Display);
glClearColor(1.0,1.0,1.0,0.0);
glutMainLoop();
}

3. Draw following diagram using OpenGL primitives.
#include<GL\glut.h>
void Display(){
glClear(GL_COLOR_BUFFER_BIT);

glBegin(GL_TRIANGLES);
glColor3f(0.0,0.0,1.0);
glVertex2f(0.0,0.8);
glVertex2f(0.7,-0.4);
glVertex2f(-0.7,-0.4);

glColor3f(0.0,1.0,0.0);
glVertex2f(0.0,-0.9);
glVertex2f(0.5,-0.2);
glVertex2f(-0.5,-0.2);
glEnd();

glBegin(GL_POLYGON);
glColor3f(1.0,0.0,0.0);
glVertex2f(-0.09,-0.195);
glVertex2f(0.09,-0.195);
glVertex2f(0.15,-0.04);
glVertex2f(0.0,0.095);
glVertex2f(-0.15,-0.04);
glEnd();

glBegin(GL_POLYGON);
glColor3f(1.0,1.0,0.0);
glVertex2f(0.0,0.095);
glVertex2f(0.15,0.17);
glVertex2f(0.15,0.32);
glVertex2f(0.0,0.4);
glVertex2f(-0.15,0.32);
glVertex2f(-0.15,0.17);
glEnd();

glFlush();
}

void main(int argc, char** argv){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowPosition(0,0);
glutInitWindowSize(600,600);
glutCreateWindow("My Program!");
glutDisplayFunc(Display);
glClearColor(1.0,1.0,1.0,0.0);
glutMainLoop();

}
tracking img