title: Rotating Pyramid in OpenGl by keeping the light source fixed
body: <p>This is the code I've written to display a 3D Pyramid and rotate it using keyboard. I've also provided a light source but it rotates with the Pyramid. I want the light source to remain fixed. What do I do? I did the programming on CodeBlocks.</p>
  
  <pre><code>#include&lt;windows.h&gt;
  #include&lt;GL/glut.h&gt;
  #include&lt;stdlib.h&gt;
  
  double rotate_y=0;
  double rotate_x=0;
  double rotate_z=0;
  
  void specialkeys(int key, int x, int y)
  {
  if(key==GLUT_KEY_RIGHT)
      rotate_y-=5;
  else if(key==GLUT_KEY_LEFT)
      rotate_y+=5;
  else if(key==GLUT_KEY_UP)
      rotate_x+=5;
  else if(key==GLUT_KEY_DOWN)
      rotate_x-=5;
  else if(key==GLUT_KEY_PAGE_UP)
      rotate_z+=5;
  else if(key==GLUT_KEY_PAGE_DOWN)
      rotate_z-=5;
  glutPostRedisplay();
  }
  
  void display()
  {
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glLoadIdentity();
  glRotatef(rotate_x,1.0,0.0,0.0);
  glRotatef(rotate_y,0.0,1.0,0.0);
  glRotatef(rotate_z,0.0,0.0,1.0);
  
  glBegin(GL_POLYGON);
  glColor3f( 1.0, 0.0, 0.0 );
  glVertex3f(0.5, 0.5, -0.5);       
  glVertex3f(0.0,0.0,0.0);       
  glVertex3f(-0.5,0.5,-0.5);       
  glEnd();
  
  glBegin(GL_POLYGON);
  glColor3f(   1.0,  0.0, 0.0 );
  glVertex3f(  0.5, 0.5, 0.5 );
  glVertex3f(  0.0,  0.0, 0.0 );
  glVertex3f( -0.5,  0.5, 0.5 );
  glEnd();
  
  glBegin(GL_POLYGON);
  glColor3f(  1.0,  0.0,  0.0 );
  glVertex3f( 0.5, 0.5, 0.5 );
  glVertex3f( 0.0,  0.0, 0.0);
  glVertex3f( 0.5,  0.5, -0.5 );
  glEnd();
  
  
  glBegin(GL_POLYGON);
  glColor3f(   1.0,  0.0,  0.0 );
  glVertex3f( -0.5, 0.5,  0.5 );
  glVertex3f( 0.0,  0.0,  0.0 );
  glVertex3f( -0.5,  0.5, -0.5 );
  glEnd();
  
  
  glBegin(GL_POLYGON);
  glColor3f(   1.0,  0.0,  0.0 );
  glVertex3f(  0.5,  0.5,  0.5 );
  glVertex3f(  0.5,  0.5, -0.5 );
  glVertex3f( -0.5,  0.5, -0.5 );
  glVertex3f( -0.5,  0.5,  0.5 );
  glEnd();
  
  glFlush();
  glutSwapBuffers();
  }
  
  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 };
  GLfloat white_light[] = { 1.0, 1.0, 1.0, 1.0 };
  GLfloat lmodel_ambient[] = { 0.1, 0.1, 0.1, 1.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);
  glLightfv(GL_LIGHT0, GL_DIFFUSE, white_light);
  glLightfv(GL_LIGHT0, GL_SPECULAR, white_light);
  glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
  glEnable(GL_LIGHTING);
  glEnable(GL_LIGHT0);
  glEnable(GL_DEPTH_TEST);
  }
  
  int main(int argc,char** argv)
  {
  glutInit(&amp;argc,argv);
  glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
  glutInitWindowPosition(100,100);
  glutInitWindowSize(320,320);
  glutCreateWindow("3D Pyramid!");
  init();
  glutDisplayFunc(display);
  glutSpecialFunc(specialkeys);
  glutMainLoop();
  return 0;
  }
  </code></pre>