#include void idle(void) { glutPostRedisplay(); } void display(void) { int i, j; static int r = 0; GLdouble vertex[8][3] = { { 0.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0 }, { 1.0, 1.0, 0.0 }, { 0.0, 1.0, 0.0 }, { 0.0, 0.0, 1.0 }, { 1.0, 0.0, 1.0 }, { 1.0, 1.0, 1.0 }, { 0.0, 1.0, 1.0 } }; int face[6][4] = { { 0, 3, 2, 1 }, { 1, 2, 6, 5 }, { 4, 5, 6, 7 }, { 0, 4, 7, 3 }, { 0, 1, 5, 4 }, { 2, 3, 7, 6 } }; GLdouble normal[6][3] = { { 0.0, 0.0,-1.0 }, { 1.0, 0.0, 0.0 }, { 0.0, 0.0, 1.0 }, {-1.0, 0.0, 0.0 }, { 0.0,-1.0, 0.0 }, { 0.0, 1.0, 0.0 } }; GLfloat lpos[4] = {5.0, 5.0, 0.0, 1.0}; GLfloat lcol[4] = {0.5, 1.0, 0.5, 1.0}; GLfloat mcol[4] = {1.0, 0.5, 0.5, 1.0}; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable(GL_DEPTH_TEST); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glLoadIdentity(); gluLookAt(3.0, 4.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); /* glLightfv(GL_LIGHT0, GL_POSITION, lpos); *//* 追加 */ /* glLightfv(GL_LIGHT0, GL_DIFFUSE, lcol); *//* 追加 */ /* glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mcol); *//* 追加 */ glRotated((GLdouble)r, 0.0, 1.0, 0.0); glBegin(GL_QUADS); for (j = 0; j < 6; j++) { glNormal3dv(normal[j]); for (i = 0; i < 4; i++) { glVertex3dv(vertex[face[j][i]]); } } glEnd(); glDisable(GL_LIGHT0); glDisable(GL_LIGHTING); glDisable(GL_DEPTH_TEST); glutSwapBuffers(); if (++r >= 360) r = 0; } void resize(int w, int h) { glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(30.0, 1.0, 1.0, 10.0); glMatrixMode(GL_MODELVIEW); } void keyboard(unsigned char key, int x, int y) { if (key == '\033') exit(0); } int main(int argc, char *argv[]) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH); glutCreateWindow(argv[0]); glClearColor(1.0, 1.0, 1.0, 0.0); glutDisplayFunc(display); glutKeyboardFunc(keyboard); glutIdleFunc(idle); glutReshapeFunc(resize); glutMainLoop(); }