Change window color after color is picked

I am working on a color picking program with two windows.
There’s a cube (from which you pick the color) in the main window. Once the user picks a color, the second window has to make it’s background color into the color that was picked.
I use

glReadPixels()

to get the color. I have a global char array that stores this color.
I know this is working because I display the color’s RGB value in the console window and the correct values are printed.
In the new window, other than the initialization things, all I have is a

glClearColor()

in the display function. The values in the glClearColor are from the global array that I mentioned earlier. So, (with my limited knowledge) I am not sure where I’m going wrong.
The color in the new window is always black and never changes to the picked color.

How can I fix this?

Are you actually clearing the window? I.e. are you calling glClear in the display function, and is the display function actually being called for that window?

The display function is for the second window.
But I don’t call glClear in it (I call glClearColor)

glClearColor sets the clear colour which glClear uses to clear the window. You need to call glClear; and unless the toolkit does it automatically, you also need to swap buffers (glutSwapBuffers or similar).

Ahh I didn’t know that.

void colorDisplay()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glFlush();
glClearColor((int)pixel[0], (int)pixel[0], (int)pixel[0], 0.0f);
glutSwapBuffers();
}

This is my function now.
I use the same glClear in my other display function.

Adding the glClear did not help

For one thing, you should call glClearColor before glClear. glClearColor itself doesn’t do anything except set the colour to be used by a subsequent glClear call.

The other thing: is the display function actually getting called for the other window? Add a print statement or set a debugger breakpoint to confirm. With GLUT, you should probably be calling glutSetWindow followed by glutPostRedisplay to force it to be redrawn.

I got it to work.
Turns out I never reset the window to the second one using glutSetWindow().

Thanks for the help