title: OpenGL Directional Lighting + Positioning
body: <p>I'm writing an engine and using Light 0 as the "sun" for the scene. The sun is a directional light.</p>
  
  <p>I setup the scene's Ortho viewpoint, then setup the light to be on the "East" side of the screen (and to the character) (x/y are coordinates of the plane terrain, with a positive z facing the camera and indicating "height" on the terrain -- the scene is also rotated for an isometric view on the x axis).</p>
  
  <p>The light seems to be shining fine "East" of 0,0,0, but as the character moves it does not shift (CenterCamera does a glTranslate3f on the negative of the values provided, such that they can be mapped specifying world coordinates).  Meaning, the further I move to the west, it's ALWAYS dark, with no light.  </p>
  
  <pre><code>    Graphics.BeginRenderingLayer();
      {
          Video.MapRenderingMode();
  
          Graphics.BeginLightingLayer( Graphics.AmbientR, Graphics.AmbientG, Graphics.AmbientB, Graphics.DiffuseR, Graphics.DiffuseG, Graphics.DiffuseB, pCenter.X, pCenter.Y, pCenter.Z );
          {
              Graphics.BeginRenderingLayer();
              {
                  Graphics.CenterCamera( pCenter.X, pCenter.Y, pCenter.Z );
                  RenderMap( pWorld, pCenter, pCoordinate );
              }
              Graphics.EndRenderingLayer();
  
              Graphics.BeginRenderingLayer();
              {
                  Graphics.DrawMan( pCenter );
              }
              Graphics.EndRenderingLayer();
          }
          Graphics.EndLightingLayer();
      }
      Graphics.EndRenderingLayer();
  </code></pre>
  
  <p>Graphics.BeginRenderingLayer = PushMatrix, EndRenderingLayer = PopMatrix Video.MapRenderingMode = Ortho Projection and Scene Rotation/Zoom CenterCamera does a translate to the opposite of the X/Y/Z, such that the character is now centered at X/Y/Z in the middle of the screen.</p>
  
  <p>Any thoughts? Maybe I've confused some of my code here a little?</p>
  
  <p>The lighting code is as follows:</p>
  
  <pre><code>    public static void BeginLightingLayer( float pAmbientRed, float pAmbientGreen, float pAmbientBlue, float pDiffuseRed, float pDiffuseGreen, float pDiffuseBlue, float pX, float pY, float pZ )
      {
          Gl.glEnable( Gl.GL_LIGHTING );
          Gl.glEnable( Gl.GL_NORMALIZE );
          Gl.glEnable( Gl.GL_RESCALE_NORMAL );
          Gl.glEnable( Gl.GL_LIGHT0 );
  
          Gl.glShadeModel( Gl.GL_SMOOTH );
  
          float[] AmbientLight = new float[4] { pAmbientRed, pAmbientGreen, pAmbientBlue, 1.0f };
          float[] DiffuseLight = new float[4] { pDiffuseRed, pDiffuseGreen, pDiffuseBlue, 1.0f };
          float[] PositionLight = new float[4] { pX + 10.0f, pY, 0, 0.0f };
          //Light position of Direction is 5 to the east of the player.
  
          Gl.glLightfv( Gl.GL_LIGHT0, Gl.GL_AMBIENT, AmbientLight );
          Gl.glLightfv( Gl.GL_LIGHT0, Gl.GL_DIFFUSE, DiffuseLight );
          Gl.glLightfv( Gl.GL_LIGHT0, Gl.GL_POSITION, PositionLight );
  
          Gl.glEnable( Gl.GL_COLOR_MATERIAL );
          Gl.glColorMaterial( Gl.GL_FRONT_AND_BACK, Gl.GL_AMBIENT_AND_DIFFUSE );
      }
  </code></pre>