1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
| #include <gl/glut.h>
#include <string.h>
void bitmap_output(int x,int y,char *string,void *font);
void Clavier(unsigned char touche,int x,int y);
void Reshape(int w, int h);
void Affichage();
double a = 1;
int ecranComplet;
int main( int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
glutInitWindowSize(250, 250);
glutInitWindowPosition(500, 300);
glutCreateWindow("OpenGL");
glClearColor(0.0,0.0,0.0,0.0);
glEnable(GL_DEPTH_TEST);
glutReshapeFunc(Reshape);
glutDisplayFunc(Affichage);
glutKeyboardFunc(Clavier);
glutMainLoop();
return 0;
}
void Affichage()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW) ;
glLoadIdentity();
gluLookAt(0,0,-10,0,0,0,0,1,0);
if (a <= -8) ecranComplet = 0;
if (a >= 8) ecranComplet = 1;
if (!ecranComplet) a += 0.1;
if (ecranComplet) a -= 0.1;
glTranslated (0,0,a);
glBegin (GL_QUADS);
glColor3d (0,1,1);glVertex3i (-3,-3,3);
glColor3d (1,0,0);glVertex3i (-3,3,3);
glColor3d (0,1,0);glVertex3i (3,3,3);
glColor3d (1,0,1);glVertex3i (3,-3,3);
glColor3d (0,0,1);glVertex3i (-3,-3,-3);
glColor3d (1,1,0);glVertex3i (-3,3,-3);
glColor3d (1,1,1);glVertex3i (3,3,-3);
glColor3d (.5,.5,.5);glVertex3i (3,-3,-3);
glColor3d (1,1,0);glVertex3i (-3,3,-3);
glColor3d (1,1,1);glVertex3i (3,3,-3);
glColor3d (0,1,0);glVertex3i (3,3,3);
glColor3d (1,0,0);glVertex3i (-3,3,3);
glColor3d (0,0,1);glVertex3i (-3,-3,-3);
glColor3d (.5,.5,.5);glVertex3i (3,-3,-3);
glColor3d (1,0,1);glVertex3i (3,-3,3);
glColor3d (0,1,1);glVertex3i (-3,-3,3);
glColor3d (0,0,1);glVertex3i (-3,-3,-3);
glColor3d (0,1,1);glVertex3i (-3,-3,3);
glColor3d (1,0,0);glVertex3i (-3,3,3);
glColor3d (1,1,0);glVertex3i (-3,3,-3);
glColor3d (.5,.5,.5);glVertex3i (3,-3,-3);
glColor3d (1,0,1);glVertex3i (3,-3,3);
glColor3d (0,1,0);glVertex3i (3,3,3);
glColor3d (1,1,1);glVertex3i (3,3,-3);
glEnd();
glFlush();
//glutFullScreen();
glutSwapBuffers();
}
void Reshape(int w, int h)
{
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45,(float) w/h,1.,500.);
}
void Clavier(unsigned char touche,int x,int y)
{
switch (touche)
{
case 'd':
glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
glutPostRedisplay(); break;
case 'w':
glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
glutPostRedisplay(); break;
case 's' :
glPolygonMode(GL_FRONT_AND_BACK,GL_POINT);
glutPostRedisplay(); break;
case 'a' :
glutFullScreen(); break;
case 'q' :
exit(0);
}
} |
Partager