View Full Version : Color display problems

07-12-2000, 07:18 AM
I am trying to display a simple array of integer values with glDrawPixels. I am using glut and I have created the window with GLUT_INDEX specefied. I then use glutSetColor to set some index values to specific colors. When I draw the pixels however, they dont come out the colors I specified. They are different colors. I ran a glGet to find the current index which is 1.

here are some portions of my code :

glutInitDisplayMode(GLUT_DOUBLE | GLUT_INDEX);
acquirewindow = glutCreateWindow("Acquire");
glutSetColor(69, 1.0,0.0,0.0);

then... in the "acquiredisplay" function..

void acquiredisplay(void)
int i;


for (i=0; i<5000; i++)
pixels[i] = 69;

for (i=5000; i<10000; i++)
pixels[i] = 2;

glDrawPixels(100, 100, GL_COLOR_INDEX, GL_INT, pixels);


When I run the program, the area that should be color #69 comes out black, changing the numbers does not help, even if I try to define color #1 it does not change the color.
If you can help me out I would really appreciate it.

On a related topic
I have seen the glIndex command that sets the current index, but I cannot find a function that defines an index. Does anyone know the name of a function like that or where I could find an example of something like this?

Thanks a lot

07-12-2000, 01:39 PM
Seems as not many people program in color index mode today. Be warned, that is almost nowhere hardware accelerated anymore. Check the vendor you got with glGetString and see for yourself, high chance you have a Microsoft pixelformat. RGBA is the mode of choice for performance.
Have you tried 256 colors display resolution in case it was a HW accelerated format in need of the system palette?
I'm not familiar with the glut color table mechanism. I would specify the array in unsigned chars and check the unpack_alignments.
Have a try with an RGBA format and checkout the manual on pixel_map settings.

07-13-2000, 10:23 AM
The reason I am doing this is color index mode is that eventually I want to display some frame grabber data which is grayscale, and in bytes, 0-255. I thought I would just make an index of grays that corresponded with numbers 0-255 and then use the index to display the data. Does this seem reasonable? Do you know a better way?

07-14-2000, 07:34 AM
Have you got the former program working now?

How does OpenGL come in play at all?
Simply displaying the frame grabber images could also be done with 2D graphics operations on any platform.

Do you have informations on how many frames per second you want to display and what you're going to do with it?

You could possibly download the image as a paletted texture with grayscale look up table and texture any geometry with it. Look in one of the former threads about the glTexSubImage2D() performance questions.

07-14-2000, 08:09 AM
I have gotten the program to work.
I made an RGBA window, then I used glDrawpixels. I set up index_to_color maps
with glPixelTransfer and glPixelMap.