/* melite1a.c - visualizza un pianeta e una navetta in 2D
 *	usando le primitive viste
 * 
 *  Autore: Andrea Fusiello, Andrea Colombari 2004
 *
 *	arrow keys		- move planet and spaceship coherently  
 *	s key			- commuta tra modalita' con shading e flat
 *	Escape Key		- esce dal programma
 */
#include <GL/glut.h>	/* includes gl.h, glu.h */

#include <stdlib.h>
#include <stdio.h>
#include <math.h>

/* Function Prototypes */

GLvoid initgfx( GLvoid );
GLvoid keyboard( GLubyte, GLint, GLint );
GLvoid specialkeys( GLint, GLint, GLint );
GLvoid drawScene( GLvoid );

void checkError( char * );
void printHelp( char * );


/* Global Definitions */

GLboolean flat = GL_TRUE;

#define KEY_ESC	27	/* ascii value for the escape key */

int
main( int argc, char *argv[] )
{
	GLsizei width, height;

	glutInit( &argc, argv );

	width = glutGet( GLUT_SCREEN_WIDTH ); 
	height = glutGet( GLUT_SCREEN_HEIGHT );
    
	glutInitWindowPosition( width / 4, height / 4 );
	glutInitWindowSize( width / 2, height / 2 );
	glutInitDisplayMode( GLUT_RGBA );
	glutCreateWindow( argv[0] );

	initgfx();

	//glutKeyboardFunc( keyboard );
	//glutSpecialFunc( specialkeys );
	glutDisplayFunc( drawScene ); 

	printHelp( argv[0] );

	glutMainLoop();
    
    return(0);
}

void printHelp( char *progname )
{
	fprintf(stdout, 
		"\n%s - elite in 2D with moving objects\n\n"
		"arrow keys - move planet and artificial satellite coherently\n"
		"<s> key    - toggle smooth/flat shading\n"
		"Escape Key - exit the program\n\n",
		progname);
}

GLvoid initgfx( GLvoid )
{
	/* set clear color to black */
	glClearColor( 0.0, 0.0, 0.0, 1.0 );
	glOrtho( -4.0f, 4.0f, -3.0f, 3.0f, -3.0f, 3.0f );
}

void checkError( char *label )
{
	GLenum error;
	while ( (error = glGetError()) != GL_NO_ERROR )
		printf( "%s: %s\n", label, gluErrorString(error) );
}

GLvoid keyboard( GLubyte key, GLint x, GLint y )
{   
	/* s key */
		/* toggle between smooth and flat shading */

	/* Exit when the Escape key is pressed */
}

GLvoid specialkeys( GLint key, GLint u, GLint v )
{   
	/* arrow keys */
		/* move the point of view */
}

GLvoid drawScene( GLvoid )
{
	static GLfloat yellow[] = { 1.0f, 1.0f, 0.0f };
	static GLfloat darkgreen[] = { 0.0f, 0.25f, 0.0f };
	static GLfloat blue[] = { 0.0f, 0.0f, 1.0f };
	static GLfloat grey[] = { 0.5f, 0.5f, 0.5f };

	glClear( GL_COLOR_BUFFER_BIT );

	/* Do all your OpenGL rendering here */
   
	/* Draw a triangle fan for the planet; make
	 * the center yellow, and the edges darkgreen
	 */
	
	/* Draw a triangle strip for the spaceship;
	 * use your fantasy to give it a shape
	 * and use two different color (e.g. blue and 
	 * grey) for shading */

	checkError( "drawScene" );
	glFlush();
}

