Click to See Complete Forum and Search --> : Look Up Table


rbha311
February 12th, 2009, 06:51 PM
I am trying to create a color lookup table which is meant to hold 255 different color values between red and blue. I am using the RGBA mode in openGL. The application I am working on receives a value between 0 and 255 and depending on the value it is meant to render a pixel onto the screen so a value of 0 renders a blue pixel and a value of 255 renders a red pixel and any value between renders the appropriate color pixel from the lookup table.

I was wondering if there were any such tables that existed that gave us the RGB values for all the different colors required between 0 and 255.

I am planning to store these RGB values into an array and then use the value between 0 and 255 as an index into this array so i can index to the correct color.

Thanks

bitshifter420
March 14th, 2009, 05:29 AM
Is this what you need?

#include <windows.h>

COLORREF color_table[256];

void InitColorTable()
{
BYTE red = 255;
BYTE green = 0;
BYTE blue = 0;

for(INT loop = 0; loop < 256; loop++)
{
color_table[loop] = RGB(red,green,blue);

red--;
blue++;
}
}

To specify the current rendering color...

void ApplyColor(INT index)
{
BYTE red = GetRValue(color_table[index]);
BYTE green = GetGValue(color_table[index]);
BYTE blue = GetBValue(color_table[index]);

glColor3ub(red,green,blue);
}