In: Computer Science
Write a program to draw a Pentagon with blue color inside a window. Using C ++ with Output.
#include<iostream.h>
//Install GLUT If you do not have GLUT installed on your machine
#include<GL/glut.h>
//this is car function
void car(){
//define the color of class
glClearColor(.3,.16,.4,1);
//Clear the color of buffer bit
glClear(GL_COLOR_BUFFER_BIT);
//set the width of line
glLineWidth(5);
//start draw polygon from here
glBegin(GL_POLYGON);
//set color
glColor3f(.1,.1,.1);
//set vertex .2 from x axis and .2 from y axis
glVertex2f(.2,.2);
//set vertex .2 from x axis and -.2 from y axis
glVertex2f(.2,-.2);
//set vertex -.2 from x axis and -.2 from y axis
glVertex2f(-.2,-.2);
//set vertex -.2 from x axis and .2 from y axis
glVertex2f(-.2,.2);
//set vertex 0 from x axis and .4 from y axis
glVertex2f(0,.4);
//End of gl
glEnd();
//Flush gl function
glFlush();
}
//starting of main function
//passing two arguments in it
void main(int argc, char **argv){
//Initialize gl function and pass two arguments in it
glutInit(&argc, argv);
//initialize the size of window
glutInitWindowSize(600,600);
//Create window
glutCreateWindow("CAR");
//call car function
glutDisplayFunc(car);
//call MainLoop
glutMainLoop();
}