#include #include #include #include #define PI 3.14 static GLfloat Xrot, Xstep; static GLfloat Yrot, Ystep; static GLfloat Zrot, Zstep; static GLfloat Step = 0.5; /* author - s l reiser */ /* reshape callback */ void reshape (int w, int h) { glViewport (0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode (GL_PROJECTION); glLoadIdentity (); glOrtho (0.0, (GLdouble) w, 0.0, (GLdouble) h, -500.0, 500.0); glMatrixMode (GL_MODELVIEW); } /* input event - keyboard */ void keyboard(unsigned char key, int x, int y) { switch (key) { case 114: exit(0); break; } } /* program unique initialiations */ void myinit(void) { /* attributes */ glClearColor(0.0, 0.3, 0.50, 0.0); /* blue background */ glDepthFunc(GL_LEQUAL); glEnable(GL_DEPTH_TEST); /* set up viewing */ /* 500 x 500 x 500 window with origin lower left */ glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0, 500.0, 0.0, 500.0, -500.0, 000.0); glMatrixMode(GL_MODELVIEW); } /* display callback */ void display( void ) { glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); /*clear the window */ glColor3f(0.0, 1.0, 0.0); glBegin(GL_TRIANGLE_STRIP); /* hull */ glVertex3f(100.0,150.0,250.0); glVertex3f(150.0,150.0,350.0); glVertex3f(150.0,100.0,250.0); glVertex3f(350.0,150.0,350.0); glVertex3f(350.0,100.0,250.0); glVertex3f(400.0,150.0,250.0); glEnd(); glBegin(GL_TRIANGLE_STRIP); /* hull */ glVertex3f(400.0,150.0,250.0); glVertex3f(350.0,150.0,150.0); glVertex3f(350.0,100.0,250.0); glVertex3f(150.0,150.0,150.0); glVertex3f(150.0,100.0,250.0); glVertex3f(100.0,150.0,250.0); glEnd(); glColor3f(.8, .8, .8); /* mast */ glBegin(GL_QUAD_STRIP); glVertex3f(175.0,125.0, 260.0); glVertex3f(175.0,450.0, 260.0); glVertex3f(190.0,125.0, 260.0); glVertex3f(190.0,450.0, 260.0); glVertex3f(190.0,125.0, 240.0); glVertex3f(190.0,450.0, 240.0); glVertex3f(175.0,125.0, 240.0); glVertex3f(175.0,450.0, 240.0); glVertex3f(175.0,125.0, 260.0); glVertex3f(175.0,450.0, 260.0); glEnd(); glBegin(GL_QUADS); /*mast end caps */ glVertex3f(175.0,125.0, 260.0); glVertex3f(190.0,125.0, 260.0); glVertex3f(190.0,125.0, 240.0); glVertex3f(175.0,125.0, 240.0); glVertex3f(175.0,450.0, 260.0); glVertex3f(190.0,450.0, 260.0); glVertex3f(190.0,450.0, 240.0); glVertex3f(175.0,450.0, 240.0); glEnd(); glColor3f(1.0, 1.0, 1.0); /* sail*/ glBegin(GL_TRIANGLE_FAN); glVertex3f(100.0,200.0, 280.0); glVertex3f(210.0,470.0, 300.0); glVertex3f(270.0,350.0, 400.0); glVertex3f(300.0,275.0, 430.0); glVertex3f(360.0,200.0, 450.0); glEnd(); glColor3f(1.0, 1.0, 0.0); /* rudder */ glBegin(GL_QUAD_STRIP); /* skinny sides */ glVertex3i(325,165,248); glVertex3i(325,165,252); glVertex3i(425,165,248); glVertex3i(425,165,252); glVertex3i(425,155,248); glVertex3i(425,155,252); glVertex3i(325,155,248); glVertex3i(325,155,252); glVertex3i(325,165,248); glVertex3i(325,165,252); glEnd(); glBegin(GL_QUAD_STRIP); glVertex3i(425,165,248); glVertex3i(425,165,252); glVertex3i(430,100,248); glVertex3i(430,100,252); glVertex3i(440, 80,248); glVertex3i(440, 80,252); glVertex3i(425, 75,248); glVertex3i(425, 75,252); glVertex3i(410, 75,248); glVertex3i(410, 75,252); glVertex3i(410,155,248); glVertex3i(410,155,252); glVertex3i(425,165,248); glVertex3i(425,165,252); glEnd(); glBegin(GL_QUADS); /* large sides */ glVertex3i(325,165,248); glVertex3i(425,165,248); glVertex3i(425,155,248); glVertex3i(325,155,248); glEnd(); glBegin(GL_POLYGON); glVertex3i(425,165,248); glVertex3i(430,100,248); glVertex3i(440, 80,248); glVertex3i(425, 75,248); glVertex3i(410, 75,248); glVertex3i(410,155,248); glEnd(); glBegin(GL_QUADS); glVertex3i(325,165,252); glVertex3i(425,165,252); glVertex3i(425,155,252); glVertex3i(325,155,252); glEnd(); glBegin(GL_POLYGON); glVertex3i(425,165,252); glVertex3i(430,100,252); glVertex3i(440, 80,252); glVertex3i(425, 75,252); glVertex3i(410, 75,252); glVertex3i(410,155,252); glEnd(); // glPopMatrix(); /* go back to saved matrix */ glFlush(); /* clear buffers */ glutSwapBuffers(); /* switch buffers */ } void boatMenu(int value) { switch (value) { case 1: case 2: exit (0); break; } glutPostRedisplay(); } int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); /* set double buffering */ glutInitWindowSize (500, 500); glutInitWindowPosition (0, 0); glutCreateWindow ("Susan's Sailboat"); /* window title */ myinit (); /* set attributes */ glutCreateMenu(boatMenu); glutAddMenuEntry("Toggle Background", 1); glutAddMenuEntry("Quit", 2); glutAttachMenu(GLUT_RIGHT_BUTTON); glutDisplayFunc(display); glutReshapeFunc(reshape); glutKeyboardFunc(keyboard); glutMainLoop(); return 0; }