Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 10 of 12

Thread: Rainbow color band and color palettes in OpenGL?

Hybrid View

  1. #1
    Intern Contributor
    Join Date
    Jun 2009
    Posts
    91

    Rainbow color band and color palettes in OpenGL?

    Hi

    How to manage different colour palettes in OpenGL? Basically I want to display a set of 2d points and points must be colored based on the depth value at that particular point. The depth value may range from -ve to +ve say -25m to 3000m. So how do I color these set of points using rainbow colorband?

    Thanks

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,117
    A point will display with the currently selected colour. So you have to do the mapping in your code to change the currently selected colour prior to rendering the point.

    Your logic could look like this
    Code :
    void setColour(float p_height)
    {
      if (p_Height < 0) glColor3f(1.0f,0.0f,0.0f);
      else  if (p_Height < 10) glColor3f(0.0f, 1.0f, 0.0f);
      else glColor3f(0.0f,0.0f,1.0f);
    }
     
    // main code
      glBegin(..
      setColour(vertex_1_Depth);
      glVertex2f(vertex_1_X,vertex_1_Y);
      setColour(vertex_2_Depth);
      glVertex2f(vertex_2_X,vertex_2Y);
    ...
      glEnd();

    The number of colours in your range is up to you.

    If you are familar with shaders you could use a 1D texture and look up the colour with a texture lookup. This would be easier then the method above.

  3. #3
    Intern Contributor
    Join Date
    Jun 2009
    Posts
    91
    Hi tonyo_au,

    Exactly that's the word. Lookup table. I don't want to hard code it every time. The logic you mentioned, I did used once, but for testing and it works fine for small number of points. So if number of points are more, then iterating all points and checking for height is time consuming isn't it? Presently I am working with VBOs. Based on the input array, the range must be automatically selected and the color palette should be used, the one which user selects. I googled up in regards to this, and I got this article (though it is quite old)

    http://web.agelid.com/protect/utile/...dex%20Mode.htm

    It suites my requirement. But wondering how to go ahead with this. Any idea or clue?

    As far as shaders are concerned, I tried a small example on shaders. I got the compilation error. vertex and fragment gets loaded but do not gets compiled. Is it that my system doesn't support shading programming. I am working with OpenGL 2.0. I am not sure whats going wrong. Any comments on this?

    Thanks

  4. #4
    Intern Contributor
    Join Date
    Jun 2009
    Posts
    91
    Should I go ahead with color index mode to solve my problem or is there much better way to do it.?

    Thanks

  5. #5
    Senior Member OpenGL Pro
    Join Date
    Jan 2007
    Posts
    1,201
    Color index mode is highly unlikely to be supported well or even hardware accelerated. Could you elaborate some more about what errors you got when you tried shaders? I ask because the classic approach to this would be to encode a palette in a 1D texture and fetch the colour from it in a vertex shader.

  6. #6
    Intern Contributor
    Join Date
    Jun 2009
    Posts
    91
    Hi mhagain,

    The sample shader program which I tested was having some problem. I got another example which displays an ellipse using shaders. IT works fine. Now I am experimenting on shader programming. Can you direct me towards a material, or link or article which helps me to understand how to encode a palette in a 1D texture and fetch color from it?

    Thanks

    Regards

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •