color

I want to colorize my vertexs using another variable. I have a value, k, associated with each vertex. Therefore, I believe a look-up table will work. However, I am not sure how to implement it using GLUT or OpenGL. Does OpenGL already have a colormap I can use or do I have to specify one? If so, where can I find a colormap? Thanks for any insight you can provide.

I don’t really understand what you mean… As far as I know OpenGl doesn’t work with a colortable. It colors the vertices with the color you provide (or adds some shine when lightning is enabled).
Why can’t you just use
glColor3f(R, G, B); ?

if you use color index mode, its like using a color table. but I agree with the post above just use glColor3f or glColor3ub or glColorfv

You can also use a one dimensional texture with the colors you want. Using this method you will have to clamp the ranges of your variable to 0-1. For instance if your variable k can range from 0-1000, just take k/1000 and use that as the texcoord.

I am going to use glColor3f(). However, I need to use k to generate RGB values for each vertex. What is the best way of doing this? I was thinking of making a color lookup table myself and using this table to assign RGB values since I could not find a precalculated lookup table in openGL. Or could I use textures?

again, why use a lookup table? what is k? do you want to generate random colors?

jebus

k represents the height above ground. Therefore, I want to assign red to the tallest object in the scene and blue to the lowest. Everything else will be assigned a color according the lookup table. In short, I want to assign colors to vertices according to the height above ground. Thanks to all who respond.

There’s a couple of ways you could do that.

  1. Using a 1d texture where your texture is say 256x1, with a gradient from blue to red. Then you use the formula s = (k-minHeight)/(maxHeight-minHeight); and use as in glTexCoord1f(s);

  2. Use the same formula s = (k-minHeight)/(maxHeight-minHeight) and then to calculate the color do something like R = s, G = 0, B = 1.0 - s. (This assumes you are using glColor3f. If you are using glColor3ub do the same thing, but then multiply each color component by 256.)