Colormap texture

I’m trying to use a color lookup table in shaders to convert rgb grayscale gl_Color to rgb color gl_Color. I want to use something similar to this :
http://blogs.mathworks.com/images/loren/73/colormapManip_14.png

I would like to know how to code this. I just don’t know how to create a texture and to write the good color values in that texture to have a color map. I didn’t find any tutorial while looking on google, well at least searching for “creat lookup texture opengl” didn’t give anything. Thanks for your help.

Well did you try with correct spelling for “create” ?
Take any texture tutorial, but instead of loading image array from disk, create the array with the code and fill it with you values. A 1D texture will do.

I thought i needed a 3D texture for each color since i have a red, green and blue value for each.
Do you mean something like that?


color_triplet table[256] = {{0,0,0}}; /* Initialize to all black */

    i = 20; /* first 20 and last 20 are reserved */
    for (red = 0; red <= 255; red+= 51) {/* the six values of red */
        for (green = 0; green <= 255; green += 51) {
            for (blue = 0; blue <= 255; blue+= 51) {
                table[i].r = red;
                table[i].g = green;
                table[i].b = blue;
                ++i;
            }
        }
    }

What should be the format of the array in order to load it as a uniform texture in glsl?