回転するティーポット
「r」と「l」でティーポットが回転する。
#include<GL/glut.h> int angle = 0; void init(char *name) { int width = 200, height = 200; glutInitDisplayMode(GLUT_RGBA); glutInitWindowSize(width, height); glutCreateWindow(name); glClearColor(0.0, 0.0, 0.0, 1.0); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(90.0, (double)width / (double)height, 0.1, 18); } void display(void) { glClear(GL_COLOR_BUFFER_BIT); glPushMatrix(); glColor3d(0.0, 1.0, 1.0); glTranslatef(0.0, 0.0, -3.0); glRotated(angle, 1.0, 0.0, 0.0); glutWireTeapot(1.3); glPopMatrix(); glFlush(); } void keyboard(unsigned char key, int x, int y) { switch (key) { case 'r': angle += 10; glutPostRedisplay(); break; case 'l': angle -= 10; glutPostRedisplay(); break; default: break; } } int main(int argc, char **argv){ glutInit(&argc, argv); init(argv[0]); glutDisplayFunc(display); glutKeyboardFunc(keyboard); glutMainLoop(); return 0; }