Advertisement Jump to content
Sign in to follow this  

Mixing HSV colors the good way

This topic is 3854 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello all, I render tetrahedra with 300000+ colored triangles in 3D with glDrawElements() :
//at init
glVertexPointer(3, GL_FLOAT, 0, g->vertex_array);        
glColorPointer(3, GL_FLOAT, 0, g->color_array);
//rendering loop

I also use HSV colors for each of their vertices, converting HSV values to RBG before filling the color array
   red    orange  yellow  green   blue    purple
  (low values)                             (high values)

Now, if I render a triangle with vertices (RED, RED, BLUE) for instance, the color goes from red to blue by direct interpolation (passing by purple), instead of passing through all colors red -> orange->yellow->green->blue. This is particulary important for me as the color represents a 4th dimension, like a height map where each color represents a value. Is there a way to specify a palette or a color function, or even fill the triangle pixel by pixel ? Thanks a lot for your help.

Share this post

Link to post
Share on other sites
Umm.. this is the obvious and expected result, since interpolation across the surface of a polygon is always linear - and since you already converted to RGB, the interpolation will be linear *in RGB space*.

You'll have to use some kind of per-fragment functionality to get what you want. It might be possible to hack this together with texture lookups in the fixed function pipeline, but you'd probably be better off with a fragment program or fragment shader.


Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!