Le source : TP-Illumination.cpp
/* Auteur: Nicolas JANEY */
/* nicolas.janey@univ-fcomte.fr */
/* Mars 2003 */
/* Une sphere illuminee */
#include <stdlib.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"
#include "ModuleCouleurs.h"
static GLfloat shininess = 64.0F ;
static float angle = 0.0F;
static float ouverture = 15.0F;
void myinit(void) {
GLfloat l_pos0[] = { -3.0F,0.0F,3.0F,0.0F };
glClearColor(0.5F,0.5F,0.5F,1.0F) ;
glMaterialfv(GL_FRONT,GL_DIFFUSE,couleurBlanc());
glMaterialfv(GL_FRONT,GL_SPECULAR,couleurJaune());
glLightfv(GL_LIGHT0,GL_POSITION,l_pos0);
glLightfv(GL_LIGHT0,GL_DIFFUSE,couleurRouge());
glLightfv(GL_LIGHT0,GL_SPECULAR,couleurVert());
glLightfv(GL_LIGHT1,GL_DIFFUSE,couleurBleu());
glLightfv(GL_LIGHT1,GL_SPECULAR,couleurBlanc());
glEnable(GL_LIGHTING);
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHT1);
glEnable(GL_CULL_FACE);
glDepthFunc(GL_LESS);
glEnable(GL_AUTO_NORMAL);
glEnable(GL_NORMALIZE);
}
void display(void) {
GLfloat l_pos1[] = { 10.0F,0.0F,10.0F,1.0F };
GLfloat l_dir1[] = { -10.0F,0.0F,-10.0F,1.0F };
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
manipulateurSouris();
manipulateurClavier();
glPushMatrix();
glRotatef(angle,0.0F,1.0F,0.0F);
glLightfv(GL_LIGHT1,GL_POSITION,l_pos1);
glLightfv(GL_LIGHT1,GL_SPOT_DIRECTION,l_dir1);
glLightf(GL_LIGHT1,GL_SPOT_CUTOFF,ouverture);
glPopMatrix();
glMaterialf(GL_FRONT,GL_SHININESS,shininess);
glutSolidSphere(5.0,300,200);
glPopMatrix();
glFlush();
glutSwapBuffers();
}
void idle(void) {
angle++;
glutPostRedisplay();
}
void key(unsigned char key,int x,int y) {
static int mode = 0;
if ( keyManipulateur(key,x,y) )
glutPostRedisplay();
else
switch ( key ) {
case 43 : ouverture += 0.1F ;
glutPostRedisplay();
break;
case 45 : ouverture -= 0.1F ;
if ( ouverture < 0.0F )
ouverture = 0.0F;
glutPostRedisplay();
break;
case 's' : shininess *= 1.03F ;
glutPostRedisplay();
break;
case 'S' : shininess /= 1.03F ;
glutPostRedisplay();
break;
case 0x0D : mode = !mode;
glutIdleFunc((mode) ? idle : NULL);
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("Illumination");
myinit();
creationMenuBasique();
setParametresOrthoBasique(-6.0,6.0,-6.0,6.0,-50.0,50.0);
setManipulateurDistance(1.0F);
glutReshapeFunc(reshapeOrthoBasique);
glutKeyboardFunc(key);
glutSpecialFunc(specialBasique);
glutMotionFunc(motionBasique);
glutMouseFunc(sourisBasique);
glutDisplayFunc(display);
glutMainLoop();
return(0);
}