#include <stdio.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 GLint fogMode;
static float z = 2.0F;
static float dz = 0.1F;
static int fog = 1;
void myinit(void) {
GLfloat position[] = { 0.0,3.0,3.0,0.0 };
GLfloat local_view[] = { 0.0 };
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glLightfv(GL_LIGHT0,GL_POSITION,position);
glLightModelfv(GL_LIGHT_MODEL_LOCAL_VIEWER,local_view);
glFrontFace(GL_CW);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_AUTO_NORMAL);
glEnable(GL_NORMALIZE);
fogMode = GL_EXP;
glFogi(GL_FOG_MODE,fogMode);
glFogfv(GL_FOG_COLOR,couleurGrisMoyen());
glFogf(GL_FOG_DENSITY,0.3F);
glHint(GL_FOG_HINT,GL_DONT_CARE);
glClearColor(0.5,0.5,0.5,1.0);
}
void renderTeapot(GLfloat x,GLfloat y,GLfloat z) {
glPushMatrix();
glTranslatef(x,y,z);
manipulateurSouris();
manipulateurClavier();
glMaterialfv(GL_FRONT,GL_AMBIENT,newCouleur(0.2F,0.0F,0.0F,1.0F));
glMaterialfv(GL_FRONT,GL_DIFFUSE,newCouleur(0.6F,0.5F,0.0F,1.0F));
glMaterialfv(GL_FRONT,GL_SPECULAR,newCouleur(0.7F,0.6F,0.1F,1.0F));
glMaterialf(GL_FRONT,GL_SHININESS,0.6F*128.0F);
glColor4fv(couleurBlanc());
glutSolidTeapot(1.0);
glPopMatrix();
}
void idle(void) {
z += dz;
if ( z > 6.5F )
dz *= -1.0F;
if ( z < -10.0F )
dz *= -1.0F;
glutPostRedisplay();
}
void display(void) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
if ( fog )
glEnable(GL_FOG);
else
glDisable(GL_FOG);
glPushMatrix();
glTranslatef(0.0F,0.0F,-5.0F);
renderTeapot(0.0,0.0,z);
glPopMatrix();
glFlush();
glutSwapBuffers() ;
}
void key(unsigned char key,int x,int y) {
if ( keyManipulateur(key,x,y) )
glutPostRedisplay();
else
switch ( key ) {
case ' ' : fog = 1 - fog;
glutPostRedisplay();
break;
case 0x0D : if ( fogMode == GL_EXP ) {
fogMode = GL_EXP2;
printf("Fog mode is GL_EXP2\n"); }
else
if ( fogMode == GL_EXP2 ) {
fogMode = GL_LINEAR;
printf("Fog mode is GL_LINEAR\n");
glFogf(GL_FOG_START,1.0);
glFogf(GL_FOG_END,5.0); }
else
if ( fogMode == GL_LINEAR ) {
fogMode = GL_EXP;
printf("Fog mode is GL_EXP\n"); }
glFogi(GL_FOG_MODE,fogMode);
glutPostRedisplay();
break; }
}
void souris(int bouton,int etat,int x,int y) {
if ( sourisManipulateur(bouton,etat,x,y) )
glutPostRedisplay();
else
if ( ( bouton == GLUT_LEFT_BUTTON ) && ( etat == GLUT_UP ) ) {
if(fogMode == GL_EXP) {
fogMode = GL_EXP2;
printf("Fog mode is GL_EXP2\n"); }
else
if(fogMode == GL_EXP2) {
fogMode = GL_LINEAR;
printf("Fog mode is GL_LINEAR\n");
glFogf(GL_FOG_START,1.0);
glFogf(GL_FOG_END,5.0); }
else
if(fogMode == GL_LINEAR) {
fogMode = GL_EXP;
printf("Fog mode is GL_EXP\n"); }
glFogi(GL_FOG_MODE,fogMode);
glutPostRedisplay(); }
}
int main(int argc,char **argv) {
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE);
glutInitWindowSize(350,250);
glutInitWindowPosition(50,50);
glutCreateWindow("Brouillard");
myinit();
creationMenuBasique();
setParametresPerspectiveBasique(43.0F,1.5F,1.0F,30.0F,0.0F,0.0F,-3.6F);
setManipulateurDistance(5.0F);
glutReshapeFunc(reshapePerspectiveBasique);
glutKeyboardFunc(key);
glutSpecialFunc(specialBasique);
glutMotionFunc(motionBasique);
glutMouseFunc(souris);
glutIdleFunc(idle);
glutDisplayFunc(display);
glutMainLoop();
return(0);}