/* Displays a sphere and allows you to change the stacks and slices. Written by Scott D. Anderson scott.anderson@acm.org Fall 2003 */ #include #include #include int Stacks = 4; int Slices = 4; bool wire = true; // when true, draw a wire-frame figure. Controlled by a key callback. void display(void) { twDisplayInit(); twCamera(); twColorName(TW_BLUE); if(wire) glutWireSphere(4,Slices,Stacks); else glutSolidSphere(4,Slices,Stacks); glFlush(); glutSwapBuffers(); // necessary for animation } void adjust(unsigned char key, int x, int y) { switch(key) { case '1': Slices++; break; case '2': Slices--; break; case '3': Stacks++; break; case '4': Stacks--; break; case 'w': wire = !wire; } glutPostRedisplay(); } int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); twInitWindowSize(500,500); glutCreateWindow(argv[0]); glutDisplayFunc(display); twBoundingBox(-4,+4,-4,+4,-4,+4); twMainInit(); twKeyCallback('1',adjust,"More Slices"); twKeyCallback('2',adjust,"Fewer Slices"); twKeyCallback('3',adjust,"More Stacks"); twKeyCallback('4',adjust,"Fewer Stacks"); twKeyCallback('w',adjust,"toggle wireframe mode"); glutMainLoop(); return 0; }