/* Auteur: Nicolas JANEY */
/* nicolas.janey@univ-fcomte.fr */
/* Avril 2001 */
/* Les lumieres en OpenGL */
#include <GL/glaux.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 obj = 0 ;
static float anglex = 0.0F ;
static float angley = 0.0F ;
static float anglez = 0.0F ;
void myinit(void) {
GLfloat mat_shininess[] = { 50.0 };
glMaterialfv(GL_FRONT,GL_SPECULAR,couleurBlanc());
glMaterialfv(GL_FRONT,GL_SHININESS,mat_shininess);
glLightfv(GL_LIGHT0,GL_DIFFUSE,couleurRouge());
glLightfv(GL_LIGHT1,GL_DIFFUSE,couleurVert());
glLightfv(GL_LIGHT2,GL_DIFFUSE,couleurBleu());
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHT1);
glEnable(GL_LIGHT2);
glDepthFunc(GL_LESS);
glEnable(GL_DEPTH_TEST);
glEnable(GL_AUTO_NORMAL);
glEnable(GL_NORMALIZE);
}
void display(void) {
GLfloat light0_position[] = { 1.0,1.0,1.0,0.0 };
GLfloat light1_position[] = { -1.0,1.0,1.0,0.0 };
GLfloat light2_position[] = { 1.0,-1.0,1.0,0.0 };
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix() ;
manipulateurSouris();
manipulateurClavier();
glPushMatrix() ;
glRotatef(anglex,1.0F,0.0F,0.0F);
glRotatef(angley,0.0F,1.0F,0.0F);
glRotatef(anglez,0.0F,0.0F,1.0F);
glLightfv(GL_LIGHT0,GL_POSITION,light0_position);
glLightfv(GL_LIGHT1,GL_POSITION,light1_position);
glLightfv(GL_LIGHT2,GL_POSITION,light2_position);
glPopMatrix() ;
glPushMatrix() ;
if ( obj )
glutSolidSphere(1.0,70,70);
else
auxSolidSphere(1.0);
glPopMatrix() ;
glPopMatrix() ;
glFlush();
glutSwapBuffers() ;
}
void idle(void) {
anglex++ ;
angley-- ;
anglez+=2 ;
glutPostRedisplay() ;
}
void key(unsigned char key,int x,int y) {
if ( keyManipulateur(key,x,y) )
glutPostRedisplay();
else
switch ( key ) {
case 0x0D : obj = 1 - obj;
break; }
}
int main(int argc,char **argv) {
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE);
glutInitWindowSize(300,300);
glutInitWindowPosition(50,50);
glutCreateWindow("Lumières");
myinit();
creationMenuBasique();
setParametresOrthoBasique(-1.5,1.5,-1.5,1.5,-500.0,500.0);
setManipulateurDistance(1.0F);
glutReshapeFunc(reshapeOrthoBasique);
glutKeyboardFunc(key);
glutSpecialFunc(specialBasique);
glutMotionFunc(motionBasique);
glutMouseFunc(sourisBasique);
glutIdleFunc(idle);
glutDisplayFunc(display);
glutMainLoop();
return(0);
}