#include <cstdlib>
#include <GL/glut.h>


int main_window;


void init(void)
{    
   glClearColor (0.0, 0.0, 0.0, 0.0);
   glShadeModel(GL_SMOOTH);
   glEnable(GL_DEPTH_TEST);

   GLfloat position[] = { 3.0, .0, 1.0, 1.0 };

   glClearColor(0.0, 0.1, 0.1, 0.0);
   glEnable(GL_DEPTH_TEST);
   glShadeModel(GL_SMOOTH);

   glLightfv(GL_LIGHT0, GL_POSITION, position);

   glEnable(GL_LIGHTING);
   glEnable(GL_LIGHT0);
}


void display(void)
{
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();

  glTranslatef(0,0,-2);
  glutSolidTorus (0.275, 0.85, 8, 15);

  glutSwapBuffers();
}


void reshape(int w, int h)
{
  glViewport(0, 0, (GLsizei) w, (GLsizei) h);

  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluPerspective(70.0, (GLfloat) w/(GLfloat) h, .5, 30.0);
}


void myGlutIdle( void )
{
  /* According to the GLUT specification, the current window is 
     undefined during an idle callback.  So we need to explicitly change
     it if necessary */
  if ( glutGetWindow() != main_window ) 
    glutSetWindow(main_window);  

  glutPostRedisplay();
}

void keyboard(unsigned char key, int x, int y)
{
  if(key == 'q' || key == 'Q')
    exit(0);
}



void mouse(int button, int state, int x, int y) 
{
  if (button == GLUT_LEFT_BUTTON) {
    if (state == GLUT_DOWN) {
      // do something...
    }
  }
  
}
 

int main(int argc, char** argv)
{
   glutInit(&argc, argv);
   glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
   glutInitWindowSize(512, 512);
   glutInitWindowPosition(100, 100);
   main_window = glutCreateWindow(argv[0]);

   init();

   glutDisplayFunc(display);
   glutReshapeFunc(reshape);
   glutIdleFunc( myGlutIdle );

   glutMouseFunc(mouse);

   glutKeyboardFunc(keyboard);

   glutMainLoop();
   return 0; 
}

