// 
// Torbert, 8.26.2009
// 
// Animation Demo, Version 1.0
// 
// A pacman-like figure moves across the screen.
// 

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

double xmin,ymin,xmax,ymax;
int w=400,h=300,xpos=20;

void display(void)
{
   glClear(GL_COLOR_BUFFER_BIT);
   glColor3f(0.0,0.0,0.0);

	glBegin(GL_POLYGON);
	glVertex2f(1.0*xpos/w+0.00,0.5);
	glVertex2f(1.0*xpos/w+0.11,0.65);
	glVertex2f(1.0*xpos/w+0.22,0.5);
	glVertex2f(1.0*xpos/w+0.06,0.45);
	glVertex2f(1.0*xpos/w+0.11,0.25);
	glVertex2f(1.0*xpos/w+0.01,0.25);
	glEnd();

   glutSwapBuffers();
}
void idle(void)
{
	xpos++;
	glutPostRedisplay();
}
void mouse(int button,int state,int xscr,int yscr)
{
	exit(0);
}
void keyfunc(unsigned char key,int xscr,int yscr)
{
	if(key=='q')
	{
		exit(0);
	}
}
void reshape(int wscr,int hscr)
{
	w=wscr; h=hscr;
   glViewport(0,0,(GLsizei)w,(GLsizei)h);
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();

	xmin=ymin=0.0; xmax=ymax=1.0;
	if(w<=h)
	   ymax=1.0*(GLfloat)h/(GLfloat)w;
	else
		xmax=1.0*(GLfloat)w/(GLfloat)h;

	gluOrtho2D(xmin,xmax,ymin,ymax);
   glMatrixMode(GL_MODELVIEW);
}
int main(int argc,char* argv[])
{  
   glutInit(&argc,argv);
   glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
   glutInitWindowSize(w,h);
   glutInitWindowPosition(100,50);
   glutCreateWindow("Animation Demo");

   glClearColor(1.0,1.0,1.0,0.0);
	glShadeModel(GL_SMOOTH);

   glutDisplayFunc(display);
	glutIdleFunc(idle);
	glutMouseFunc(mouse);
	glutKeyboardFunc(keyfunc);
	glutReshapeFunc(reshape);

   glutMainLoop();

   return 0;
}

// 
// Notes
// -----
// ./Lgcc animate_0
// ./animate_0
// 
