Exemple 4: afficher une théière animée
Ce programme affiche une théière tournoyante. Une lumière directionnelle perpendiculaire au plan de l’oeil est activée, pour donner un rendu plus réaliste.
Fichier : examples/prog4.cpp /*
Animation d'une théière, éclairée par une lampe. La lampe est gérée
par une classe fournie, la théière est générée grâce à un seul appel
de la fonction gluSolidTeaPot() (qui se charge d'envoyer les bonnes
coordonnées d'évaluateurs à OpenGl).
*/
#include "glut_import.h"
#include "application.h"
#include "light.h"
class DemoWindow:public Window{
Light light;
public:
DemoWindow():
Window("Fenêtre de démonstration",windowStyle(GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE,WC_KEYBOARD | WC_IDLE)){};
void onIdle(){
redisplay();
};
void onDisplay(){
float t=glutGet(GLUT_ELAPSED_TIME)*0.1;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(50,(float) getWidth()/getHeight(),0.1,10);
gluLookAt(0,0,4,0,0,0,0,1,0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glRotatef(0.8*t,1,0,0);
glRotatef(1.2*t,0,1,0);
glRotatef(1.5*t,0,0,1);
glutSolidTeapot(1);
glFlush();
glutSwapBuffers();
};
void onCreate(){
printf("Appuyer sur [ESCAPE] pour quitter\n");
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
light.on();
};
};
int main(){
DemoWindow w;
Application::run();
} Ce document a été traduit de LaTeX par HeVeA |