How to get the clear color?

Hello all,

Is it possible to retrieve the clear color set using glClearColor()?

Thanks

Hello,
Sure there is a way.I went through the openGL specs and found a variable GL_COLOR_CLEAR_VALUE. Use the glGet* function to get the value in this way …

GLfloat bkColor[3];
glGetFloatv(GL_COLOR_CLEAR_VALUE, bkColor);
bkColor[0]= Red component of clear color
bkColor[1]= Green component of clear color
bkColor[2]= Blue component of clear color

Hope this will help. Thanx

The clear color is four color components, so there should be enough room for four color components in the array.

GLfloat bkColor[4]; // 4 instead of 3

Otherwise the array is too small and you get a buffer overrun, which can cause pretty nasty and hard to find bugs.

Ahhhh… Thanks! I went through the specs and couldn’t find it (probably right in front of my nose). Thanks again for the quick replies.

Another tip: I think it’s defined (I THINK, my Red Book is locked up in my desk at work) that the clear color is initialized to <0, 0, 0, 0>; if you just remember that and take a note of whenever you change it (unless you have some crazy stuff going on in your application and have other threads zipping in, somehow using the context and changing it without you knowing!) and then you should always be aware of what it is, with no GL server overhead of glGet’ing!