# OpenGL hue rotation

• 08-01-2007
OpenGL hue rotation
Does anyone know a way to rotate the hue of a 2d object or the whole opengl scene ?
• 08-02-2007
VirtualAce
I would venture to guess since the 2D object is made of vertices that altering the color at the vertices would do the trick.

But I'm not an OpenGL fella.
• 08-03-2007
CrazyNorman
You could render the entire scene to an in memory bitmap, perform the hue rotation however you would do that, pixel by pixel, and then blit the bitmap to the screen.

This NeHe tutorial includes how to render to a texture, from which the rest shouldn't be too complex.
http://nehe.gamedev.net/data/lessons....asp?lesson=36

I'm also guessing you could somehow accomplish this with shaders, but I haven't had much experience with shaders.
• 08-04-2007
indigo0086
you could try experimenting with transparency, having an object modify the hue by placing a flat plane in front of the viewport that is the hue you would like.
• 08-14-2007
simpleid
I wrote this for a project where I was trying to develop my own (more elegant) HSB formula, well this piece will give you ALL hue's in the full color spectrum in 24bit color space.

Put this BEFORE the RENDERING LOOP... it's way too big to recalculate over and over.

(this might not be the best way, but it will work if you can think of a creative way to implement it... which I'll leave up to you... hehe :-)

Make this vector GLOBAL:

Code:

```vector<int> vrINT; const int LMAX = 256;```

Put this where it will execute BEFORE rendering loop:

Code:

```for (int k=0; k<3; ++k) for (intj=1; j>=0; --j) for (inti=0; i<LMAX; ++i) {         if (j==1)                 aRGB[(k+j)&#37;3] = i;         else                 aRGB[(k+j)%3] = (LMAX-1) - i;         vrINT.push_back(                 RGBtoINT(aRGB[0], aRGB[1], aRGB[2])                 ); }```

You'll need this function as well:

Code:

```int RGBtoINT (int r, int g, int b) {         // assuming r|g|b is > 0 and <= 255         if (r>255) r = 255;         if (g>255) g = 255;         if (b>255) b = 255;         int cR=0, cG=0, cB=0;         cR = r;      // cR = 0xRR000000         cG = cR << 8; // cG = 0x00RR0000         cG = cG | g;  // cG = 0xGGRR0000         cB = cG << 8; // cB = 0x00GGRR00         cB = cB | b;  // cB = 0xBBGGRR00         return cB; }```

to get the RGB back IN RENDERING to put in to glColorf(R, G, B) use:

Code:

```int sINT[] = {0, 0, 0}; // <-- GLOBAL, put it where ever you define vrINT void INTtoRGB (int k) {         sINT[0] = (k >> 16) & 0xFF;         sINT[1] = (k >> 8) & 0xFF;         sINT[2] = (k) & 0xFF; }```

then in the rendering bit...

Code:

```glBegin(GL_LINE_STRIP); for (m=0; m<LoopM; ++m) {         INTtoRGB( vrINT.at( m%vrINT.size() ) );         glColor3f(                 sINT[0]/255.0,                 sINT[1]/255.0,                 sINT[2]/255.0);         glVertex3f(                 cvx.at(m), // i rendered screen x axis coords to doubles in this vector (x/app_width)                 cvy.at(m), // same for y axis (y/app_width)                 0.0        ); } glEnd();```

Now you have the full spectrum of HUES!! Adjust your calculations to do what ever you want with em!

Enjoy!