#ifdef __APPLE__#include <GLUT/glut.h>#else#include <GL/glut.h>#endif#include <stdio.h>#include <stdlib.h>// Inclusion de la bibliotheque contenant les fonctions et structures// utiles pour le TP note.#include "libtpnote.h"// Tableau recevant les point projetes sur l'ecranPointProjete * points = NULL;// Nombre de points projetes sur l'ecranunsigned int nombre_points = 0;// Largeur et hauteur de la fenetreint largeur_fenetre = 500;int hauteur_fenetre = 300;// Affiche-t-on les faces des cubes de differentes couleurs?int colorize_faces = 0;// Angle du cube qui tournefloat angle = 0;void display_pixels() {  int i;  for ( i = 0; i < nombre_points; i++ ) {    glBegin(GL_POINTS);    glVertex2f(points[i].proj_x, points[i].proj_y);    glEnd();  }}void cube() {  if ( colorize_faces)    glColor3f(1., 0., 0.);  // Face du bas  nombre_points = generate_pixels((Point3D){-0.5, -0.5, -0.5, 1},				  (Point3D){ 0.5, -0.5, -0.5, 1},				  (Point3D){ 0.5, -0.5,  0.5, 1},				  &points,				  largeur_fenetre, hauteur_fenetre);  display_pixels();  nombre_points = generate_pixels((Point3D){-0.5, -0.5, -0.5, 1},				  (Point3D){-0.5, -0.5,  0.5, 1},				  (Point3D){ 0.5, -0.5,  0.5, 1},				  &points,				  largeur_fenetre, hauteur_fenetre);  display_pixels();  if ( colorize_faces)    glColor3f(0., 0., 1.);  // Face gauche  nombre_points = generate_pixels((Point3D){-0.5,  0.5,  0.5, 1},				  (Point3D){-0.5, -0.5,  0.5, 1},				  (Point3D){-0.5, -0.5, -0.5, 1},				  &points,				  largeur_fenetre, hauteur_fenetre);  display_pixels();  nombre_points = generate_pixels((Point3D){-0.5,  0.5,  0.5, 1},				  (Point3D){-0.5, -0.5, -0.5, 1},				  (Point3D){-0.5,  0.5, -0.5, 1},				  &points,				  largeur_fenetre, hauteur_fenetre);  display_pixels();  if ( colorize_faces)    glColor3f(1., 1., 0.);  // Face droite  nombre_points = generate_pixels((Point3D){ 0.5,  0.5,  0.5, 1},				  (Point3D){ 0.5, -0.5,  0.5, 1},				  (Point3D){ 0.5, -0.5, -0.5, 1},				  &points,				  largeur_fenetre, hauteur_fenetre);  display_pixels();  nombre_points = generate_pixels((Point3D){ 0.5,  0.5,  0.5, 1},				  (Point3D){ 0.5, -0.5, -0.5, 1},				  (Point3D){ 0.5,  0.5, -0.5, 1},				  &points,				  largeur_fenetre, hauteur_fenetre);  display_pixels();  if ( colorize_faces)    glColor3f(0., 1., 0.);  // Face du haut  nombre_points = generate_pixels((Point3D){-0.5,  0.5, -0.5, 1},				  (Point3D){ 0.5,  0.5, -0.5, 1},				  (Point3D){ 0.5,  0.5,  0.5, 1},				  &points,				  largeur_fenetre, hauteur_fenetre);  display_pixels();  nombre_points = generate_pixels((Point3D){-0.5,  0.5, -0.5, 1},				  (Point3D){-0.5,  0.5,  0.5, 1},				  (Point3D){ 0.5,  0.5,  0.5, 1},				  &points,				  largeur_fenetre, hauteur_fenetre);  display_pixels();  if ( colorize_faces)    glColor3f(0.5, 0.5, 0.5);  // Face avant  nombre_points = generate_pixels((Point3D){-0.5, -0.5,  0.5, 1},				  (Point3D){-0.5,  0.5,  0.5, 1},				  (Point3D){ 0.5,  0.5,  0.5, 1},				  &points,				  largeur_fenetre, hauteur_fenetre);  display_pixels();  nombre_points = generate_pixels((Point3D){-0.5, -0.5,  0.5, 1},				  (Point3D){ 0.5, -0.5,  0.5, 1},				  (Point3D){ 0.5,  0.5,  0.5, 1},				  &points,				  largeur_fenetre, hauteur_fenetre);  display_pixels();  if ( colorize_faces)    glColor3f(0., 1., 1.);  // Face arriere  nombre_points = generate_pixels((Point3D){-0.5, -0.5, -0.5, 1},				  (Point3D){-0.5,  0.5, -0.5, 1},				  (Point3D){ 0.5,  0.5, -0.5, 1},				  &points,				  largeur_fenetre, hauteur_fenetre);  display_pixels();  nombre_points = generate_pixels((Point3D){-0.5, -0.5, -0.5, 1},				  (Point3D){ 0.5, -0.5, -0.5, 1},				  (Point3D){ 0.5,  0.5, -0.5, 1},				  &points,				  largeur_fenetre, hauteur_fenetre);  display_pixels();}void display() {  glClear(GL_COLOR_BUFFER_BIT);  glPointSize(1.0f);  glColor3f(0., 1., 0.);  // Sol  nombre_points = generate_pixels((Point3D){-5, 0, -5, 1},				  (Point3D){ 5, 0, -5, 1},				  (Point3D){ 5, 0,  5, 1},				  &points,				  largeur_fenetre, hauteur_fenetre);  display_pixels();  nombre_points = generate_pixels((Point3D){-5, 0, -5, 1},				  (Point3D){-5, 0,  5, 1},				  (Point3D){ 5, 0,  5, 1},				  &points,				  largeur_fenetre, hauteur_fenetre);  display_pixels();  // Les cubes  libtpnotePushMatrix();  libtpnoteTranslatef(2, 1.5, 4);  libtpnoteRotatef(-angle, 0, 1, 0);  libtpnoteScalef(3, 3, 3);  glColor3f(1, 1, 1);  cube();  libtpnotePopMatrix();  libtpnotePushMatrix();  libtpnoteTranslatef(2, 1, -2);  libtpnoteScalef(2, 2, 2);  libtpnoteRotatef(angle, 0, 1, 0);  glColor3f(1, 1, 0);  cube();  libtpnotePopMatrix();  libtpnotePushMatrix();  libtpnoteTranslatef(0, 0.5, 0);  glColor3f(1, 0, 0);  cube();  libtpnotePopMatrix();  glutSwapBuffers(); }void reshape(int w, int h) {  glViewport(0, 0, w, h);  glMatrixMode(GL_PROJECTION);  glLoadIdentity();  gluOrtho2D(0.0, w, 0.0, h);  largeur_fenetre = w;  hauteur_fenetre = h;  libtpnotePerspective(60, (double)largeur_fenetre/hauteur_fenetre, 0.1, 1000);	}void keyboard(unsigned char key, int x, int y) {  switch(key) {  case 27:  case 'q':    exit(0);    break;  case 'c':    colorize_faces = 1 - colorize_faces;    break;  default:    break;  } // switch(key)	  glutPostRedisplay();}void mouse(int button, int state, int x, int y) {  static float ny=0;  if ( state == GLUT_DOWN ) {    if ( button == GLUT_LEFT_BUTTON )      ny++;    else if ( button == GLUT_RIGHT_BUTTON )      ny--;    if ( ny > 600 )      ny = 600;    else if ( ny < -600 )      ny = -600;    libtpnoteLookAt(ny, 4, -5, 0, 0, 0, 0, 1, 0);    glutPostRedisplay();  }}void idle() {  angle++;  glutPostRedisplay();}int main(int argc, char** argv) {  glutInit(&argc, argv);  glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);  glutInitWindowSize(largeur_fenetre, hauteur_fenetre);  glutCreateWindow("TP note - Test de la bibliotheque");  glutDisplayFunc(display);  glutReshapeFunc(reshape);  glutKeyboardFunc(keyboard);  glutIdleFunc(idle);  glutMouseFunc(mouse);  libtpnotePerspective(60, (double)largeur_fenetre/hauteur_fenetre, 0.1, 1000);	  libtpnoteLookAt(0, 4, -5, 0, 0, 0, 0, 1, 0);  glClearColor(0.0f, 0.0f, 0.5f, 1.0f);  glutMainLoop();  return 0;}