Le source : TP-MateriauxFacette.cpp
/* Auteur: Nicolas JANEY */
/* nicolas.janey@univ-fcomte.fr */
/* Mars 2003 */
/* Materiux sur les sommets d'une facette */
/* transparente situee devant une sphere */
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <GL/glut.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include "ModuleCouleurs.h"
#include "ModuleManipulateur.h"
#include "ModuleMenus.h"
#include "ModuleReshape.h"
static int disc = 50;
static int ordre = 1;
typedef struct Position {
float x ;
float y ;
float z ; } Position ;
void facette(void) {
glPushMatrix();
Position p1 = { -8.0F,-7.0F,0.0F } ;
Position p2 = { 8.0F,-8.0F,0.0F } ;
Position p3 = { 6.0F,8.0F,0.0F } ;
Position p4 = { -6.0F,7.0F,0.0F } ;
glBegin(GL_QUADS);
glNormal3f(0.0F,0.0F,1.0F);
glMaterialfv(GL_FRONT,GL_SPECULAR,couleurVert(0.2F));
glMaterialfv(GL_FRONT,GL_DIFFUSE,couleurRouge(0.2F));
glMaterialf(GL_FRONT,GL_SHININESS,64.0F);
glVertex3fv((float *) &p1);
glMaterialfv(GL_FRONT,GL_SPECULAR,couleurRouge(0.5F));
glMaterialfv(GL_FRONT,GL_DIFFUSE,couleurJaune(0.5F));
glMaterialf(GL_FRONT,GL_SHININESS,64.0F);
glVertex3fv((float *) &p2);
glMaterialfv(GL_FRONT,GL_SPECULAR,couleurJaune(1.0F));
glMaterialfv(GL_FRONT,GL_DIFFUSE,couleurVert(1.0F));
glMaterialf(GL_FRONT,GL_SHININESS,64.0F);
glVertex3fv((float *) &p3);
glMaterialfv(GL_FRONT,GL_SPECULAR,couleurJaune(1.0F));
glMaterialfv(GL_FRONT,GL_DIFFUSE,couleurBleu(1.0F));
glMaterialf(GL_FRONT,GL_SHININESS,64.0F);
glVertex3fv((float *) &p4);
glEnd();
glPopMatrix();
}
void sphere(void) {
glPushMatrix();
glMaterialfv(GL_FRONT,GL_SPECULAR,couleurNoir(1.0F));
glMaterialfv(GL_FRONT,GL_DIFFUSE,couleurBlanc(1.0F));
glMaterialf(GL_FRONT,GL_SHININESS,64.0F);
glTranslatef(0.0F,0.0F,-20.0F);
glutSolidSphere(5.0,72,72);
glPopMatrix();
}
void display(void) {
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
if ( ordre ) {
sphere();
manipulateurSouris();
manipulateurClavier();
facette(); }
else {
glPushMatrix();
manipulateurSouris();
manipulateurClavier();
facette();
glPopMatrix();
sphere(); }
glPopMatrix();
glFlush();
glutSwapBuffers();
}
void myinit (void) {
glClearColor(0.5,0.5,0.5,1.0) ;
GLfloat l_pos0[] = { 1.0,1.0,3.2,0.0 };
glLightfv(GL_LIGHT0,GL_POSITION,l_pos0);
GLfloat l_pos1[] = { -1.0,1.0,3.5,0.0 };
glLightfv(GL_LIGHT1,GL_POSITION,l_pos1);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHT1);
glDepthFunc(GL_LESS);
glEnable(GL_DEPTH_TEST);
glShadeModel(GL_SMOOTH);
}
void key(unsigned char key,int x,int y) {
if ( keyManipulateur(key,x,y) )
glutPostRedisplay();
else
switch ( key ) {
case 0x0D : ordre = !ordre;
glutPostRedisplay();
break; }
}
int main(int argc,char **argv) {
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE);
glutInitWindowSize(300,300);
glutInitWindowPosition(50,50);
glutCreateWindow("Materiaux sur facette");
myinit();
creationMenuBasique();
setParametresOrthoBasique(-10.0,10.0,-10.0,10.0,-50.0,50.0);
setManipulateurDistance(1.0F);
glutReshapeFunc(reshapeOrthoBasique);
glutKeyboardFunc(key);
glutSpecialFunc(specialBasique);
glutMotionFunc(motionBasique);
glutMouseFunc(sourisBasique);
glutIdleFunc(idleBasique);
glutDisplayFunc(display);
glutMainLoop();
return(0);
}