title: OpenGL: How do you create a colormap texture?
body: <p>colorMap instantiation:</p>
  
  <pre><code>GLfloat colormapColors[16];
  </code></pre>
  
  <p>here's my colormap data:</p>
  
  <pre><code>colormapColors[0] =  0.0f; // black
  colormapColors[1] =  0.0f;
  colormapColors[2] =  0.0f;
  colormapColors[3] =  0.0f;
  
  colormapColors[4] =  0.0f; // blue
  colormapColors[5] =  0.0f;
  colormapColors[6] =  1.0f;
  colormapColors[7] =  0.0f;
  
  colormapColors[8] =  1.0f; // red
  colormapColors[9] =  0.0f;
  colormapColors[10] = 0.0f;
  colormapColors[11] = 0.0f;
  
  colormapColors[12] = 1.0f; // white
  colormapColors[13] = 1.0f;
  colormapColors[14] = 1.0f;
  colormapColors[15] = 1.0f;
  </code></pre>
  
  <p>in my render loop I have</p>
  
  <pre><code>glGenTextures(1, &amp;texture); // get texture id
  glBindTexture(GL_TEXTURE_1D, texture);
  glTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA32F, 4, 0, GL_RGBA, GL_FLOAT, colormapColors);
  glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); // linear interpolation when too small
  glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // linear interpolation when too bi
  glErrorCheck;
  </code></pre>
  
  <p>fragment shader:</p>
  
  <pre><code>vec4 color = texture(ourTexture, clamp(alpha,0.0,1.0));
  gl_FragColor = vec4(color.r, color.g, color.b, 1.0);
  </code></pre>
  
  <p>alpha is calculated by distance to center, and I get:</p>
  
  <p><a href="https://i.stack.imgur.com/cYLed.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cYLed.png" alt="bad dot"></a></p>
  
  <p>so, clearly we have the black, blue, red, white. There should be no grey. I think it's a data alignment problem. Am I doing glTexImage1D wrong?</p>