title: How to use the ambient color of the material instead of the global ambient color of lights? (OpenGL 1)
body: <p>I'm writting the lighting effect of my programming in OpenGL 1.1. The light and normals stuffs works. I have only a wrong color</p>
  
  <p>I would like to use the ambient color of the used material but not the global ambient light.</p>
  
  <p>When I use this code, I have a dark grey(64, 64, 64) for light-hidden face but never black (0, 0, 0).</p>
  
  <p>This is the pseudo code :</p>
  
  <pre><code>void Init()
  {
  glEnable(GL_LIGHTING);
  glEnable(GL_LIGHT0);
  SetAmbientLight(64, 64, 64); // global value
  material.ambientColor = VECTOR3F(0,0,0); // black color, other are default values of OpenGL
  }
  
  void SetAmbientLight(U8 r, U8 g, U8 b)
  {
      //  Ambient Light is a global value
      const GLfloat inv = 1.0f / 255.0f;
      const GLfloat ambientColor[] = {r * inv, g * inv, b * inv, 1.0f};
      glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientColor);
  }
  
  
  void Render()
  {
      UseMaterial(material);
      RenderTexturedObject();
      UseMaterial(NULL);
      UseLights();
  }
  
  void UseMaterial(MATERIAL *materialdata)
  {
      if (materialdata)
      {
          const VECTOR3F&amp; ambiantColor = materialdata-&gt;ambiantColor;
          const VECTOR3F&amp; diffuseColor = materialdata-&gt;diffuseColor;
          const VECTOR3F&amp; specularColor = materialdata-&gt;specularColor;
          const float&amp; shiness = materialdata-&gt;shiness;
          const VECTOR3F&amp; emissiveColor = materialdata-&gt;emissiveColor;
  
          const GLfloat amb[4] = {ambiantColor.x, ambiantColor.y, ambiantColor.z, 1.0f};
          const GLfloat diff[4] = {diffuseColor.x, diffuseColor.y, diffuseColor.z, 1.0f};
          const GLfloat spec[4] = {specularColor.x, specularColor.y, specularColor.z, 1.0f};
          const GLfloat emi[4] = {emissiveColor.x, emissiveColor.y, emissiveColor.z, 1.0f};
  
          glEnable(GL_COLOR_MATERIAL);
  
          glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, amb);
          glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diff);
          glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, spec);
          glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shiness);
          glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, emi);
      }
      else
      {
          glDisable(GL_COLOR_MATERIAL);
      }
  }
  
  void RenderTexturedObject()
  {
    FillVertexBuffer(mesh, t);
    FillTexCoordBuffer(mesh);
    FillColorBuffer(mesh, 255, 255, 255);
  
    glColor3ub(255, 255, 255);
  
    // Use normals only when lighting is used
    if (IsLightingEnabled() &amp;&amp; s_nbLights &gt; 0)
    {
      FillNormalBuffer(mesh, t);
      glEnableClientState(GL_NORMAL_ARRAY);
      glNormalPointer(GL_FLOAT, 12, gNormals);
    }
  
    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, tex);
  
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    glEnableClientState(GL_COLOR_ARRAY);
  
    glVertexPointer(3, GL_FLOAT, 0, gVertices);
    glTexCoordPointer(2, GL_FLOAT, 0, gTexCoords);
    glColorPointer(3, GL_UNSIGNED_BYTE, 0, gColors);
    glDrawElements(GL_TRIANGLES, 3 * mesh-&gt;nbtriangles, GL_UNSIGNED_SHORT, gIndexes);
  
    glDisable (GL_TEXTURE_2D);
    if (IsLightingEnabled() &amp;&amp; s_nbLights &gt; 0)
    {
      glDisableClientState(GL_NORMAL_ARRAY);
    }
  }
  
  void UseLights()
  {
          for (int lightIdx = GL_LIGHT0; lightIdx &lt;= GL_LIGHT7; lightIdx++)
          {
              const int idx = lightIdx - GL_LIGHT0;
              const LIGHT_DATA&amp; lightdata = s_lightsData[idx];
  
              const VECTOR3F&amp; ambiantColor = lightdata.ambiantColor;
              const VECTOR3F&amp; diffuseColor = lightdata.diffuseColor;
              const VECTOR3F&amp; specularColor = lightdata.specularColor;
              const VECTOR3F&amp; direction = lightdata.direction;
  
              const GLfloat amb[4] = {ambiantColor.x, ambiantColor.y, ambiantColor.z, 1.0f};
              const GLfloat diff[4] = {diffuseColor.x, diffuseColor.y, diffuseColor.z, 1.0f};
              const GLfloat spec[4] = {specularColor.x, specularColor.y, specularColor.z, 1.0f};
              const GLfloat dir[4] = {-direction.x, -direction.y, -direction.z, 0.0f}; // always use w=0.0 for a direction
  
              glLightfv(lightIdx, GL_AMBIENT, amb);
              glLightfv(lightIdx, GL_DIFFUSE, diff);
              glLightfv(lightIdx, GL_SPECULAR, spec);
              glLightfv(lightIdx, GL_POSITION, dir);
              glLightf(lightIdx, GL_SPOT_EXPONENT, 0.0f);
              glLightf(lightIdx, GL_SPOT_CUTOFF, 180.0f);
          }
  
  }
  </code></pre>