
Le source: SphereSpeculaire.cpp
#include <windows.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glaux.h>
static float anglex = 0.0F ;
static float angley = 0.0F ;
static GLfloat shininess = 100.0F ;
void myinit(void) {
GLfloat gris[] = { 0.4F,0.4F,0.4F,1.0F };
GLfloat specular[] = { 1.0F,1.0F,1.0F,1.0F };
GLfloat bleu[] = { 0.0F,0.0F,1.0F,1.0F };
GLfloat vert[] = { 0.0F,1.0F,0.0F,1.0F };
GLfloat l_pos0[] = { 1.0F,1.0F,1.0F,0.0F };
GLfloat l_pos1[] = { -1.0F,0.0F,1.0F,0.0F };
glClearColor(0.5F,0.5F,1.0F,1.0F) ;
glMaterialfv(GL_FRONT,GL_SPECULAR,specular);
glLightfv(GL_LIGHT0,GL_DIFFUSE,gris);
glLightfv(GL_LIGHT0,GL_POSITION,l_pos0);
glLightfv(GL_LIGHT0,GL_SPECULAR,bleu);
glLightfv(GL_LIGHT1,GL_DIFFUSE,gris);
glLightfv(GL_LIGHT1,GL_POSITION,l_pos1);
glLightfv(GL_LIGHT1,GL_SPECULAR,vert);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHT1);
glDepthFunc(GL_LESS);
glEnable(GL_DEPTH_TEST);
}
void CALLBACK display(void) {
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotatef(angley,0.0F,1.0F,0.0F) ;
glRotatef(anglex,1.0F,0.0F,0.0F) ;
glMaterialf(GL_FRONT,GL_SHININESS,shininess);
auxSolidSphere(1.0);
glPopMatrix();
glFlush();
auxSwapBuffers();
}
void CALLBACK myReshape(int w,int h) {
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (w <= h)
glOrtho(-1.5,1.5,-1.5*(float)h/(float)w,1.5*(float)h/(float)w,-10.,10.);
else
glOrtho(-1.5*(float)w/(float)h,1.5*(float)w/(float)h,-1.5,1.5,-10.,10.);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void CALLBACK up(void) {
anglex-- ;
}
void CALLBACK down(void) {
anglex++ ;
}
void CALLBACK left(void) {
angley-- ;
}
void CALLBACK right(void) {
angley++ ;
}
void CALLBACK keys(void) {
shininess *= 1.03F ;
}
void CALLBACK keyS(void) {
shininess /= 1.03F ;
}
void main(void) {
auxInitDisplayMode(AUX_DOUBLE|AUX_RGB|AUX_DEPTH);
auxInitPosition(0,0,250,250);
auxInitWindow("2 Lumières avec réflexion spéculaire");
myinit();
auxKeyFunc(AUX_UP,up) ;
auxKeyFunc(AUX_DOWN,down) ;
auxKeyFunc(AUX_LEFT,left) ;
auxKeyFunc(AUX_RIGHT,right) ;
auxKeyFunc(AUX_s,keys) ;
auxKeyFunc(AUX_S,keyS) ;
auxReshapeFunc(myReshape);
auxMainLoop(display);
}
RETOUR