
Le source : Simple2007-2008.cpp
/* Auteur: Nicolas JANEY                        */
/* nicolas.janey@univ-fcomte.fr                 */
/* Septembre 2007                               */
/* Un programme OpenGL fonctionnel tout simple  */
#include <GL/glut.h>
#include <GL/gl.h>
#include <GL/glu.h>
/* Scene dessinee                               */
void scene(void) {
  glPushMatrix() ;
  glBegin(GL_POLYGON) ;
  glVertex2f(-0.5F,-0.5F) ;
  glVertex2f(-0.5F,0.5F) ;
  glVertex2f(0.5F,0.5F) ;
  glVertex2f(0.5F,-0.5F) ;
  glEnd() ;
  glPopMatrix() ;
}
/* Fonction executee lors d'un rafraichissement */
/* de la fenetre de dessin                      */
void display(void) {
  glClear(GL_COLOR_BUFFER_BIT) ;
  glPushMatrix() ;
  scene();
  glPopMatrix() ;
  glFlush();
}
/* Fonction executee lors d'un changement       */
/* de la taille de la fenetre OpenGL            */
void reshape(int tx,int ty) {
  glViewport(0,0,tx,ty); 
  glMatrixMode(GL_PROJECTION) ;
  glLoadIdentity() ;
  glOrtho(-1.0,1.0,(double) -ty/tx,(double) ty/tx,-1.0,1.0) ;
  glMatrixMode(GL_MODELVIEW) ;
  glLoadIdentity() ;
}
/* Fonction principale                          */
int main(int argc,char **argv) {
  glutInit(&argc,argv);
  glutInitDisplayMode(GLUT_RGBA|GLUT_SINGLE);
  glutInitWindowSize(200,200); 
  glutInitWindowPosition(50,50); 
  glutCreateWindow("Simple"); 
  glutReshapeFunc(reshape);
  glutDisplayFunc(display);
  glutMainLoop();
  return(0);
}