#include #include #include #include
#define TRUE 1 #define FALSE 0 /* Dimensions of texture image. */ #define IMAGE_WIDTH 64 #define IMAGE_HEIGHT 64 /* Step to be taken for each rotation. */ #define ANGLE_STEP 10 /* Magic numbers for relationship b/w cylinder head and crankshaft. */ #define MAGNITUDE 120 #define PHASE 270.112 #define FREQ_DIV 58 #define ARC_LENGHT 2.7 #define ARC_RADIUS 0.15 /* Rotation angles */ GLdouble view_h = 270, view_v = 0, head_angle = 0; GLint crank_angle = 0; /* Crank rotation step. */ GLdouble crank_step = 5; /* Toggles */ GLshort shaded = TRUE, anim = FALSE; GLshort texture = FALSE, transparent = FALSE; GLshort light1 = TRUE, light2 = FALSE; /* Storage for the angle look up table and the texture map */ GLdouble head_look_up_table[361]; GLubyte image[IMAGE_WIDTH][IMA image[IMAGE_WIDTH][IMAGE_HEIGHT][3]; GE_HEIGHT][3]; /* Indentifiers for each Display list */ GLint list_piston_shaded = 1; GLint list_piston_texture = 2; GLint list_flywheel_shaded = 4; GLint list_flywheel_texture = 8; int first=1,sec=2,third=3, first=1,sec=2,third=3,fourth=4; fourth=4; void keyboard1(unsigned char,int,int); void keyboard2(unsigned char key,int x,int y); void display1(void); void myreshape1(int w,int h); void myreshape2(int w,int h); void display2(void); void keyboard3(unsigned char key,int x,int y); void display3(void); void myreshape3(int w,int h); void DrawTextXY(double x,double y,double z,double scale,char *s); /* Variable used in the creaton of glu objects */ GLUquadricObj *obj; /* Draws a box by scaling a glut cube of size 1. Also checks the shaded
toggle to see which rendering style to use. NB Texture doesn't work correctly due to the cube being scaled. */ void myBox(GLdouble x, GLdouble y, GLdouble z) { glPushMatrix(); glScalef(x, y, z); if (shaded) glutSolidCube(1); else glutWireCube(1); glPopMatrix(); } /* Draws a cylinder using glu function, drawing flat disc's at each end, to give the appearence of it being solid. */ void myCylinder(GLUquadricObj * object, GLdouble outerRadius, GLdouble innerRadius, GLdouble lenght) { glPushMatrix(); gluCylinder(object, outerRadius, outerRadius, lenght, 20, 1); glPushMatrix(); glRotatef(180, 0.0, 1.0, 0.0); gluDisk(object, innerRadius, outerRadius, 20, 1); glPopMatrix(); glTranslatef(0.0, 0.0, lenght); gluDisk(object, innerRadius, outerRadius, 20, 1); glPopMatrix(); } //this function is used to create the blades of wind mill void myBlade(GLdouble x, GLdouble y, GLdouble z) { glPushMatrix(); glScalef(x, y, z); if (shaded) glutSolidCube(1); else glutWireCube(1); glPopMatrix(); } /* Draws a piston. */ void draw_bolt(void) { glPushMatrix(); glColor4f(0.6, 0.6, 0.6, 1.0); glPushMatrix(); glRotatef(90, 0.0, 1.0, 0.0); glTranslatef(0.0, 0.0, -0.07); myCylinder(obj, 0.125, 0.06, 0.12); glPopMatrix(); glRotatef(-90, 1.0, 0.0, 0.0); glTranslatef(0.0, 0.0, 0.1); myCylinder(obj, 0.06, 0.0, 0.2);
//bolt
//this displays the flywheel of the blad
e glTranslatef(0.0, 0.0, 0.85); glRotatef(35,0.0,0.0,1.0); myBlade(0.2, 0.00, 1.3);//this diplays or creats a blade glPushMatrix(); glTranslatef(0.0,0.0,0.67); glRotatef(90,0.0,1.0,0.0); glRotatef(-90,1.0,0.0,0.0); gluDisk(obj,0,0.1,20,1); glPopMatrix(); glPopMatrix(); /******************************************************************************* ********/ glColor4f(0.5, 0.1, 0.5, 1.0); glPushMatrix(); glTranslatef(0.22, -0.31, -0.17); glRotatef(-90, 0.0, 1.0, 0.0); myCylinder(obj, 0.06, 0.0, 0.34);//the purple color cylinder con necting the wing or piston glPopMatrix(); glPushMatrix(); glColor4f(0.6, 0.6, 0.6, 1.0); glPushMatrix(); glRotatef(90, 0.0, 1.0, 0.0); glTranslatef(0.175, -0.31, -0.07); myCylinder(obj, 0.125, 0.06, 0.12); glPopMatrix(); glRotatef(155, 1.0, 0.0, 0.0); glTranslatef(0.0, 0.19, 0.4); myCylinder(obj, 0.06, 0.0, 0.2); //this displays the flywheel of the blade glTranslatef(0.0, 0.0, 0.85); glRotatef(35,0.0,0.0,1.0); myBlade( 0.2, 0.00, 1.3); //this diplays or creats a piston glPushMatrix(); glTranslatef(0.0,0.0,0.67); glRotatef(90,0.0,1.0,0.0); glRotatef(-90,1.0,0.0,0.0); gluDisk(obj,0,0.1,20,1); glPopMatrix(); glPopMatrix(); /***************************************************************************** ***********************/ glColor4f(0.5, 0.1, 0.5, 1.0); glPushMatrix(); glTranslatef(0.22, -0.31, 0.17); glRotatef(-90, 0.0, 1.0, 0.0); myCylinder(obj, 0.06, 0.0, 0.34); der connecting the wing or piston glPopMatrix(); glPushMatrix();
//the purple color cylin
glColor4f(0.6, 0.6, 0.6, 1.0); glPushMatrix(); glRotatef(90, 0.0, 1.0, 0.0); glTranslatef(-0.175, -0.31, -0.07); myCylinder(obj, 0.125, 0.06, 0.12); glPopMatrix(); glRotatef(33, 1.0, 0.0, 0.0); glTranslatef(0.0, -0.17, 0.43); myCylinder(obj, 0.06, 0.0, 0.2); //this displays the flywheel of the blade glTranslatef(0.0, 0.0, 0.85); glRotatef(35,0.0,0.0,1.0); myBlade(0.2, 0.00, 1.3); //this diplays or creats a piston glPushMatrix(); glTranslatef(0.0,0.0,0.67); glRotatef(90,0.0,1.0,0.0); glRotatef(-90,1.0,0.0,0.0); gluDisk(obj,0,0.1,20,1); glPopMatrix(); glPopMatrix(); } /* Draws the engine pole and the pivot pole for the cylinder head. */ void draw_shaft_cube(void) { glPushMatrix(); glColor4f(0.709, 0.596, 0.1765, 1.0); glTranslatef(-1.5,-0.8,0.0); myBox(0.5, 1.0, 0.6); //this used to construct the cube to held the pole glPopMatrix(); }
/* Draws the flywheel. */ void draw_flywheel(void) { glPushMatrix(); glColor4f(0.5, 0.5, 1.0, 1.0); glRotatef(90, 0.0, 1.0, 0.0); glTranslatef(0.0, 0.0, -3); myCylinder(obj, 0.3, 0.08, 0.7); he end of the shaft glPopMatrix(); }
void draw_bladecluster(void) { glPushMatrix(); glColor4f(1.0, 0.5, 0.5, 1.0); glRotatef(90, 0.0, 1.0, 0.0);
//this is the blue splitring that is at t
myCylinder(obj, 0.3, 0.08, 0.12); e attached glColor4f(0.5, 0.1, 0.5, 1.0); glTranslatef(0.0, 0.2, 0.0); myCylinder(obj, 0.06, 0.0, 0.34); he wing or piston
//the red color fly disc where wings ar
//the purple color cylinder connecting t
glTranslatef(0.0, 0.0, 0.22); glRotatef(90, 0.0, 1.0, 0.0); if (shaded) { if (texture) glCallList(list_piston_texture); else glCallList(list_piston_shaded); } else draw_bolt(); glPopMatrix(); } /* Draws the complete crank. Piston also gets drawn through the crank bell function. */ void draw_blade(void) { glPushMatrix(); glRotatef(crank_angle, 1.0, 0.0, 0.0); glColor4f(0.447,0.404,0.227,1.0); glPushMatrix(); glRotatef(90, 0.0, 1.0, 0.0); glTranslatef(0.0, 0.0, -4.0); myCylinder(obj, 0.08, 0.0, 4.4); //This is the lever between the 2 fly wheel glPopMatrix(); glPushMatrix(); glTranslatef(0.28, 0.0, 0.0); draw_bladecluster(); isplays the 3 blades bolted to the flywheel(pink) glPopMatrix(); glPushMatrix(); glTranslatef(-0.77, 0.0, 0.0); if (shaded) { if (texture) glCallList(list_flywheel_texture); else glCallList(list_flywheel_shaded); } else draw_flywheel(); glPopMatrix(); glPopMatrix(); } void display(void) { int pass;
//this d
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glutFullScreen(); glColor3f(-0.2,-0.6,-0.9); DrawTextXY(2.0,2.0,-1.0,0.0012,"s : shading"); DrawTextXY(2.0,1.8,-1.0,0.0012,"t : texture"); DrawTextXY(2.0,1.6,-1.0,0.0012,"space :wind toggle"); DrawTextXY(2.0,1.4,-1.0,0.0012,"0 : lights toggle"); DrawTextXY(2.0,1.2,-1.0,0.0012,"+ : increase wind "); DrawTextXY(2.0,1.0,-1.0,0.0012," speed"); DrawTextXY(2.0,0.8,-1.0,0.0012,"- : decrease wind "); DrawTextXY(2.0,0.6,-1.0,0.0012," speed"); DrawTextXY(2.0,0.4,-1.0,0.0012,"c : back"); DrawTextXY(2.0,0.2,-1.0,0.0012,"m : main page"); DrawTextXY(2.0,0.0,-1.0,0.0012,"e : exit");
glPushMatrix(); if (transparent) { glEnable(GL_ALPHA_TEST); pass = 2; } else { glDisable(GL_ALPHA_TEST); pass = 0; } /* Rotate the whole model */ glRotatef(view_h, 0, 1, 0); glRotatef(view_v, 1, 0, 0); do { if (pass == 2) { glAlphaFunc(GL_EQUAL, 1); glDepthMask(GL_TRUE); pass--; } else if (pass != 0) { glAlphaFunc(GL_NOTEQUAL, 1); glDepthMask(GL_FALSE); pass--; } draw_shaft_cube(); y the cube connected to shaft which rotates
//used to displa
glPushMatrix(); glTranslatef(0.0, -0.8, 0.0); draw_blade(); glPopMatrix(); } while (pass > 0); glDepthMask(GL_TRUE); glutSwapBuffers(); glPopMatrix(); } /* Called when the window is idle. When called increments the crank angle by ANGLE_STEP, updates the head angle and notifies the system that
the screen needs to be updated. */ void animation(void) { if ((crank_angle += crank_step) >= 360) crank_angle = 0; head_angle = head_look_up_table[crank_angle]; glutPostRedisplay(); } /* Called when a key is pressed. Checks if it reconises the key and if so acts on it, updateing the screen. */ /* ARGSUSED1 */ void keyboard(unsigned char key, int x, int y) { switch (key) { case 's': if (shaded == FALSE) { shaded = TRUE; glShadeModel(GL_SMOOTH); glEnable(GL_LIGHTING); glEnable(GL_DEPTH_TEST); glEnable(GL_COLOR_MATERIAL); gluQuadricNormals(obj, GLU_SMOOTH); gluQuadricDrawStyle(obj, GLU_FILL); } else { shaded = FALSE; glShadeModel(GL_FLAT); glDisable(GL_LIGHTING); glDisable(GL_DEPTH_TEST); glDisable(GL_COLOR_MATERIAL); gluQuadricNormals(obj, GLU_NONE); gluQuadricDrawStyle(obj, GLU_LINE); gluQuadricTexture(obj, GL_FALSE); } if (texture && !shaded); else break; case 't': if (texture == FALSE) { texture = TRUE; glEnable(GL_TEXTURE_2D); gluQuadricTexture(obj, GL_TRUE); } else { texture = FALSE; glDisable(GL_TEXTURE_2D); gluQuadricTexture(obj, GL_FALSE); } break; case 'a': if ((crank_angle += crank_step) >= 360) crank_angle = 0; head_angle = head_look_up_table[crank_angle]; break; case 'z': if ((crank_angle -= crank_step) <= 0) crank_angle = 360; head_angle = head_look_up_table[crank_angle];
break; case '0': if (light1) { glDisable(GL_LIGHT0); light1 = FALSE; } else { glEnable(GL_LIGHT0); light1 = TRUE; } break; case '1': if (light2) { glDisable(GL_LIGHT1); light2 = FALSE; } else { glEnable(GL_LIGHT1); light2 = TRUE; } break; case '4': if ((view_h -= ANGLE_STEP) <= 0) view_h = 360; break; case '6': if ((view_h += ANGLE_STEP) >= 360) view_h = 0; break; case '8': if ((view_v += ANGLE_STEP) >= 360) view_v = 0; break; case '2': if ((view_v -= ANGLE_STEP) <= 0) view_v = 360; break; case ' ': if (anim) { glutIdleFunc(0); anim = FALSE; } else { glutIdleFunc(animation); anim = TRUE; } break; case '+': if ((++crank_step) > 45) crank_step = 45; break; case '-': if ((--crank_step) <= 0) crank_step = 0; break; case 'e': exit(0); break; case 'h': case 'H': case 'c' : case 'C' :keyboard1('c',0,0); case 'm' : case 'M' :keyboard2('m',0,0); default: return; }
glutPostRedisplay(); } /* ARGSUSED1 */ void special(int key, int x, int y) { switch (key) { case GLUT_KEY_LEFT: if ((view_h -= ANGLE_STEP) view_h = 360; break; case GLUT_KEY_RIGHT: if ((view_h += ANGLE_STEP) view_h = 0; break; case GLUT_KEY_UP: if ((view_v += ANGLE_STEP) view_v = 0; break; case GLUT_KEY_DOWN: if ((view_v -= ANGLE_STEP) view_v = 360; break; case GLUT_KEY_F1: exit(0); default: return; } glutPostRedisplay(); }
<= 0)
>= 360)
>= 360)
<= 0)
/* Called when a menu option has been selected. Translates the menu item identifier into a keystroke, then call's the keyboard function. */ void menu(int val) { unsigned char key; switch (val) { case 1: key = 's'; keyboard(key, break; case 2: key = ' '; keyboard(key, break; case 3: key = 't'; keyboard(key, break; case 4: key = 'o'; keyboard(key, break; case 5: key = '0'; keyboard(key, break;
0, 0);
0, 0);
0, 0);
0, 0);
0, 0);
case 6: key = '1'; keyboard(key, 0, 0); break; case 7: key = '+'; keyboard(key, 0, 0); break; case 8: key = '-'; keyboard(key, 0, 0); break; case 9: key= 'e'; keyboard(key, 0, 0); break; case 10: glutDestroyWindow(third); fourth=glutCreateWindow("help"); glutKeyboardFunc(keyboard3); glutDisplayFunc(display3); glutReshapeFunc(myreshape3); glutMainLoop(); break; case 11:glutDestroyWindow(first); sec=glutCreateWindow("home"); glutReshapeFunc(myreshape2); glutKeyboardFunc(keyboard2); glutDisplayFunc(display2); glutMainLoop(); break; case 12:glutDestroyWindow(fourth); first=glutCreateWindow("Windmill Simulation by Darshan and Prash ant"); glutReshapeFunc(myreshape1); glutKeyboardFunc(keyboard1); glutDisplayFunc(display1); glutMainLoop(); break; default: return; } } /* Initialises the menu of toggles. */ void create_menu(void) { glutCreateMenu(menu); glutAttachMenu(GLUT_LEFT_BUTTON); glutAttachMenu(GLUT_RIGHT_BUTTON); glutAddMenuEntry("Shaded", 1); glutAddMenuEntry("Blow Wind", 2); glutAddMenuEntry("Texture", 3); glutAddMenuEntry("Lights On/Off", 5); glutAddMenuEntry("Wind Speed UP", 7); glutAddMenuEntry("Wind Slow Down", 8); glutAddMenuEntry("Exit", 9); glutAddMenuEntry("Help", 10);
glutAddMenuEntry("Home Page", 11); glutAddMenuEntry("Main Page", 12); } /* Makes a simple check pattern image. (Copied from the redbook example "checker.c".) */ void make_image(void) { int i, j, c; for (i = 0; i < IMAGE_WIDTH; i++) { for (j = 0; j < IMAGE_HEIGHT; j++) { c = (((i & 0x8) == 0) ^ (((j & 0x8)) == 0)) * 255; image[i][j][0] = (GLubyte) c; image[i][j][1] = (GLubyte) c; image[i][j][2] = (GLubyte) c; } } } /* Makes the head look up table for all possible rotation of blade angles */ void make_table(void) { GLint i; GLdouble k; for (i = 0, k = 0.0; i < 360; i++, k++) { head_look_up_table[i] = MAGNITUDE * atan( (ARC_RADIUS * sin(PHASE - k / FREQ_DIV)) / ((ARC_LENGHT - ARC_RADIUS * cos(PHASE - k / FREQ_DIV)))); } } /* Initialises texturing, lighting, display lists, and everything else associated with the model. */ void myinit(void) { GLfloat mat_specular[] = {1.0, 1.0, 1.0, 1.0}; GLfloat mat_shininess[] = {50.0}; GLfloat light_position1[] = {1.0, 1.0, 1.0, 0.0}; GLfloat light_position2[] = {-1.0, 1.0, 1.0, 0.0}; glClearColor(0.0, 0.0, 0.0, 0.0); obj = gluNewQuadric(); make_table(); make_image(); /* Set up Texturing */ glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glTexImage2D(GL_TEXTURE_2D, 0, 3, IMAGE_WIDTH, IMAGE_HEIGHT, 0, GL_RGB, GL_UNSIGNED_BYTE, image); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); /* Set up Lighting */ glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess); glLightfv(GL_LIGHT0, GL_POSITION, light_position1); glLightfv(GL_LIGHT1, GL_POSITION, light_position2); /* Initial render mode is with full shading and LIGHT 0 enabled. */ glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glDepthFunc(GL_LEQUAL); glEnable(GL_DEPTH_TEST); glDisable(GL_ALPHA_TEST); glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE); glEnable(GL_COLOR_MATERIAL); glShadeModel(GL_SMOOTH); /* Initialise display lists */ glNewList(list_piston_shaded, GL_COMPILE); draw_bolt(); glEndList(); glNewList(list_flywheel_shaded, GL_COMPILE); draw_flywheel(); glEndList(); gluQuadricTexture(obj, GL_TRUE); glNewList(list_piston_texture, GL_COMPILE); draw_bolt(); glEndList(); glNewList(list_flywheel_texture, GL_COMPILE); draw_flywheel(); glEndList(); gluQuadricTexture(obj, GL_FALSE); } /* Called when the model's window has been reshaped. */ void myReshape(int w, int h) { glClearColor(1.0,1.0,1.0,1.0); glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(65.0, (GLfloat) w / (GLfloat) h, 1.0, 30.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0.5, 0.8, -5.2); /* viewing transform */ glScalef(1.5, 1.5, 1.5); } void myreshape3(int w,int h) { glClearColor(1.0,1.0,1.0,1.0); glViewport(0,0,w,h); glMatrixMode(GL_PROJECTION); glLoadIdentity();
if(w<=h) glOrtho(-2.0,2.0,-2.0*(GLfloat)h/(GLfloat)w,2.0*(GLfloat)h/(GLf loat)w,-10.0,10.0); else glOrtho(-2.0*(GLfloat)w/(GLfloat)h,2.0*(GLfloat)w/(GLfloat)h,-2.0,2 .0,-10.0,10.0); } void DrawTextXY(double x,double y,double z,double scale,char *s) { int i,l=strlen(s); glPushMatrix(); glTranslatef(x,y,z); glScalef(scale,scale,scale); for (i=0;i CLICK ON THE RIGHT BUTTON TO VIEW ME NUS"); DrawTextXY(-2.65,1.0,0.0,0.0012,"-> THE MENUS PRESENT ARE:"); glColor3f(0.369,0.2901,0.596); DrawTextXY(-2.65,0.8,0.0,0.001," 1.SHADE ENABLE/DISABLE 2.WIND START/ST OP 3.TEXURE ENABLE/DISABLE"); DrawTextXY(-2.65,0.6,0.0,0.001," 4.LIGHTS ON/OFF 5.WIND VELOCITY UP 6.WI ND VELOCITY DOWN"); DrawTextXY(-2.65,0.4,0.0,0.001," 7.EXIT 8.HELP 9.HOME PAGE 10.MAIN PAGE" ); glColor3f(0.518,0.62,0.266); DrawTextXY(-2.65,0.0,0.0,0.0010,"Press 's' to toggle shading "); DrawTextXY(-2.65,-0.2,0.0,0.0010,"Press 't' to toggle texture "); DrawTextXY(-2.65,-0.4,0.0,0.0010,"Press 'o' to toggle transparency"); DrawTextXY(-2.65,-0.6,0.0,0.0010,"Press 'z' to rotate the crank clockwis e"); DrawTextXY(-2.65,-0.8,0.0,0.0010,"Press ation"); DrawTextXY(-2.65,-1.0,0.0,0.0010,"Press ation "); DrawTextXY(-2.65,-1.2,0.0,0.0010,"Press glColor3f(0.1,0.6,1.0); DrawTextXY(-2.65,-1.6,0.0,0.0015,"Press DrawTextXY(-2.65,-1.8,0.0,0.0015,"Press glutSwapBuffers(); glFlush(); } void keyboard3(unsigned char key,int x,int y) { if(key=='H'||key=='h')
'+' to increase the speed of rot '-' to decrease the speed of rot '0' to toggle lighting"); 'h' to go to options "); 'm' to go to main page");
{ glutDestroyWindow(fourth); sec=glutCreateWindow("home"); glutReshapeFunc(myreshape2); glutKeyboardFunc(keyboard2); glutDisplayFunc(display2); glutMainLoop(); } if(key=='m'||key=='M') { glutDestroyWindow(fourth); first=glutCreateWindow("Windmill Simulation by Darshan and Prash ant"); glutReshapeFunc(myreshape1); glutKeyboardFunc(keyboard1); glutDisplayFunc(display1); glutMainLoop(); } } void keyboard2(unsigned char key,int x,int y) { if(key=='a'||key=='A') { glutDestroyWindow(sec); third=glutCreateWindow("Windmill Simulation by Darshan B S and Prashanth G") ; /* Transperancy won't work properly without GLUT_ALPHA */ glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_MULTISAMPLE); glutDisplayFunc(display); glutKeyboardFunc(keyboard); glutSpecialFunc(special); create_menu(); myinit(); glutReshapeFunc(myReshape); glutMainLoop(); } if(key=='b'||key=='B') { glutDestroyWindow(sec); fourth=glutCreateWindow("help"); glutKeyboardFunc(keyboard3); glutDisplayFunc(display3); glutReshapeFunc(myreshape3); glutMainLoop(); } if(key=='m' || key=='M') { glutDestroyWindow(first); first=glutCreateWindow("Windmill Simulation by Darshan and Prashant"); glutReshapeFunc(myreshape1); glutKeyboardFunc(keyboard1);
glutDisplayFunc(display1); glutMainLoop(); } if(key=='c'||key=='C') exit(0); } void display2(void) { glClear(GL_COLOR_BUFFER_BIT); glutFullScreen(); glColor3f(0.0,0.0,1.0); DrawTextXY(-0.5,1.5,0.0,0.0022,"OPTIONS"); DrawTextXY(-1.0,0.80,0.0,0.0015,"PRESS A : EXECUTION"); DrawTextXY(-1.0,0.0,0.0,0.0015,"PRESS B : HELP"); DrawTextXY(-1.0,-0.80,0.0,0.0015,"PRESS C : EXIT"); DrawTextXY(-1.0,-1.60,0.0,0.0015,"PRESS M : MAIN PAGE"); glutSwapBuffers(); glFlush(); } void myreshape1(int w,int h) { glClearColor(1.0,1.0,1.0,1.0); glViewport(0,0,w,h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); if(w<=h) glOrtho(-2.0,2.0,-2.0*(GLfloat)h/(GLfloat)w,2.0*(GLfloat)h/(GLf loat)w,-10.0,10.0); else glOrtho(-2.0*(GLfloat)w/(GLfloat)h,2.0*(GLfloat)w/(GLfloat)h,-2.0,2 .0,-10.0,10.0); } void myreshape2(int w,int h) { glClearColor(1.0,1.0,1.0,1.0); glViewport(0,0,w,h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); if(w<=h) glOrtho(-2.0,2.0,-2.0*(GLfloat)h/(GLfloat)w,2.0*(GLfloat)h/(GLf loat)w,-10.0,10.0); else glOrtho(-2.0*(GLfloat)w/(GLfloat)h,2.0*(GLfloat)w/(GLfloat)h,-2.0,2 .0,-10.0,10.0); } void display1(void) { glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glutFullScreen(); glColor3f(0.941,0.368,0.141); DrawTextXY(-3.10,1.70,0.0,0.0022,"VISVESVARAYA TECHNOLOGICAL UNIVERSITY" ); DrawTextXY(-0.7,1.5,0.0,0.0012,"Belgaum,Karnataka"); glColor3f(0.125,0.027,0.843); DrawTextXY(-1.0,1.0,0.0,0.0015,"Press C to continue "); glColor3f(0.627,0.063,0.522); DrawTextXY(-0.7,.60,0.0,0.0015,"PROJECT TITLE"); glColor3f(0.976,0.027,0.796); DrawTextXY(-3.1,0.30,0.0,0.00210,"Graphical Implementation Of Miniature Windmill"); DrawTextXY(-3.05,0.00,0.0,0.00210," Simulation"); glColor3f(0.0,0.0,0.0); DrawTextXY(-0.65,-0.3,0.0,0.0015,"Submitted By: ");
DrawTextXY(-3.2,-0.550,0.0,0.0012,"DARSHAN B S (1BY07CS020) PR ASHANTH G (1BY07CS021)"); glColor3f(0.133,0.957,0.024); DrawTextXY(-2.5,-0.85,0.0,0.0015," Under the guidance of:"); DrawTextXY(-3.0,-1.05,0.0,0.00125," Mr. MUNESHWARA M S"); DrawTextXY(-0.5,-1.17,0.0,0.0008,"Lecturer, Dept of CSE"); DrawTextXY(-0.1,-1.3,0.0,0.0008,"BMSIT"); glColor3f(0.5451,0.0627,0.0118); DrawTextXY(-2.3,-1.65,0.0,0.0022,"BMS INSTITUTE OF TECHNOLOGY"); DrawTextXY(-2.5,-1.80,0.0,0.0012," Avallahalli,Doddaballapura Main Road,Yelahanka,"); DrawTextXY(-0.6,-1.95,0.0,0.0012,"Bangalore-560064"); glutSwapBuffers(); glFlush(); } void keyboard1(unsigned char key,int x,int y) { if(key=='c'||key=='C') { glutDestroyWindow(first); sec=glutCreateWindow("Home page"); glutReshapeFunc(myreshape2); glutKeyboardFunc(keyboard2); glutDisplayFunc(display2); glutMainLoop(); } } /* Main program. An interactive model of a miniture steam engine. Sets system in Double Buffered mode and initialises all the call-back functions. */ int main(int argc, char **argv) { puts("Windmill Simulation by Darshan and Prashanth\n"); puts("Keypad Arrow keys (with NUM_LOCK on) rotates object."); puts("Rotate crank: 'a' = anti-clock wise 'z' = clock wise"); puts("Wind Speed : '+' = Speed up by 1 '-' = Slow Down by 1"); puts("Toggle : 's' = Shading 't' = Texture"); puts("Wind Start : ' ' = Blow wind "); puts("Exit : 'e' or F1"); puts(" Alternatively a pop up menu with all toggles is attached"); puts(" to the left mouse button.\n"); glutInitWindowSize(1274, 770); glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_MULTISAMPLE); first=glutCreateWindow("Main Page of Windmill Simulation by Darshan B S and Pr ashanth G"); glutReshapeFunc(myreshape1); glutDisplayFunc(display1); glutKeyboardFunc(keyboard1);
glutMainLoop(); return 0; }
/* ANSI C requires main to return int. */