/* demoQuadric.c */ /* Purpose - create a quadric geometric object */ #include #include #include #include #define KEY_ESC 27 /* GLUT doesn't supply this */ /* Global variables */ GLUquadricObj* pQuadric; GLvoid keyboard(GLubyte key, GLint x, GLint y) { switch (key) { case KEY_ESC: exit(0); /* exit when ESC pressed */ break; } } GLvoid checkError( const char* const label ) { GLenum error; error = glGetError(); while (GL_NO_ERROR != error ) { fprintf(stderr,"%s: %s\n", label, gluErrorString(error) ); error = glGetError(); } } /* Note that the CALLBACK is necessary to work under MS Windows. To make this work on unix as well as MS Windows, do this: #ifndef WIN32 #define CALLBACK #endif */ GLvoid CALLBACK checkError2( GLvoid ) { checkError("Quadric Error"); } GLvoid display(GLvoid) { /* Do all your OpenGL rendering here */ GLfloat ww; GLfloat wh; glClear(GL_COLOR_BUFFER_BIT); glLoadIdentity(); /* reset modelview */ /* get current window size */ ww = glutGet(GLUT_WINDOW_WIDTH); wh = glutGet(GLUT_WINDOW_HEIGHT); /* Draw a tapering cylinder with baseRadius = 1.0, topRadius = 0.5, height = 0.8, slices = 12, stacks = 6 */ glRotatef(45.0, 1.0, 1.0, 0.0); /* First viewport */ glViewport(0,0,ww/2,wh/2); gluQuadricDrawStyle( pQuadric, GLU_POINT ); gluCylinder(pQuadric, 1.0, 0.5, 0.8, 12, 6 ); /* draw another object : gluQuadricDrawStyle( pQuadric, GLU_LINE ); gluPartialDisk( pQuadric, 0.4, 1.0, 12, 6, 0.0, 120.0); */ /* Second viewport */ glViewport(ww/2,0,ww/2,wh/2); gluQuadricDrawStyle( pQuadric, GLU_LINE ); gluCylinder(pQuadric, 1.0, 0.5, 0.8, 12, 6 ); /* Third viewport */ glViewport(0,wh/2,ww/2,wh/2); gluQuadricDrawStyle( pQuadric, GLU_SILHOUETTE ); gluCylinder(pQuadric, 1.0, 0.5, 0.8, 12, 6 ); /* Fourth viewport */ glViewport(ww/2,wh/2,ww/2,wh/2); gluQuadricDrawStyle( pQuadric, GLU_FILL ); gluCylinder(pQuadric, 1.0, 0.5, 0.8, 12, 6 ); checkError("display"); glFlush(); } void init(void) { /* set background color */ glClearColor(0.4,0.4,0.7,1.0); /* set the 2D orthographic projection */ glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-2.0,2.0,-2.0,2.0,-2.0,2.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } int main(int argc, char* argv[]) { glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB ); glutCreateWindow(argv[0]); init(); glutDisplayFunc(display); glutKeyboardFunc(keyboard); /* allocate a quadric creation object */ pQuadric = gluNewQuadric(); /* Set up quadric error callback function */ gluQuadricCallback( pQuadric, GLU_ERROR, checkError2 ); glutMainLoop(); /* After finishing with a quadric creation object, we should delete it; but the execution never gets to here. */ gluDeleteQuadric( pQuadric ); return 0; }