/**************************************************
 *   File:     ManyInstances.cpp
 *   Author:   Dr. Dalton R. Hunkins     
 *   Date:     September 2007
**************************************************/

#include 
#include 
#include 

float yellow[] = {1.0, 1.0, 0.0};
float cyan[]   = {0.0, 1.0, 1.0};
float darkCyan[] = {0.0, 0.6, 0.6};


void init() {   
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
   gluOrtho2D(0.0, 1.0, 0.0, 1.0);
   
   glClearColor(0.0, 0.0, 0.0, 1.0);
}
   

void diamond(float color[3]) {
	glColor3fv(color);
    glBegin(GL_POLYGON);
      glVertex2d(-1.0,  0.0);
      glVertex2d( 0.0,  1.0);
      glVertex2d( 1.0,  0.0);
      glVertex2d( 0.0, -1.0);
    glEnd();
}


void disk(float color[3]) {
    glColor3fv(color);
    gluDisk(gluNewQuadric(), 0.0, 1.0, 72, 1);
}


void display() {
    glClear(GL_COLOR_BUFFER_BIT);
    glMatrixMode(GL_MODELVIEW);

//First Instance of Diamond
    glPushMatrix();
    glTranslated(0.2, 0.8, 0.0);
    glScaled(0.1, 0.1, 1.0);
    diamond(cyan);
    glPopMatrix();

    glPushMatrix();
    glTranslated(0.8, 0.2, 0.0);
    glScaled(0.1, 0.1, 1.0);
    diamond(cyan);
    glPopMatrix();

//First Instance of Disk    
    glPushMatrix();
    glTranslated(0.5, 0.5, 0.0);
    glScaled(0.1, 0.1, 1.0);
    disk(yellow);
    glPopMatrix();
    
    glPushMatrix();
    glTranslated(0.8, 0.8, 0.0);
    glScaled(0.1, 0.1, 1.0);
    disk(yellow);
    glPopMatrix();

    glPushMatrix();
    glTranslated(0.8, 0.8, 0.0);
    glRotated(45.0, 0.0, 0.0, 1.0);
    glScaled(0.05, 0.05, 1.0);
    diamond(darkCyan);
    glPopMatrix();
    
//Instance of Diamond and Disk
    glPushMatrix();
    glTranslated(0.2, 0.2, 0.0);
       glPushMatrix();
       glScaled(0.1, 0.1, 1.0);
       disk(darkCyan);
       glPopMatrix();
    
       glPushMatrix();
       glRotated(45.0, 0.0, 0.0, 1.0);
       glScaled(0.05, 0.05, 1.0);
       diamond(yellow);
       glPopMatrix();
    glPopMatrix();

    glFlush();
}

 int main(int argc, char **argv) {
    glutInit(&argc, argv);
    glutInitWindowPosition(0, 0);
    glutInitWindowSize(500, 500);
    glutCreateWindow("Many Instances");

    glutDisplayFunc(display);
    
    init();
   
    glutMainLoop(); 
    return 0;
}