Le source: EnsembleFacettes.cpp
/* Auteur: Nicolas JANEY */
/* nicolas.janey@univ-fcomte.fr */
/* Avril 2001 */
/* Generation OpenGL d'un volume (20 facettes) */
/* au moyen d'un ensemble de facettes */
#include <stdio.h>
#include <stdlib.h>
#include <GL/glut.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include "ModuleManipulateur.h"
#include "ModuleMenus.h"
#include "ModuleReshape.h"
#define X .525731112119133606f
#define Z .850650808352039932f
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 display(void) {
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
manipulateurSouris();
manipulateurClavier();
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();
glutSwapBuffers();
}
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);
glEnable(GL_AUTO_NORMAL);
glEnable(GL_NORMALIZE);
}
int main(int argc,char **argv) {
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE);
glutInitWindowSize(300,250);
glutInitWindowPosition(50,50);
glutCreateWindow("Ensemble de facettes");
myinit();
creationMenuBasique();
setParametresOrthoBasique(-1.3F,1.3F,-1.3F,1.3F,-100.0,100.0);
setManipulateurDistance(1.0F);
glutReshapeFunc(reshapeOrthoBasique);
glutKeyboardFunc(keyBasique);
glutSpecialFunc(specialBasique);
glutMotionFunc(motionBasique);
glutMouseFunc(sourisBasique);
glutDisplayFunc(display);
glutMainLoop();
return(0);
}