/*
 * initial.c
 * draw and spin my initials, woohoo!
 * Bill Thibault 1/13/98
 */


#include <glut.h>
#include <stdio.h>
//#include <stdlib.h>
#include <math.h>
#include <string.h>

void menu ( int );

int use_polys = 0;

void init(void) 
{
   glClearColor (0.0, 0.0, 0.0, 0.0);

   glutCreateMenu ( menu );
   glutAddMenuEntry ( "toggle animation", 1 );
   glutAttachMenu ( GLUT_RIGHT_BUTTON );
}

void initials ( int frame, int use_polys )
{
  static GLfloat points[8][3] = {
    {-4,2,0},
    {-2.5,-2,0},
    {-2,0,0},
    {-1.5,-2,0},
    {0,2,0},
    {2,-2,0},
    {4,2,0},
    {2,2,0}
  };

  glPushMatrix();
  glRotatef ( (GLfloat)frame * 3.0, 0, 0, 1 );
  glRotatef ( (GLfloat)frame, 1, 0, 0 );
  glRotatef ( (GLfloat)frame * 2.0, 0, 1, 0 );

  if ( use_polys ) {
  } else {
	 /* W */
	 glColor3f ( 1.0, 0, 0 );
	glBegin ( GL_LINE_STRIP );
	 glVertex3fv ( points[0] );
	 glVertex3fv ( points[1] );
	 glVertex3fv ( points[2] );
	 glVertex3fv ( points[3] );
	 glVertex3fv ( points[4] );
	glEnd();

   /* T */
   glColor3f ( 0, 0, 1.00 );
   glBegin ( GL_LINES );
    glVertex3fv ( points[4] );
    glVertex3fv ( points[6] );
    glVertex3fv ( points[5] );
    glVertex3fv ( points[7] );
   glEnd ();
  }

  glPopMatrix();

}

 char name[512];


 void menu ( int value ) {
	 printf ("menu: got %d\n", value );
 }

void display(void)
{
  static long frame = 0;
  unsigned int c;
  int width;

   glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

   /*
    * Draw the initials
    */

   initials (frame++,false);

   glPushMatrix();
     strcpy ( name, "William Thibault" );
#if 0
     glScalef ( 0.005, 0.005, 0.005 );
     for ( c = 0; c < strlen(name); c++ )
	     glutStrokeCharacter ( GLUT_STROKE_ROMAN, name[c] );
#else
	 glColor3f ( 0,1,0 );
    glRasterPos2i ( 0,0 );	 
     for ( c = 0; c < strlen(name); c++ )
	     glutBitmapCharacter ( GLUT_BITMAP_HELVETICA_12, name[c] );
#endif

   glPopMatrix();

   glutSwapBuffers();

}

void reshape (int w, int h)
{
   glViewport (0, 0, (GLsizei) w, (GLsizei) h); 
   glMatrixMode (GL_PROJECTION);
   glLoadIdentity ();
   gluPerspective(65.0, (GLfloat) w/(GLfloat) h, 1.0, 50.0);
   glMatrixMode(GL_MODELVIEW);
   glLoadIdentity();
   glTranslatef (0.0, 0.0, -10.0);
}

void keyboard (unsigned char key, int x, int y)
{
   switch (key) {
      case 27: /* ESC */
         exit(0);
         break;
      default:
         break;
   }
}

int main(int argc, char** argv)
{
   glutInit(&argc, argv);
   glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH );
   glutInitWindowSize (300, 300); 
   glutInitWindowPosition (100, 100);
   glutCreateWindow (argv[0]);
   init ();
   glutDisplayFunc(display);
   glutReshapeFunc(reshape);
   glutKeyboardFunc(keyboard);
   glutIdleFunc(display); 
   glutMainLoop();
   return 0;
}
