Le source: EnsembleFacttes.cpp
#include <windows.h> #include <GL/gl.h> #include <GL/glu.h> #include <GL/glaux.h> #include <stdio.h> #include <stdlib.h> #define X .525731112119133606 #define Z .850650808352039932 static float anglex = 0.0F ; static float angley = 0.0F ; static GLfloat vdata[12][3] = { {-X,0,Z},{X,0,Z},{-X,0,-Z},{X,0,-Z}, {0,Z,X},{0,Z,-X},{0,-Z,X},{0,-Z,-X}, {Z,X,0},{-Z,X,0},{Z,-X,0},{-Z,-X,0}} ; static GLint tindices[20][3] = { {0,4,1},{0,9,4},{9,5,4},{4,5,8},{4,8,1}, {8,10,1},{8,3,10},{5,3,8},{5,2,3},{2,7,3}, {7,10,3},{7,6,10},{7,11,6},{9,2,5},{0,1,6}, {6,1,10},{9,0,11},{9,11,2},{11,0,6}, {7,2,11}}; void CALLBACK display(void) { glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glPushMatrix(); glRotatef(angley,0.0F,1.0F,0.0F) ; glRotatef(anglex,1.0F,0.0F,0.0F) ; for ( int i = 0 ; i < 20 ; i++ ) { glBegin(GL_TRIANGLES) ; glNormal3fv(&vdata[tindices[i][0]][0]); glVertex3fv(&vdata[tindices[i][0]][0]); glNormal3fv(&vdata[tindices[i][1]][0]); glVertex3fv(&vdata[tindices[i][1]][0]); glNormal3fv(&vdata[tindices[i][2]][0]); glVertex3fv(&vdata[tindices[i][2]][0]); glEnd() ; } glPopMatrix(); glFlush(); auxSwapBuffers(); } void myinit (void) { glClearColor(0.6F,0.6F,0.3F,0.0F); glShadeModel(GL_SMOOTH); glEnable(GL_DEPTH_TEST); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); } void CALLBACK myReshape(int w, int h) { glViewport(0,0,w,h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-1.3,1.3,-1.3/w*h,1.3/w*h,-1.3,1.3); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } void CALLBACK up(void) { anglex++ ; } void CALLBACK down(void) { anglex-- ; } void CALLBACK left(void) { angley++ ; } void CALLBACK right(void) { angley-- ; } void main(void) { auxInitDisplayMode(AUX_DOUBLE|AUX_RGBA|AUX_DEPTH); auxInitPosition(0,0,300,250); auxInitWindow("Ensemble de facettes") ; myinit(); auxKeyFunc(AUX_UP,up) ; auxKeyFunc(AUX_DOWN,down) ; auxKeyFunc(AUX_LEFT,left) ; auxKeyFunc(AUX_RIGHT,right) ; auxReshapeFunc(myReshape); auxMainLoop(display); }
RETOUR