Question
Type the following function description in computer graphices opengl void declare(char *string) { while(*string) glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *string++); } ///////////////////// void draw_pixel(GLint cx, GLint cy) { glBegin(GL_POINTS);
Type the following function description in computer graphices opengl
void declare(char *string) { while(*string) glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *string++); } /////////////////////
void draw_pixel(GLint cx, GLint cy) {
glBegin(GL_POINTS); glVertex2i(cx,cy); glEnd(); }
/////////////////////
void plotpixels(GLint h,GLint k, GLint x,GLint y) { draw_pixel(x+h,y+k); draw_pixel(-x+h,y+k); draw_pixel(x+h,-y+k); draw_pixel(-x+h,-y+k); draw_pixel(y+h,x+k); draw_pixel(-y+h,x+k); draw_pixel(y+h,-x+k); draw_pixel(-y+h,-x+k); }
///////////////////////////////////////////////
void draw_circle(GLint h, GLint k, GLint r) { GLint d=1-r, x=0, y=r; while(y>x) { plotpixels(h,k,x,y); if(d<0) d+=2*x+3; else { d+=2*(x-y)+5; --y; } ++x; } plotpixels(h,k,x,y); } ////////////////////////
void draw_object() { int l; if(day==1) { //sky glColor3f(0.0,0.9,0.9); glBegin(GL_POLYGON); glVertex2f(0,380); glVertex2f(0,700); glVertex2f(1100,700); glVertex2f(1100,380); glEnd(); /////////////////////////////////////////////////////////
void traffic_light() { int l; if(light==1) { for(l=0;l<=20;l++) {
glColor3f(0.0,0.0,0.0); draw_circle(1065,475,l);
glColor3f(0.0,0.7,0.0); draw_circle(1065,375,l); } }
else {
for(l=0;l<=20;l++) { glColor3f(1.0,0.0,0.0); draw_circle(1065,475,l);
glColor3f(0.0,0.0,0.0); draw_circle(1065,375,l); } } }
//////////////////////////////////////////
void idle() { glClearColor(1.0,1.0,1.0,1.0);
if(light==0 && (i>=0 && i<=1150)) {
i+=SPEED/10; m+=SPEED/150; n-=2; o+=0.2; c+=2;
} if(light==0 && (i>=2600 && i<=3000)) {
i+=SPEED/10; m+=SPEED/150; n-=2; o+=0.2; c+=2;
}
if(light==0) { i=i; m+=SPEED/150; n-=2; o+=0.2; c+=2;
}
else {
i+=SPEED/10; m+=SPEED/150; n-=2; o+=0.2; c+=2; } if(i>3500) i=0.0; if(m>1100) m=0.0; if( o>75) { plane=0; } if(c>500) { comet=0; } glutPostRedisplay();
}
void mouse(int btn,int state,int x,int y) { if(btn==GLUT_LEFT_BUTTON && state==GLUT_UP) exit(0); } /////////////////////////////////////////////
void keyboardFunc( unsigned char key, int x, int y ) { switch( key ) { case 'g': case 'G': light=1; break;
case 'r': case 'R': light=0; break;
case 'd': case 'D': day=1; break;
case 'n': case 'N': day=0; break; case 't': case 'T': train=1; i=0; break;
};
} ////////////////////////////////////////////////
void myinit() { glClearColor(1.0,1.0,1.0,1.0); glColor3f(0.0,0.0,1.0); glPointSize(2.0); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0.0,1100.0,0.0,700.0); }
void display() {
glClear(GL_COLOR_BUFFER_BIT); draw_object(); traffic_light(); glFlush(); }
int main(int argc,char** argv) { int c_menu; printf("Project by CSEMiniProjects.com "); printf("--------------------------------------------------------------------------------"); printf(" ARRIVAL AND DEPARTURE OF TRAIN "); printf("--------------------------------------------------------------------------------"); printf("Press 'r' or 'R' to change the signal light to red. "); printf("Press 'g' or 'G' to change the signal light to green. "); printf("Press 'd' or 'D' to make it day. "); printf("Press 'n' or 'N' to make it night. "); printf("Press 't' or 'T' Train arrive at station. "); printf("Press RIGHT MOUSE BUTTON to display menu. "); printf("Press LEFT MOUSE BUTTON to quit the program. "); printf("Press any key and Hit ENTER. "); scanf("%s",&ch);
glutInit(&argc,argv); glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); glutInitWindowSize(1100.0,700.0); glutInitWindowPosition(0,0); glutCreateWindow("Traffic Control"); glutDisplayFunc(display); glutIdleFunc(idle); glutKeyboardFunc(keyboardFunc); glutMouseFunc(mouse); myinit(); c_menu=glutCreateMenu(main_menu); glutAddMenuEntry("Aeroplane",1); glutAddMenuEntry("Comet",2); glutAttachMenu(GLUT_RIGHT_BUTTON); glutMainLoop(); return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started