/*
    transform1.c

    - Zeigt Transformationen: glTranslatef(), glRotatef(), glScalef().
      und die Funktion des Matrixstacks: glPushMatrix(), glPopMatrix().

    > Übung: Vier Pfeile in den Ecken des Fensters zeichnen,
      die jeweils nach außen (auf die Ecke hin) zeigen.
*/




# include       <stdio.h>
# include       <stdlib.h>
# include       <math.h>
# include       <GL/glut.h>



static GLuint   objekt_liste;



static void     erzeuge_objekt_liste (void)
/*****************************************/
{
    objekt_liste = glGenLists (1);
    glNewList (objekt_liste, GL_COMPILE);
        glBegin (GL_TRIANGLE_STRIP);
            glVertex2f (-0.2, -0.3);
            glVertex2f ( 0.0, -0.1);
            glVertex2f ( 0.0,  0.3);
            glVertex2f ( 0.2, -0.3);
        glEnd ();
    glEndList ();
}



static void     display_func (void)
/*********************************/
{
    static GLfloat
                weissgrau[3]    = { 0.85, 0.85, 0.85 },
                hellgrau[3]     = { 0.65, 0.65, 0.65 },
                mittelgrau[3]   = { 0.45, 0.45, 0.45 },
                dunkelgrau[3]   = { 0.25, 0.25, 0.25 },
                schwarz[3]      = { 0.00, 0.00, 0.00 };

    /* printf ("display_func()\n"); */

    glClearColor (1, 1, 1, 0);
    glClear (GL_COLOR_BUFFER_BIT);

    /* Original */
    glLoadIdentity ();
    glColor3fv (weissgrau);
    glCallList (objekt_liste);

    glPushMatrix ();

    /* Verschoben nach rechts */
    glTranslatef (0.5, 0, 0);
    glColor3fv (hellgrau);
    glCallList (objekt_liste);

    /* Gedreht */
    glRotatef (45, 0, 0, 1);
    glColor3fv (mittelgrau);
    glCallList (objekt_liste);

    /* Verkleinert */
    glScalef (0.5, 0.5, 1);
    glColor3fv (dunkelgrau);
    glCallList (objekt_liste);

    glPopMatrix ();

    /* Verschoben nach links */
    glTranslatef (-0.5, 0, 0);
    glColor3fv (schwarz);
    glCallList (objekt_liste);

    glFlush ();
    glutReportErrors ();
}



static void     keyboard_func (unsigned char key, int x, int y)
/*************************************************************/
{
    exit (0);
}



extern int      main (int argc, char **argv)
/******************************************/
{
    glutInit (&argc, argv);
    glutInitDisplayMode (GLUT_RGB);

    glutInitWindowPosition (200, 100);
    glutInitWindowSize (600, 600);
    glutCreateWindow ("list1");

    glutDisplayFunc (display_func);
    glutKeyboardFunc (keyboard_func);

    erzeuge_objekt_liste ();

    glutMainLoop ();

    return 0;
}


