/*
 *  drawdots.c
 *  This program demonstrates a dotdrawing process.
 *  Three dots are drawn.
 *
 *  Click the right button of the mouse within the opened
 *  window to exit the program.
 */
#include << X11/Xlib.h>
#include << GLUT/glut.h>
#include << OpenGL/gl.h>
#include << stdlib.h>
#include << stdio.h>

void myInit(void) 
{
   glClearColor (1.0, 1.0, 1.0, 0.0);   // set black background color
   glColor3f (0.0f, 0.0f, 0.0f);       // set the drawing color
   glPointSize (4.0);                  // set dot size 4 x 4
   glMatrixMode (GL_PROJECTION);       // set "camera shape"
   glLoadIdentity ();                    // clear the matrix
           // viewing transformation 
   gluOrtho2D (0.0, 640.0, 0.0, 480.0);  // set the World Window
}

void myDisplay(void)
{
   glClear (GL_COLOR_BUFFER_BIT);    // clear the screen
   glBegin(GL_POINTS);
       glVertex2i (100, 50);         // draw three points
       glVertex2i (100, 130);
       glVertex2i (150, 130);
   glEnd();
   glFlush ();                       // send all out to display
}

void myMouse(int button, int state, int x, int y)
{
  switch (button) {
     case GLUT_RIGHT_BUTTON:
        if (state == GLUT_DOWN)
           exit (-1);
        break;
     default:
        break;
  }
}

int main(int argc, char** argv)
{
   glutInit(&argc, argv);                         // initialize the toolkit
   glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);  // set display mode
   glutInitWindowSize (640, 480);                 // set screen window size
   glutInitWindowPosition (100, 150);       // set window position on screen
   glutCreateWindow (argv[0]);              // open the screen window
   myInit ();
   glutDisplayFunc(myDisplay);          // register redraw function
   glutMouseFunc(myMouse);              // register the mouse action function
   glutMainLoop();                      // go into a perpetual loop
   return 0;
}