title: OpenGL: Using glColorPointer make color weird
body: <p>Like the picture showed in the link below. I want to color my robot hand with white color(RGB: 0.9 0.9 0.9). When I use glColor3f, the white color display correctly. But when I store RGB data in GLfloat array and call glColorPointer, the color becomes so weird.</p>
  
  <p>Here is code of right arm</p>
  
  <pre><code> static const GLfloat playerBodyColor[] = {0.9, 0.9, 0.9};
  
   glEnableClientState(GL_COLOR_ARRAY);
   //glColor3f(0.9, 0.9, 0.9);
   glColorPointer(3, GL_FLOAT, 0, playerBodyColor);
   glTranslatef(0.0, player_body_height/6, player_body_width/2+LENGTH_UNIT/2);
   glRotatef(340.0, 0.0, 0.0, 1.0);
   glPushMatrix();
   glTranslatef(2*LENGTH_UNIT, 0.0, 0.0);
   glScalef (4.0, 1.0, 1.0);
   copyCodeSolidCube (LENGTH_UNIT);
   glDisableClientState(GL_COLOR_ARRAY);
   glPopMatrix();
  </code></pre>
  
  <p>If I change code like this:</p>
  
  <pre><code> static const GLfloat playerBodyColor[] = {0.9, 0.9, 0.9};
  
  
   //glEnableClientState(GL_COLOR_ARRAY);
   glColor3f(0.9, 0.9, 0.9);
   //glColorPointer(3, GL_FLOAT, 0, playerBodyColor);
   glTranslatef(0.0, player_body_height/6, player_body_width/2+LENGTH_UNIT/2);
   glRotatef(340.0, 0.0, 0.0, 1.0);
   glPushMatrix();
   glTranslatef(2*LENGTH_UNIT, 0.0, 0.0);
   glScalef (4.0, 1.0, 1.0);
   copyCodeSolidCube (LENGTH_UNIT);
   //glDisableClientState(GL_COLOR_ARRAY);
   glPopMatrix();
  </code></pre>
  
  <p>The color shows correct.</p>
  
  <p>The picture of correct-color code:
  <a href="http://imgur.com/S6zt5wf" rel="nofollow">http://imgur.com/S6zt5wf</a></p>
  
  <p>The picture of wrong-color code:
  <a href="http://imgur.com/8m5Ag1O" rel="nofollow">http://imgur.com/8m5Ag1O</a></p>
  
  <p>In the code, I also called a function copyCodeSolidCube.
  Here is part of copyCodeSolidCube code:</p>
  
  <pre><code>glEnableClientState (GL_VERTEX_ARRAY);
  glEnableClientState (GL_NORMAL_ARRAY);
  glVertexPointer (3, GL_FLOAT, 0, vert);
  glNormalPointer (GL_FLOAT, 0, norm);
  
  glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_BYTE, one);
  glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_BYTE, two);
  glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_BYTE, three);
  glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_BYTE, four);
  glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_BYTE, five);
  glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_BYTE, six);
  
  glDisableClientState (GL_VERTEX_ARRAY);
  glDisableClientState (GL_NORMAL_ARRAY);
  </code></pre>
  
  <p>Where is the problem?</p>