#include #include #include const double TWO_PI = 6.2831853; /* Initial display-window size. */ GLsizei winWidth = 400, winHeight = 400; GLuint regHex; class screenPt { public: GLint x, y; }; static void init (void) { screenPt hexVertex, circCtr; GLdouble theta; GLint k; /* Set circle center coordinates. */ circCtr.x = winWidth / 2; circCtr.y = winHeight / 2; glClearColor (1.0, 1.0, 1.0, 0.0); // Display-window color = white. /* Set up a display list for a red regular hexagon. * Vertices for the hexagon are six equally spaced * points around the circumference of a circle. */ regHex = glGenLists (1); // Get an identifier for the display list. glNewList (regHex, GL_COMPILE); glColor3f (1.0, 0.0, 0.0); // Set fill color for hexagon to red. glBegin (GL_POLYGON); for (k = 0; k < 6; k++) { theta = TWO_PI * k / 6.0; hexVertex.x = circCtr.x + 150 * cos (theta); hexVertex.y = circCtr.y + 150 * sin (theta); glVertex2i (hexVertex.x, hexVertex.y); } glEnd ( ); glEndList ( ); } void regHexagon (void) { glClear (GL_COLOR_BUFFER_BIT); glCallList (regHex); glFlush ( ); } void winReshapeFcn (int newWidth, int newHeight) { glMatrixMode (GL_PROJECTION); glLoadIdentity ( ); gluOrtho2D (0.0, (GLdouble) newWidth, 0.0, (GLdouble) newHeight); glClear (GL_COLOR_BUFFER_BIT); } void main (int argc, char** argv) { glutInit (&argc, argv); glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); glutInitWindowPosition (100, 100); glutInitWindowSize (winWidth, winHeight); glutCreateWindow ("Reshape-Function & Display-List Example"); init ( ); glutDisplayFunc (regHexagon); glutReshapeFunc (winReshapeFcn); glutMainLoop ( ); }