/* Auteur: Nicolas JANEY */ /* Avril 2001 */ /* Un programme OpenGL tout simple */ /* mais complet */ #include #include #include #include #include #include static float rotx = 0.0f ; static float roty = 0.0f ; static float rotz = 0.0f ; void CALLBACK display(void) { glClear(GL_COLOR_BUFFER_BIT); glPushMatrix(); glRotatef(rotx,1.0f,0.0f,0.0f); glRotatef(roty,0.0f,1.0f,0.0f); glRotatef(rotz,0.0f,0.0f,1.0f); glBegin(GL_POLYGON) ; glColor3f(1.0F,0.0F,0.0F) ; glVertex2f(-0.5F,-0.5F) ; glColor3f(0.0F,1.0F,0.0F) ; glVertex2f(-0.5F,0.5F) ; glColor3f(1.0F,1.0F,1.0F) ; glVertex2f(0.5F,0.5F) ; glColor3f(0.0F,0.0F,1.0F) ; glVertex2f(0.5F,-0.5F) ; glEnd() ; glPopMatrix(); glFlush(); auxSwapBuffers(); } void myinit (void) { glClearColor (0.0,0.0,0.0,0.0); glShadeModel(GL_SMOOTH); } void CALLBACK myReshape(int w, int h) { glViewport(0,0,w,h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-1.0,1.0,-1.0/w*h,1.0/w*h,-1.0,1.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } void CALLBACK auxX(void) { rotx += 2 ; } void CALLBACK auxx(void) { rotx -= 2 ; } void CALLBACK auxY(void) { roty += 2 ; } void CALLBACK auxy(void) { roty -= 2 ; } void CALLBACK auxZ(void) { rotz += 2 ; } void CALLBACK auxz(void) { rotz -= 2 ; } void main(void) { auxInitDisplayMode(AUX_DOUBLE|AUX_RGBA); auxInitPosition(0,0,300,220); auxInitWindow("Carré coloré") ; myinit(); auxKeyFunc(AUX_X,auxX) ; auxKeyFunc(AUX_x,auxx) ; auxKeyFunc(AUX_Y,auxY) ; auxKeyFunc(AUX_y,auxy) ; auxKeyFunc(AUX_Z,auxZ) ; auxKeyFunc(AUX_z,auxz) ; auxReshapeFunc(myReshape); auxMainLoop(display); }