/* Artist3D exports OpenGL-files.
   This program demonstrates how to use such a file.
   Here we assume, that the exported file is named XXX.c .
   You have to link this file with XXX.c and glut- and OpenGL-libraries. 
*/

#include <GL/glut.h>

GLfloat rx = 0.f;
GLfloat ry = 0.f;
GLfloat scale = 1.f;

void display(void)
{
	glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
   
	glLoadIdentity (); 
	gluLookAt (0.0, 1.0, 5.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0);
	glRotatef(ry, 0, 1, 0);
	glRotatef(rx, 1, 0, 0);
	glScalef(scale, scale, scale);
   
	glEnable(GL_TEXTURE_2D);
	glEnable(GL_DEPTH_TEST);
	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);

	/* Insert the draw function calls here !!!!!!!!! */
	drawXXX();

	glutSwapBuffers();
}

void reshape (int w, int h)
{
	glViewport (0, 0, (GLsizei) w, (GLsizei) h); 
	glMatrixMode (GL_PROJECTION);
	glLoadIdentity ();
	glFrustum (-1.0, 1.0, -1.0, 1.0, 1.5, 20.0);
	glMatrixMode (GL_MODELVIEW);
}

void keyboard(unsigned char key, int x, int y)
{
	switch (key) 
	{
		case 27: exit(0); break;
		case '+': scale *= 1.1; break;
		case '-': scale /= 1.1; break;
		case 'x': rx += 2.0; break;
		case 'X': rx -= 2.0; break;
		case 'y': ry += 2.0; break;
		case 'Y': ry -= 2.0; break;
		default: printf("x/X, y/Y to rotate +/- to scale, ESC to exit\n"); break;
	}

	glutPostRedisplay();
}

int main(int argc, char** argv)
{
	glutInit(&argc, argv);
	glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
	glutInitWindowSize (500, 500); 
	glutInitWindowPosition (100, 100);
	glutCreateWindow ("Artist3D-OGL-Export");
	glutDisplayFunc(display); 
	glutReshapeFunc(reshape);
	glutKeyboardFunc(keyboard);
	glutMainLoop();
	return 0;
}


