/* Auteur: Nicolas JANEY */
/* nicolas.janey@univ-fcomte.fr */
/* Avril 2001 */
/* Les lumieres en OpenGL */
#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 scene = 0 ;
void display(void) {
glClearColor(0.0F,0.0F,0.0F,0.0F);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
switch ( scene ) {
case 0 : glEnable(GL_LIGHT0);
glEnable(GL_LIGHT1);
glEnable(GL_LIGHT2);
break;
case 1 : glEnable(GL_LIGHT0);
glDisable(GL_LIGHT1);
glDisable(GL_LIGHT2);
break;
case 2 : glDisable(GL_LIGHT0);
glEnable(GL_LIGHT1);
glDisable(GL_LIGHT2);
break;
case 3 : glDisable(GL_LIGHT0);
glDisable(GL_LIGHT1);
glEnable(GL_LIGHT2);
break; }
glPushMatrix();
manipulateurSouris();
manipulateurClavier();
glPushMatrix();
glMaterialfv(GL_FRONT_AND_BACK,GL_EMISSION,couleurNoir()) ;
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,couleurCyan()) ;
glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,couleurRouge()) ;
glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,couleurNoir()) ;
glMaterialf(GL_FRONT_AND_BACK,GL_SHININESS,100) ;
glTranslatef(-1.5F,0.0F,0.0F) ;
glutSolidSphere(1.0,50,50) ;
glPopMatrix();
glPushMatrix();
glMaterialfv(GL_FRONT_AND_BACK,GL_EMISSION,couleurNoir()) ;
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,couleurMagenta()) ;
glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,couleurNoir()) ;
glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,couleurNoir()) ;
glMaterialf(GL_FRONT_AND_BACK,GL_SHININESS,0) ;
glTranslatef(1.5F,0.0F,0.0F) ;
glRotatef(-90.0f,1.0f,0.0f,0.0f);
glTranslatef(0.0f,0.0f,-1.0f);
glutSolidCone(1.0,2.0,50,50) ;
glPopMatrix();
glPopMatrix();
glFlush();
glutSwapBuffers();
}
void myinit (void) {
glShadeModel(GL_SMOOTH);
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
float dir0[] = { -1.0f,0.0f,1.0f,0.0f } ;
glLightfv(GL_LIGHT0,GL_DIFFUSE,couleurCyan()) ;
glLightfv(GL_LIGHT0,GL_SPECULAR,couleurCyan()) ;
glLightfv(GL_LIGHT0,GL_AMBIENT,couleurNoir()) ;
glLightfv(GL_LIGHT0,GL_POSITION,dir0) ;
float pos1[] = { 4.0f,0.0f,0.0f,1.0f } ;
glLightfv(GL_LIGHT1,GL_DIFFUSE,couleurJaune()) ;
glLightfv(GL_LIGHT1,GL_SPECULAR,couleurJaune()) ;
glLightfv(GL_LIGHT1,GL_AMBIENT,couleurNoir()) ;
glLightfv(GL_LIGHT1,GL_POSITION,pos1) ;
float pos2[] = { -1.5f,0.0f,5.0f,1.0f } ;
float dir2[] = { 0.0f,0.0f,-1.0f,0.0f } ;
glLightfv(GL_LIGHT2,GL_DIFFUSE,couleurBleu()) ;
glLightfv(GL_LIGHT2,GL_SPECULAR,couleurBleu()) ;
glLightfv(GL_LIGHT2,GL_AMBIENT,couleurNoir()) ;
glLightfv(GL_LIGHT2,GL_POSITION,pos2) ;
glLightfv(GL_LIGHT2,GL_SPOT_DIRECTION,dir2) ;
glLightf(GL_LIGHT2,GL_SPOT_CUTOFF,0.15F*180.0F/3.14159F) ;
glEnable(GL_AUTO_NORMAL);
glEnable(GL_NORMALIZE);
}
void key(unsigned char key,int x,int y) {
if ( keyManipulateur(key,x,y) )
glutPostRedisplay();
else
switch ( key ) {
case 0x0D : scene = (scene+1)%4;
glutPostRedisplay();
break; }
}
int main(int argc,char **argv) {
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE);
glutInitWindowSize(300,150);
glutInitWindowPosition(50,50);
glutCreateWindow("Lumieres et materiaux");
myinit();
creationMenuBasique();
setParametresOrthoBasique(-1.8F,1.8F,-1.8F,1.8F,-500.0,500.0);
setManipulateurDistance(1.0F);
glutReshapeFunc(reshapeOrthoBasique);
glutKeyboardFunc(key);
glutSpecialFunc(specialBasique);
glutMotionFunc(motionBasique);
glutMouseFunc(sourisBasique);
glutDisplayFunc(display);
glutMainLoop();
return(0);
}