Thread: OpenGL hue rotation

  1. #1
    Registered User
    Join Date
    Jul 2007

    OpenGL hue rotation

    Does anyone know a way to rotate the hue of a 2d object or the whole opengl scene ?

  2. #2
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    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.

  3. #3
    Amazingly beautiful user.
    Join Date
    Jul 2005
    If you knew I'd have to kill you
    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.

    I'm also guessing you could somehow accomplish this with shaders, but I haven't had much experience with shaders.
    Programming Your Mom.

  4. #4
    Ethernal Noob
    Join Date
    Nov 2001
    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.

  5. #5
    Registered User
    Join Date
    Jul 2006
    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:

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

    Put this where it will execute BEFORE rendering loop:

    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;
    		aRGB[(k+j)%3] = (LMAX-1) - i;
    		RGBtoINT(aRGB[0], aRGB[1], aRGB[2])

    You'll need this function as well:

    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:

    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...

    for (m=0; m<LoopM; ++m)
    	INTtoRGB( m%vrINT.size() ) );
    	glVertex3f(, // i rendered screen x axis coords to doubles in this vector (x/app_width), // same for y axis (y/app_width)
    		0.0	);

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

    Last edited by simpleid; 08-15-2007 at 07:45 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linking OpenGL in Dev-C++
    By linkofazeroth in forum Game Programming
    Replies: 4
    Last Post: 09-13-2005, 10:17 AM
  2. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM
  3. OpenGL rotation
    By ay_okay in forum Game Programming
    Replies: 17
    Last Post: 01-31-2005, 11:12 AM
  4. Binary Search Trees Part III
    By Prelude in forum A Brief History of
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  5. OpenGL .dll vs video card dll
    By Silvercord in forum Game Programming
    Replies: 14
    Last Post: 02-12-2003, 07:57 PM