#include <cassert>
#include <iostream>
#include <vector>

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

using namespace std;

#include <zpr.h>

#include <graphmisc.h>

#include <gobj.h>
//#include <displaypoints.h>

#include <print.h>


#include <test06.h>


typedef point3<double> pt3;


test06::test06
(
  int & argc, 
  char** & argv,
  uintc mode,
  uintc x,
  uintc y,
  string const & title
)
  : myglutgui(argc,argv,mode,x,y,title)
{
  switchContainer = new gobjSwitchContainer();

  globalSet();
}

void test06::display()
{
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  xGraphics.draw();

//cout << "drawing" << endl;
//cout << SHOW(xGraphics.v.size()) << endl;

  glerrordisplay();
  glutSwapBuffers();
}

void test06::f1()
{
  cout << endl;
  cout << "Keyboard Commands" << endl;
  cout << "s  - toggles the sphere" << endl;
  cout << "c  - toggles the cube" << endl;
  cout << "w  - toggles the cone" << endl; 
  cout << "u  - toggle the icosahedron" << endl;
  cout << "f  - sets full screen mode" << endl;

  xGraphics.push_back( new gobjglColor3f(1.0,0.0,0.0) );
  gobjQuadric * q = new gobjQuadric();
  q->radius=0.5;
  q->slices=20;
  q->loops=6;
  gobjMySphereDraw * s = new gobjMySphereDraw(0.0,0.0,0.0,q);

  switchContainer->push_back(q,false);
  switchContainer->push_back(s,true);


  gobjglutSolidCube * cub = new gobjglutSolidCube((GLdouble)0.5);
  switchContainer->push_back(cub,true);

  gobjglutSolidCone * con = 
    new gobjglutSolidCone(.2,.3,10,10);
  switchContainer->push_back(con,true);

  gobjContainer * d1 = new gobjContainer();
  d1->push_back( new gobjglColor3f(1.0,1.0,0.0) );
  d1->push_back( new gobjglPushMatrix() );
  d1->push_back( new gobjglTranslatef(0.5,0.0,0.0) );
  d1->push_back( new gobjglutSolidIcosahedron() );
  d1->push_back( new gobjglPopMatrix() );
  switchContainer->push_back(d1,true);

  xGraphics.push_back(switchContainer);

}

void test06::keyboard(unsigned char key, int x, int y)
{
  switch (key)
  {
    case 27:
      exit(0);
      break;

    case 's':
      switchContainer->v[1]->toggle();
      break;

    case 'c':
      switchContainer->v[2]->toggle();
      break;

    case 'w':
      switchContainer->v[3]->toggle();
      break;

    case 'u':
      switchContainer->v[4]->toggle();
      break;
    

    case 'f':
      glutFullScreen();
      break;
   
 
    
  }

  glutPostRedisplay();
}






void test06::eval()
{
  OpenGLinitialisation();
  
  glEnable(GL_DEPTH_TEST);
  glEnable(GL_CULL_FACE);

  //zpr::init();

  xGraphics.set();

  f1();

  glutPostRedisplay();

}


