// GLUT key handling code #include "key.h" #include "view.h" #include "draw.h" #include "motion.h" #include "imgtex.h" // Apple's annoying non-standard GL include location #if defined(__APPLE__) || defined(MACOSX) #include #else #include #endif #include #include // called on any keypress // // We don't use x and y, but they're the mouse location when the key // was pressed. extern "C" void key(unsigned char k, int /*x*/, int /*y*/) { char *image; FILE *ifile; switch (k) { case 't': case 'T': { // t: switch to teapot drawStyle = DRAW_TEAPOT; glutPostRedisplay(); break; } case 's': case 'S': { // s: switch to sphere drawStyle = DRAW_SPHERE; glutPostRedisplay(); break; } case 'd': case 'D': { // d: switch to torus (donut) drawStyle = DRAW_DONUT; glutPostRedisplay(); break; } case 'p': case 'P': { // p: switch to plane drawStyle = DRAW_PLANE; glutPostRedisplay(); break; } case 'i': case 'I': { // i: dump image dumpIMG("dump.png",0,0,winWidth,winHeight); break; } case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': { // numbers adjust frame counters (see draw.h for mapping) updateFrame(k-'0'); break; } case 27: { // Escape: exit exit(0); } case '?': { printf("Keyboard commands:\n\ what to draw\n\ t: draw teapot\n\ s: draw sphere\n\ d: draw donut (torus)\n\ p: draw plane\n\ animated color (can be used to animate shaders)\n\ 1/2: decrease/increase rate of change in red\n\ 3/4: decrease/increase rate of change in green\n\ 5/6: decrease/increase rate of change in blue\n\ 7/8: decrease/increase rate of change in alpha\n\ 0: stop changes in all color channels\n\ 9: reset all color channels to 0\n\ i: dump image to 'dump.png'\n\ ESC: quit\n"); break; } } }