Un carré blanc au milieu d'une fenêtre noire.
En cas de modification du ratio largeur/hauteur
de la fenêtre, le carré reste un carré.

L'exécutable: GLUTReshape.exe

Image022.gif (2558 octets)  Image022.gif (2558 octets)

Image022.gif (2558 octets)

Le source: GLUTReshape.cpp

#include <windows.h>

#include <GL/gl.h>
#include <GL/glut.h>

void reshape(int w,int l) {
  glViewport(0,0,w,l);
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  if ( w > l )
    glOrtho((float) -w/l,(float) w/l,
            -1.0,1.0,
            -1.0,1.0);
    else
    glOrtho(-1.0,1.0,
            (float) -l/w,(float) l/w,
            -1.0,1.0);
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
}

void display(void) {
  glClearColor(0.0F,0.0F,0.0F,0.0F) ;
  glClear(GL_COLOR_BUFFER_BIT) ;
  glColor3f(1.0F,1.0F,1.0F) ;
  glBegin(GL_POLYGON) ;
  glVertex2f(-0.5F,-0.5F) ;
  glVertex2f(-0.5F,0.5F) ;
  glVertex2f(0.5F,0.5F) ;
  glVertex2f(0.5F,-0.5F) ;
  glEnd() ;
  glFlush() ;
}

void main(int argc,char **argv) {
  glutInit(&argc,argv);
  glutInitWindowSize(200,200);
  glutInitWindowPosition(100,100);
  glutInitDisplayMode(GLUT_RGBA|GLUT_SINGLE);
  glutCreateWindow("Carre blanc homothetique") ;
  glutReshapeFunc(reshape) ;
  glutDisplayFunc(display) ;
  glutMainLoop() ;
}
WB01624_.gif (281 octets) RETOUR