/* sampleGL.cpp */


#include <stdio.h>
#include <iostream.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include "glaux.h"


// This Section creates a Window, but uses only GL commands rather than X.

static void Init( void )
{
   /* one-time init (clearColor, set palette, etc) */

   glClearColor(0.5, 0.5, 0.5, 1.0 );
   glShadeModel( GL_FLAT );
}



static void Reshape( int width, int height )  // Essential Magic again!
{
   glViewport(0, 0, (GLint)width, (GLint)height);

   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
   glOrtho( -1.0, 1.0, -1.0, 1.0, -1.0, 1.0 );
   glMatrixMode(GL_MODELVIEW);
}


static void key_up()  //  A Function accessing the UP ARROW Key
{
   cout << "AUX_UP\n";
}


static void key_down()  // A Function accessing the DOWN ARROW Key
{
   cout <<"AUX_DOWN\n";
}


static void key_esc()  // A Function Accessing the ESCAPE key
{
   auxQuit();          // If pressed, the window QUITS
}



void DrawMyStuff()  // The Drawing Routine
{float i, j; 
    double x,y, xstep;
    glColor3f(1.0, 1.0, 0.0);
    glBegin( GL_POINTS );
	for (x = -1; x < 1; x += .001) // Step from -1 to +1 inefficiently
          { y = 1 - 2 * x * x;         // Calculate y value of parabola
            glVertex3f(x, y, 0.0);
          }


   glEnd();
} 


static void display( )  // Main display routine called from event loop
{
   /* clear viewport */
   glClear( GL_COLOR_BUFFER_BIT );

 
   /* draw stuff */
   DrawMyStuff();


   /* flush / swap buffers */
   glFlush();
   auxSwapBuffers();
}



int main( int argc, char **argv )
{  

   auxInitDisplayMode( AUX_RGBA );  // Initialize Display in RGB mode

   auxInitPosition( 50,50, 400, 400 );  // Draw a window starting at (50,50)
                                        // with size of 400 pixels for both
                                        // X and Y dimensions.

   if (auxInitWindow("My Window") == GL_FALSE)  // Create window and give it 
    { 						// a name.  If problems, quit. 
      auxQuit();
    }

   Init();  // Call Init routine

   auxExposeFunc(Reshape);  //  More Magic

   auxReshapeFunc(Reshape);
   auxKeyFunc( AUX_UP, key_up );
   auxKeyFunc( AUX_DOWN, key_down );

   auxMainLoop( display );  // Call display loop with display function

   return 0;
}

