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

#include <iostream>
#include <cstdlib>
using namespace std;

void keyboard
(
  unsigned char key,
  int x,
  int y
)
{
  switch (key)
  {
    case 27: exit(0);
  }
}

inline void glerrordisplay()
{
  GLenum errval = glGetError();
  if (errval != GL_NO_ERROR)
     cout << gluErrorString( errval ) << endl;
}

void init()
{
  GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
  GLfloat mat_shininess[] = { 50.0 };
  GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 };

  glClearColor(0.0,0.0,0.0,0.0);
  glShadeModel(GL_SMOOTH);

  glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
  glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
  glLightfv(GL_LIGHT0, GL_POSITION, light_position);

  glEnable(GL_LIGHTING);
  glEnable(GL_LIGHT0);
  glEnable(GL_DEPTH_TEST);
  glEnable(GL_NORMALIZE);
  glEnable(GL_COLOR_MATERIAL);
}

void display()
{

  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);


  glDisable(GL_BLEND);

  glEnable(GL_DEPTH_TEST);
  glColor3f(0.0,1.0,0.0);

  glPushMatrix ();
  glTranslatef (-0.75, -1.5, 10.0);
  glRotatef (270.0, 1.0, 0.0, 0.0);
  glutSolidCone (1.0, 2.0, 15, 15);
  glPopMatrix ();


  double radius=1.0;
  unsigned int slices=40;
  unsigned int stacks=40;

  glPushMatrix();

  glDisable(GL_DEPTH_TEST);
  glEnable(GL_BLEND);
  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

  glColor4f(1.0,1.0,0.0,0.6);
  glutSolidSphere(radius,slices,stacks);

glerrordisplay();

  glPopMatrix();

  glutSwapBuffers();
}


void reshape(int w, int h)
{
  float r = (float)w / (float)h;
  float ri = (float)h / (float)w;

  glViewport(0,0,w,h);
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();

  float c=1.5;

  if (w<=h)
  {
    glOrtho(-c,c,-c*ri,c*ri,-10.0,10.0);
  }
  else
  {
    glOrtho(-c*r,c*r,-c,c,-10.0,10.0);
  }

  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
}



int main(int argc, char** argv)
{
  glutInit(&argc,argv);
  glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
  glutInitWindowSize(150,150);
  glutInitWindowPosition(100,100);
  glutCreateWindow(argv[0]);
  init();
  glutDisplayFunc(display);
  glutReshapeFunc(reshape);
  glutKeyboardFunc(keyboard);


  glutMainLoop();
  return 0;
}



