From 0b030e341f927b157bb27fa6e3d9b1bc777b76dc Mon Sep 17 00:00:00 2001 From: josh Date: Sun, 30 Nov 2008 22:26:44 +0000 Subject: [PATCH] updated git-svn-id: svn://anubis/misc/opengl@81 bd8a9e45-a331-0410-811e-c64571078777 --- spincube/cube.c | 93 +++++++++++++++++++++++++------------------------ 1 file changed, 47 insertions(+), 46 deletions(-) diff --git a/spincube/cube.c b/spincube/cube.c index eaa280f..6a94636 100644 --- a/spincube/cube.c +++ b/spincube/cube.c @@ -1,76 +1,77 @@ + #include #include #include float r = 0.0; -void init(void) +void init(void) { - glClearColor (0.0, 0.0, 0.0, 0.0); - glShadeModel (GL_FLAT); + glClearColor (0.0, 0.0, 0.0, 0.0); + glShadeModel (GL_FLAT); } void idle(void) { - r += 0.2; - glutPostRedisplay(); + r += 0.02; + glutPostRedisplay(); } void drawcubes(int level, double size) { - glutWireCube(size); - if (!level) - return; - double a = 0.0; - int i; - for (i = 0; i < 4; i++) - { - glPushMatrix(); - glRotatef(a, 0.0, 1.0, 0.0); - glTranslatef(size * 0.375, size * 0.625, size * 0.375); - glRotatef(r, 0.0, 1.0, 0.0); - drawcubes(level - 1, size * 0.25); - glPopMatrix(); - a += 90.0; - } + glutWireCube(size); + if (!level) + return; + double a = 0.0; + int i; + for (i = 0; i < 4; i++) + { + glPushMatrix(); + glRotatef(a, 0.0, 1.0, 0.0); + glTranslatef(size * 0.375, size * 0.625, size * 0.375); + glRotatef(r, 0.0, 1.0, 0.0); + drawcubes(level - 1, size * 0.25); + glPopMatrix(); + a += 90.0; + } } void display(void) { - glClear (GL_COLOR_BUFFER_BIT); - glColor3f (1.0, 1.0, 1.0); - glLoadIdentity (); /* clear the matrix */ - /* viewing transformation */ - glTranslatef(0.0, -1.0, -5.0); - glRotatef(40.0, 1.0, 0.0, 0.0); - glRotatef(r, 0.0, 1.0, 0.0); + glClear (GL_COLOR_BUFFER_BIT); + glColor3f (1.0, 1.0, 1.0); + glLoadIdentity (); /* clear the matrix */ + /* viewing transformation */ + glTranslatef(0.0, -1.0, -5.0); + glRotatef(40.0, 1.0, 0.0, 0.0); + glRotatef(r, 0.0, 1.0, 0.0); - drawcubes(4, 2.0); + drawcubes(4, 2.0); - glFlush (); - glutSwapBuffers(); + glFlush (); + glutSwapBuffers(); } void reshape (int w, int h) { - glViewport (0, 0, (GLsizei) w, (GLsizei) h); - glMatrixMode (GL_PROJECTION); - glLoadIdentity (); - gluPerspective(60.0, 4.0/3.0, 1.5, 20.0); - glMatrixMode (GL_MODELVIEW); + glViewport (0, 0, (GLsizei) w, (GLsizei) h); + glMatrixMode (GL_PROJECTION); + glLoadIdentity (); + gluPerspective(60.0, 4.0/3.0, 1.5, 20.0); + glMatrixMode (GL_MODELVIEW); } int main(int argc, char** argv) { - glutInit(&argc, argv); - glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB); - glutInitWindowSize (800, 600); - glutInitWindowPosition (-1, -1); - glutCreateWindow (argv[0]); - init (); - glutDisplayFunc(display); - glutReshapeFunc(reshape); - glutIdleFunc(idle); - glutMainLoop(); - return 0; + glutInit(&argc, argv); + glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB); + glutInitWindowSize (800, 600); + glutInitWindowPosition (-1, -1); + glutCreateWindow (argv[0]); + init (); + glutDisplayFunc(display); + glutReshapeFunc(reshape); + glutIdleFunc(idle); + glutMainLoop(); + return 0; }