title: C++ Opengl - lighting using spotlight
body: <p>I have a model that needs to be under a spotlight/directional light,</p>
  
  <p>Meaning, I need to switch between the modes (Spotlight and directional).</p>
  
  <p>Here is the code with some explanation:</p>
  
  <p>I can rotate the model / light source with mouse movements so I am using </p>
  
  <p>glRotate and glTranslate for that.</p>
  
  <p>Once the user pressed the 'L' key I'm supposed to switch between the modes.</p>
  
  <p>here is the code for the lightning:</p>
  
  <pre><code>void LightBall::projectLight(void)
  {
  if(LIGHT == _lightMode){
      printf("Entering LIGHT mode\n"); &lt;--- Supposed to be a directional light
      glDisable(GL_LIGHT1);
      glEnable(GL_LIGHT0);
      glLightfv(GL_LIGHT0, GL_POSITION, _light_position);
  }
  
  if(SPOT_LIGHT == _lightMode){
      printf("Entering SPOTLIGHT mode\n"); &lt;--- Supposed to be a spotlight
      glDisable(GL_LIGHT0);
      glEnable(GL_LIGHT1);
      glLightfv(GL_LIGHT1, GL_POSITION, _light_position);
      glLightf(GL_LIGHT1, GL_SPOT_CUTOFF, 10.0);
      glLightf(GL_LIGHT1, GL_SPOT_EXPONENT, 2.0);
      glLightfv(GL_LIGHT1,GL_SPOT_DIRECTION,_spotlight_position);
  }
  }
  </code></pre>
  
  <p>The problem is I always get the same light mode when switching between them,</p>
  
  <p>Which is the following:</p>
  
  <p><img src="https://i.stack.imgur.com/IdVdZ.png" alt="directional"> </p>
  
  <p>And another example after switching between 2 light modes and still getting same light </p>
  
  <p>source with light source rotation (the small ball):</p>
  
  <p><img src="https://i.stack.imgur.com/0OmYL.png" alt="rotation"></p>
  
  <p>How can I get the wanted result?</p>
  
  <p>Here are the LIGHT0 &amp; LIGHT1 definitions:</p>
  
  <pre><code>    GLfloat light_ambient[] = { 1.0, 0.0, 0.0, 1.0 };
  GLfloat light_diffuse[] = { 1.0, 0.0, 0.0, 1.0 };
  GLfloat light_specular[] = { 1.0, 1.0, 1.0, 1.0 };
  _light_position[0] =  0.0;
  _light_position[1] = 1.0;
  _light_position[2] = 0.0;
  _light_position[3] = 0.0;
  
  _spotlight_position[0] = 0.0;
  _spotlight_position[1] = -1.0;
  _spotlight_position[2] = 0.0;
  
  glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
  glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
  glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
  
  glLightfv(GL_LIGHT1, GL_AMBIENT, light_ambient);
  glLightfv(GL_LIGHT1, GL_DIFFUSE, light_diffuse);
  glLightfv(GL_LIGHT1, GL_SPECULAR, light_specular);
  </code></pre>
  
  <p>Thanks!</p>