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

void init(void) {
   glClearColor (0.0, 0.0, 0.0, 0.0);         /* Hintergrundfarbe schwarz          */
   glShadeModel (GL_SMOOTH);                  /* smooth shading                    */
}

void reshape (int w, int h) {
   GLfloat p = (GLfloat) w / (GLfloat) h;     /* berechne Fensterverhaeltnis       */
   glViewport (0,0,(GLsizei)w,(GLsizei)h);    /* lege Viewport fest                */
   glMatrixMode (GL_PROJECTION);              /* ab jetzt: Projektionsmatrix       */
   glLoadIdentity ();                         /* lade Einheitsmatrix               */
   if (p > 1.0)                               /* falls breiter als hoch            */
        gluOrtho2D (0.0,p*30.0,0.0,30.0  );   /* left,right,bottom,top             */
   else gluOrtho2D (0.0,  30.0,0.0,30.0/p);   /* left,right,bottom,top             */
   glMatrixMode(GL_MODELVIEW);                /* ab jetzt: Modelview-Matrix        */
   glLoadIdentity ();                         /* lade Einheitsmatrix               */
}

void display(void) {
   glClear (GL_COLOR_BUFFER_BIT);             /* reset Farbpuffer                  */
   glBegin (GL_TRIANGLES);                    /* Beginn der Dreiecks-Knoten        */
   glColor3f  ( 1.0,  0.0, 0.0);              /* Farbe rot                         */ 
   glVertex2f (25.0,  5.0);                   /* Knoten unten rechts               */
   glColor3f  ( 0.0,  1.0, 0.0);              /* Farbe gruen                       */ 
   glVertex2f ( 5.0, 25.0);                   /* Knoten links oben                 */ 
   glColor3f  ( 0.0,  0.0, 1.0);              /* Farbe blau                        */ 
   glVertex2f ( 5.0,  5.0);                   /* Knoten unten links                */
   glEnd();                                   /* Ende der Dreiecks-Knoten          */
   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("smooth");                 /* 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          */
}