#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 color[6][3] = { { 1.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }, { 0.0, 0.0, 1.0 }, { 1.0, 1.0, 0.0 }, { 1.0, 0.0, 1.0 }, { 0.0, 1.0, 1.0 } }; glClear(GL_COLOR_BUFFER_BIT /* | GL_DEPTH_BUFFER_BIT *//* 追加 */); /* glEnable(GL_DEPTH_TEST); *//* 追加 */ glLoadIdentity(); gluLookAt(3.0, 4.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); glRotated((GLdouble)r, 0.0, 1.0, 0.0); glColor3d(0.0, 0.0, 0.0); glBegin(GL_QUADS); for (j = 0; j < 6; j++) { glColor3dv(color[j]); for (i = 0; i < 4; i++) { glVertex3dv(vertex[face[j][i]]); } } glEnd(); /* 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(); }