Pixel color format

I’m attempting to use the glDrawPixels function to view some data in color at particular pixel locations. I’m able to accomplish this ok in a gray scale environment. I’m including the approach I used for that situation. Any comments (or examples to point me to) on how to see the color RGB values displayed would be appreciated. Please be specific as I’m a beginner with openGl.

Here’s a snippet of my current implementation:

float *TheTempData;

int BufferSize = window_width*window_height;
TheTempData = new float[BufferSize];

for( row = 0; row < window_height; row++)
{
rowoffset = row*width;

 for( col = 0; col &lt; widow_width; col++)
   {
      int index = rowOffset + col;
     
      float temp = call to a function that returns a floating point value for temperature from a                                                           floating point 2-D array.

      float grey_temp = (temp - minTemp) / (maxTemp - minTemp);  // max/minTemp are floats
     
              grey_temp = MAX(grey_temp, 0.0);
              grey_temp = MIN(grey_temp, 1.0);
              TheTempData[index] = grey_temp;
       }
   }

To draw the pixels:

   glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
  glPushMatrix();
  
  glDrawPixels(window_width, window_height, GL_LUMINANCE, GL_FLOAT,                                 TheTempData);

I just want to display the same data in color, and if possible, avoid reading in the database (that the temperature values are extracted from) in a different data type (e.g. unsigned long as opposed to the current float type).

Thanks for the help!

If you just want to display it in shades of one color can you try to replace GL_LUMINANCE with GL_RED, GL_BLUE or GL_GREEN.

Originally posted by nvidia_linux:
If you just want to display it in shades of one color can you try to replace GL_LUMINANCE with GL_RED, GL_BLUE or GL_GREEN.

I actually would like to use the GL_RGB format with the appropriate data type. I’m not sure how to send the data into an array so that the RGB values would be deciphered by the glDrawPixels function. With the current implementation, I have a float array (TheTempData) that sends a float value. How do I convert the float value such that a Red Green and Blue color could be associated with it and be interpreted within glDrawPixels? Is this even possible? Thanks!

I guess you just have to make your arrays 3 times bigger and replace GL_LUMINANCE with GL_RGB. Each floating point is between 0…1 in the order red, green and blue.