/*  w1gl.c  a basic yet complete OpenGL program */

#include <GL/glut.h>
#include <stdlib.h>

void display(void)
{
  char text[]="Click here to exit";
  char *p;
  
  /* clear window */
  glClear(GL_COLOR_BUFFER_BIT); 
  glLoadIdentity ();
  
  /* draw rectangle */
  glBegin(GL_LINE_LOOP);
    glVertex2f(-0.75,  0.0);
    glVertex2f(-0.75, -0.5);
    glVertex2f( 0.75, -0.5);
    glVertex2f( 0.75,  0.0);
  glEnd();
  
  /* draw text */
  glEnable(GL_LINE_SMOOTH);
  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  glEnable(GL_BLEND);
  glTranslatef(-0.8, 0.5, 0.0);
  glScalef(0.0015, 0.0015, 0.0);
  for(p=text; *p; p++)
    glutStrokeCharacter(GLUT_STROKE_ROMAN, *p);

  glFlush(); 
}

/* This routine handels mouse events */
static void mouse(int button, int state, int x, int y)
{
  /* We are only interested in left clicks */
  if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
    exit(0);
}

void init()
{
  /* set clear color to white */
  glClearColor (1.0, 1.0, 1.0, 0.0);
  /* set fill  color to black */
  glColor3f(0.0, 0.0, 0.0);

  glMatrixMode (GL_PROJECTION);
  glLoadIdentity ();
  glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
  glMatrixMode (GL_MODELVIEW);
}

int main(int argc, char* argv[])
{
  glutInit(&argc,argv);
  glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);  
  glutInitWindowSize(200,125);
  glutInitWindowPosition(0,0); 
  
  glutCreateWindow(argv[0]); 
  glutDisplayFunc(display);
  glutMouseFunc(mouse);
  init();
  glutMainLoop();
  return 0;
}

