/* LetterL.c * * define display lists that draw the 3D letter L */ #include #include #include #define FLAT_L 1 #define SMOOTH_L 2 #define NPOINTS 12 #define NPOLYGONS 10 extern void getNormals(); void createDisplayLists() { int face, pt, pindex; /* Define the geometry */ GLdouble point[NPOINTS][3] = {{0.0, 0.0, 1.0}, {2.0, 0.0, 1.0}, {2.0, 1.0, 1.0}, {1.0, 1.0, 1.0}, {1.0, 3.0, 1.0}, {0.0, 3.0, 1.0}, {0.0, 0.0, 0.0}, {2.0, 0.0, 0.0}, {2.0, 1.0, 0.0}, {1.0, 1.0, 0.0}, {1.0, 3.0, 0.0}, {0.0, 3.0, 0.0}}; int polygon[NPOLYGONS][4] = {{0, 1, 2, 3}, /* front faces */ {0, 3, 4, 5}, {9, 8, 7, 6}, /* back faces */ {11, 10, 9, 6}, {0, 5, 11, 6}, /* side faces */ {1, 0, 6, 7}, {2, 1, 7, 8}, {3, 2, 8, 9}, {4, 3, 9, 10}, {5, 4, 10, 11}}; /* Generate the normals for the letter */ GLdouble face_normals[NPOLYGONS][3]; GLdouble point_normals[NPOINTS][3]; getNormals (point, NPOINTS, polygon, NPOLYGONS, face_normals, point_normals); /* Create a display list for flat shading */ glNewList (FLAT_L, GL_COMPILE); for (face = 0; face < NPOLYGONS; face++) { glBegin(GL_POLYGON); glNormal3dv(face_normals[face]); for (pt = 0; pt < 4; pt++) /* draw all points on the face */ glVertex3dv (point[polygon[face][pt]]); glEnd(); } glEndList(); /* Create a display list for smooth shading */ glNewList (SMOOTH_L, GL_COMPILE); for (face = 0; face < NPOLYGONS; face++) { glBegin(GL_POLYGON); for (pt = 0; pt < 4; pt++) { /* draw all points on the face */ pindex = polygon[face][pt]; glNormal3dv (point_normals[pindex]); glVertex3dv (point[pindex]); } glEnd(); } glEndList(); }