//  This program shows how to open a single window and plot a colored 
//  Pixel for every coordinate in the window
#include <string.h>
#include <stdio.h>
#include <stdarg.h>
#include <GL/glut.h>

#define initial_width 360             // Initial Window Width 
#define initial_height 360            // Initial Window Height

int main_window;          // Main Window ID 
float xmax=2.0, xmin=-2.0, ymax=2.0, ymin=-2.0;  // X-axis and y-axis values

// Draw Background Colors 

DrawGraph()
{ int row, col; 
  float x, y, xstep, ystep, r, g, b;
  xstep = (xmax-xmin)/359.0;  // X-distance between adjacent pixels 
  ystep = (ymax-ymin)/359.0;  // Y-distance between adjacent pixels 
  glBegin(GL_POINTS);
  y = ymin;                  // Initialize or Set First Row y-value
  for (row=0; row<360; row++){     // Go to each column
    x = xmin;                    // Initialize Start of Row 
    for (col=0; col<360; col++){
      r = row / 360.0;  // Calculate new value for Red
      g = col / 360.0;  // Calculate new value for Green
      b = 1.0;          // Keep blue always the same
      glColor3f(r, g, b);
      glVertex3f(x, y, 0.0);
      x += xstep;  // Find out next x-coordinate in row
    }
    y += ystep;    // Go to next Row
  }
  glEnd();
  glFlush();
} 

// Draw a set of axes

DrawAxes()
{  glBegin(GL_LINES);                         // Start Drawing Lines
    glColor3f(0.0, 0.0, 0.0);                 // Set Drawing Color
    glVertex3f(xmax,0.0, 0.0);                // Starting Point for x-axis
    glVertex3f(xmin, 0.0, 0.0);                // Ending Point
    glVertex3f(0.0, ymax,0.0);                // Staring Point for y-axis
    glVertex3f(0.0, ymin, 0.0);                // Ending Point
  glEnd();
 
}

  
// Display window 

void display1(void)
{ 
  glClear(GL_COLOR_BUFFER_BIT);
  DrawGraph();
  DrawAxes();                                 
  glFlush();                                  // Force all drawing
}
void init(void)
{ /* select clearing (background) color   */
   glClearColor(0.0, 0.0, 0.0, 0.0);

/* initialize viewing values */
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
   glOrtho(xmax, xmin, ymax, ymin, -1.0, 1.0);
}
                               

int main(int argc, char **argv)
{
  glutInit(&argc, argv);                                 // Primary Initialize  
  glutInitDisplayMode(GLUT_RGB);              // Initialize RGB mode in OpenGL
  glutInitWindowSize(initial_width, initial_height);  // Initialize window
  main_window = glutCreateWindow("Colors 1a ");  // Create main window with title
  init();				      // My initialization
  glutDisplayFunc(display1);                  // Pass pointer to display
  glutMainLoop();                             // Enter main loop - wait for interrupts
  return 0;             /* ANSI C requires main to return int. */
}
