//  This program shows how to open a single window and plot bitmapped text
//  on the screen in Times Roman font. 
#include <string.h>
#include <stdio.h>
#include <stdarg.h>
#include <GL/glut.h>

#define initial_width 360             // Initial Window Width = 400 pixels
#define initial_height 360            // Initial Window Height = 400 pixels

int main_window;          // Outer Window and Inner Window ID numbers 
float xmax=2.0, xmin=-2.0, ymax=2.0, ymin=-2.0;

// Draw Background Colors.

DrawGraph()
{ int i, j; 
  float x, y, xstep, ystep, r, g, b;
  glBegin(GL_POINTS);
  for (i=0; i<360; i++){
    for (j=0; j<360; j++){
      xstep = (xmax-xmin)/359.0; 
      ystep = (ymax-ymin)/359.0;
      x = xmin + xstep * i; 
      y = ymin + ystep * j;
      r = i / 360.0;
      g = j / 360.0;
      b = 1.0;
      glColor3f(r, g, b);
      glVertex3f(x, y, 0.0);
      glFlush();
    }
  }
  glEnd();
} 

// 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 1 ");  // 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. */
}
