Thread: OpenGL hue rotation

  1. #1
    Registered User
    Join Date
    Jul 2007
    Posts
    3

    OpenGL hue rotation

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

  2. #2
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    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
    Location
    If you knew I'd have to kill you
    Posts
    254
    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.
    Programming Your Mom. http://www.dandongs.com/

  4. #4
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    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
    Posts
    162
    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!
    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 Cprogramming.com
    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