#include <GL/glut.h>                          /* Header f. OpenGl utility toolkit  */
#include <stdlib.h>                           /* Header fuer C-Library             */

void init(void) {                             /* Initialisierung                   */
  glClearColor(0.0, 0.0, 1.0, 0.0);           /* setze Blau als Hintergrundfarbe   */
}

void reshape(int w, int h) {
  GLfloat p = (GLfloat) w / (GLfloat) h;      /* Proportionalitaetsfaktor          */
  glViewport(0, 0, (GLsizei)w, (GLsizei)h);   /* setze Viewport                    */
  glMatrixMode(GL_PROJECTION);                /* betrifft Projektionsmatrix        */
  glLoadIdentity();                           /* lade Einheitsmatrix               */
  if (p > 1.0)                                /* falls breiter als hoch            */
       glFrustum(  -p,  p,-1.0,1.0,1.5,20.0); /* left,right,bottom,top,near,far    */
  else glFrustum(-1.0,1.0,-1/p,1/p,1.5,20.0); /* left,right,bottom,top,near,far    */
}

void display(void){                           /* Prozedur zum Zeichnen             */
  glClear(GL_COLOR_BUFFER_BIT);               /* alle Pixel zurecksetzen           */
  glMatrixMode(GL_MODELVIEW);                 /* ab jetzt:  Modellierungsmatrix    */
  glColor3f(1.0, 1.0, 0.0);                   /* Farbe gelb                        */
  glLoadIdentity();                           /* Einheitsmatrix                    */
  gluLookAt(0.0, 0.0, 5.0,                    /* Kamera-Standpunkt                 */
            0.0, 0.0, 0.0,                    /* Kamera-Fokussierpunkt             */
            0.0, 1.0, 0.0);                   /* Up-Vektor                         */
  glScalef(1.0, 1.5, 1.0);                    /* Skalierung in 3 Dimensionen       */
  glRotatef(30.0, 0.0, 1.0, 0.0);             /* rotiere 30 Grad um y-Achse        */
  glutWireCube(2.0);                          /* Drahtgitterwuerfel                */
  glFlush();                                  /* direkt ausgeben                   */
}

int main (int argc, char ** argv) {           /* Hauptprogramm                     */
  glutInit(&argc, argv);                      /* initialisiere GLUT                */
  glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);  /* single buffer, true color         */
  glutInitWindowSize(800, 600);               /* initiale Fenstergroesse           */
  glutInitWindowPosition(0,0);                /* initiale Fensterposition          */
  glutCreateWindow("wire-cube-prop");         /* Fenster mit Aufschrift            */
  init();                                     /* rufe init auf                     */
  glutDisplayFunc(display);                   /* registriere display               */
  glutReshapeFunc(reshape);                   /* registriere reshape               */
  glutMainLoop();                             /* beginne Event-Schleife            */
  return 0;                                   /* ISO C verlangt Rueckgabe          */
}