/* Auteur: Nicolas JANEY */
/* nicolas.janey@univ-fcomte.fr */
/* Mars 2003 */
/* Le blending */
#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"
#include "ModuleFont.h"
static float angle = 0.0F ;
static float da = 1.0F;
static float alpha = 0.5F ;
static int f1;
static int f2;
static int obj = 0;
static int cull = 1;
void myinit(void) {
glClearColor(0.5F,0.5F,0.5F,1.0F);
GLfloat light_position0[] = { 1.0F,1.0F,1.0F,0.0F };
glLightfv(GL_LIGHT0,GL_AMBIENT,couleurNoir());
glLightfv(GL_LIGHT0,GL_DIFFUSE,couleurBlanc());
glLightfv(GL_LIGHT0,GL_SPECULAR,couleurBlanc());
glLightfv(GL_LIGHT0,GL_POSITION,light_position0);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_AUTO_NORMAL);
glEnable(GL_NORMALIZE);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_CULL_FACE);
}
void objet(void) {
glRotatef(angle*1.1F,0.0F,1.0F,0.0F);
switch(obj) {
case 0 : glFrontFace(GL_CCW);
glutSolidSphere(4.5,60,60);
break;
case 1 : glFrontFace(GL_CCW);
glutSolidTorus(2.3,3.0,60,120);
break;
case 2 : glFrontFace(GL_CW);
glutSolidTeapot(4.5);
break; }
}
void display(void) {
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
if ( cull )
glEnable(GL_CULL_FACE);
else
glDisable(GL_CULL_FACE);
glPushMatrix();
manipulateurSouris();
manipulateurClavier();
glRotatef(angle,0.0F,1.0F,0.0F);
glPushMatrix();
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,couleurRouge(1.0)) ;
glTranslatef(4.0F,0.0F,0.0F);
objet();
glPopMatrix();
glPushMatrix();
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,couleurVert(alpha)) ;
glTranslatef(-5.0F,0.0F,0.0F);
objet();
glPopMatrix();
glPopMatrix();
glFlush();
glutSwapBuffers() ;
}
void postRedisplay(void) {
glutPostWindowRedisplay(f1);
glutPostWindowRedisplay(f2);
}
void idle(void) {
angle += da;
postRedisplay();
}
void key(unsigned char key,int x,int y) {
static int anim = 1;
if ( keyManipulateur(key,x,y) )
glutPostRedisplay();
else
switch ( key ) {
case 'a' : da *= 1.1F;
break;
case 'A' : da /= 1.1F;
break;
case 'c' : cull = !cull;
postRedisplay();
break;
case 0x0D : obj =(obj+1) % 3;
postRedisplay();
break;
case ' ' : anim = !anim;
glutIdleFunc((anim) ? idle : NULL);
break;
case 45 : alpha -= 0.05F;
if ( alpha < 0.0F )
alpha = 0.0F;
postRedisplay();
break;
case 43 : alpha += 0.05F;
if ( alpha > 1.0F )
alpha = 1.0F;
postRedisplay();
break; }
}
void reshape2(int w,int h) {
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0,w,-h,0,-1.0,1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void display2() {
glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
glPushMatrix();
float pos = 1.0F;
glColor4fv(couleurBlanc());
placeFontCursor(5.0F,-pos*20.0F,0.0F) ;
simpleBitmapOutput(1,REGULAR8x13,"alpha : %6.3f",alpha) ;
pos += 1.0F;
glPopMatrix();
glutSwapBuffers();
}
int main(int argc,char **argv) {
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE);
glutInitWindowSize(360,200);
glutInitWindowPosition(50,50);
f1 = glutCreateWindow("Le blending");
myinit();
creationMenuBasique();
setParametresOrthoBasique(-6.0,6.0,-6.0,6.0,-50.0,50.0);
setManipulateurDistance(1.0F);
glutReshapeFunc(reshapeOrthoBasique);
glutIdleFunc(idle);
glutKeyboardFunc(key);
glutSpecialFunc(specialBasique);
glutMotionFunc(motionBasique);
glutMouseFunc(sourisBasique);
glutDisplayFunc(display);
glutInitWindowSize(150,30);
glutInitWindowPosition(60,340);
glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE);
f2 = glutCreateWindow("Valeurs");
creationMenuBasique();
glutDisplayFunc(display2);
glutReshapeFunc(reshape2);
glutKeyboardFunc(key);
glutSpecialFunc(specialBasique);
glutMainLoop();
return(0);
}