updated
git-svn-id: svn://anubis/misc/opengl@81 bd8a9e45-a331-0410-811e-c64571078777
This commit is contained in:
parent
07b6e80e7b
commit
0b030e341f
@ -1,76 +1,77 @@
|
|||||||
|
|
||||||
#include <GL/gl.h>
|
#include <GL/gl.h>
|
||||||
#include <GL/glu.h>
|
#include <GL/glu.h>
|
||||||
#include <GL/glut.h>
|
#include <GL/glut.h>
|
||||||
|
|
||||||
float r = 0.0;
|
float r = 0.0;
|
||||||
|
|
||||||
void init(void)
|
void init(void)
|
||||||
{
|
{
|
||||||
glClearColor (0.0, 0.0, 0.0, 0.0);
|
glClearColor (0.0, 0.0, 0.0, 0.0);
|
||||||
glShadeModel (GL_FLAT);
|
glShadeModel (GL_FLAT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void idle(void)
|
void idle(void)
|
||||||
{
|
{
|
||||||
r += 0.2;
|
r += 0.02;
|
||||||
glutPostRedisplay();
|
glutPostRedisplay();
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawcubes(int level, double size)
|
void drawcubes(int level, double size)
|
||||||
{
|
{
|
||||||
glutWireCube(size);
|
glutWireCube(size);
|
||||||
if (!level)
|
if (!level)
|
||||||
return;
|
return;
|
||||||
double a = 0.0;
|
double a = 0.0;
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < 4; i++)
|
for (i = 0; i < 4; i++)
|
||||||
{
|
{
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glRotatef(a, 0.0, 1.0, 0.0);
|
glRotatef(a, 0.0, 1.0, 0.0);
|
||||||
glTranslatef(size * 0.375, size * 0.625, size * 0.375);
|
glTranslatef(size * 0.375, size * 0.625, size * 0.375);
|
||||||
glRotatef(r, 0.0, 1.0, 0.0);
|
glRotatef(r, 0.0, 1.0, 0.0);
|
||||||
drawcubes(level - 1, size * 0.25);
|
drawcubes(level - 1, size * 0.25);
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
a += 90.0;
|
a += 90.0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void display(void)
|
void display(void)
|
||||||
{
|
{
|
||||||
glClear (GL_COLOR_BUFFER_BIT);
|
glClear (GL_COLOR_BUFFER_BIT);
|
||||||
glColor3f (1.0, 1.0, 1.0);
|
glColor3f (1.0, 1.0, 1.0);
|
||||||
glLoadIdentity (); /* clear the matrix */
|
glLoadIdentity (); /* clear the matrix */
|
||||||
/* viewing transformation */
|
/* viewing transformation */
|
||||||
glTranslatef(0.0, -1.0, -5.0);
|
glTranslatef(0.0, -1.0, -5.0);
|
||||||
glRotatef(40.0, 1.0, 0.0, 0.0);
|
glRotatef(40.0, 1.0, 0.0, 0.0);
|
||||||
glRotatef(r, 0.0, 1.0, 0.0);
|
glRotatef(r, 0.0, 1.0, 0.0);
|
||||||
|
|
||||||
drawcubes(4, 2.0);
|
drawcubes(4, 2.0);
|
||||||
|
|
||||||
glFlush ();
|
glFlush ();
|
||||||
glutSwapBuffers();
|
glutSwapBuffers();
|
||||||
}
|
}
|
||||||
|
|
||||||
void reshape (int w, int h)
|
void reshape (int w, int h)
|
||||||
{
|
{
|
||||||
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
|
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
|
||||||
glMatrixMode (GL_PROJECTION);
|
glMatrixMode (GL_PROJECTION);
|
||||||
glLoadIdentity ();
|
glLoadIdentity ();
|
||||||
gluPerspective(60.0, 4.0/3.0, 1.5, 20.0);
|
gluPerspective(60.0, 4.0/3.0, 1.5, 20.0);
|
||||||
glMatrixMode (GL_MODELVIEW);
|
glMatrixMode (GL_MODELVIEW);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
glutInit(&argc, argv);
|
glutInit(&argc, argv);
|
||||||
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);
|
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);
|
||||||
glutInitWindowSize (800, 600);
|
glutInitWindowSize (800, 600);
|
||||||
glutInitWindowPosition (-1, -1);
|
glutInitWindowPosition (-1, -1);
|
||||||
glutCreateWindow (argv[0]);
|
glutCreateWindow (argv[0]);
|
||||||
init ();
|
init ();
|
||||||
glutDisplayFunc(display);
|
glutDisplayFunc(display);
|
||||||
glutReshapeFunc(reshape);
|
glutReshapeFunc(reshape);
|
||||||
glutIdleFunc(idle);
|
glutIdleFunc(idle);
|
||||||
glutMainLoop();
|
glutMainLoop();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user