#include <cassert>
#include <iostream>
#include <vector>
using namespace std;

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


#include <pointsdisplay.h>
#include <gobj.h>
#include <graphmisc.h>
#include <test05.h>
#include <typedefs.h>
#include <zpr.h>


typedef point3<double> pt3;


test05::test05
(
  int & argc, 
  char** & argv,
  uintc mode,
  uintc x,
  uintc y,
  string const & title
)
  : myglutgui(argc,argv,mode,x,y,title), xGraphics(true)
{
  globalSet();
}

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

  xGraphics.draw();

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

  glerrordisplay();
  glutSwapBuffers();
}

void test05::f1()
{
  xGraphics.push( new gobjglDisable(GL_LIGHTING) );

  
  vector< pt3 > v;
  v.push_back( pt3(0.2, 0.3, 0.5) );
  v.push_back( pt3(-0.5, 0.0, 0.2) );
  v.push_back( pt3(0.2, 0.7, 0.9) );
  v.push_back( pt3(0.0, -0.3, -0.5) );

  xGraphics.push( new gobjglColor3f(1.0,0.0,0.0) );

  pointsdisplay3D<pt3> dp(xGraphics,v);
}

void test05::f2()
{
  xGraphics.push( new gobjglDisable(GL_LIGHTING) );

  xGraphics.push( new gobjMyBitmapCharacter
    ( string("hello"), pt3(.2, .3, .5) ) );
  xGraphics.push( new gobjMyBitmapCharacter
    ( string("a"), pt3(.1, .5, .8) ) );
  xGraphics.push( new gobjMyBitmapCharacter
    ( string("b"), pt3(.2, .3, .2) ) );
  xGraphics.push( new gobjMyBitmapCharacter
    ( string("c"), pt3(-0.2, .9, .0) ) );

}

void test05::testCircles()
{
  cout << "Testing Circles" << endl;
  cout << "Test the simple default circle generation." << endl;
  gobjMyCircle * c=new gobjMyCircle();
  xGraphics.push( new gobjMyCircleDraw(point3<double>(0.0,0.0,0.0),*c) );

  cout << "Test arc generation." << endl;
  gobjMyCircle * c2=new gobjMyCircle(PI/2.0,1.5*PI);
  xGraphics.push( new gobjglColor3f(0.0,1.0,0.0) );
  xGraphics.push( new gobjMyCircleDraw(point3<double>(1.0,0.0,0.0),*c2) );
}

void test05::testMyArrow()
{
  cout << "Testing gobjMyArrow" << endl;

  point3<double> p0(0.0,0.0,0.0);
  point3<double> p1(3.0,0.0,0.0);
  double delta=0.2;
  
  gobjMyArrow* arr = 
    new gobjMyArrow(p0,p1,0.2,0.2,delta);

  xGraphics.push( new gobjglColor3f(0.0,1.0,0.0) );

  xGraphics.push(arr);
}

void test05::eval()
{
/*
  glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
  glutInitWindowSize(800,600);
  glutCreateWindow("");

  glutDisplayFunc(myglutguidisplay);
  glutKeyboardFunc(myglutguikeyboard);
*/

  OpenGLinitialisation();
  
  glEnable(GL_DEPTH_TEST);
  glEnable(GL_CULL_FACE);


  
  xGraphics.set();

  f1();
  f2();
  testCircles();
  testMyArrow();

  glutPostRedisplay();

}



