PDA

View Full Version : How to get the clear color?



01-22-2005, 09:51 PM
Hello all,

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

Thanks

MMMovania
01-23-2005, 02:53 AM
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

Bob
01-23-2005, 05:31 AM
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 3Otherwise the array is too small and you get a buffer overrun, which can cause pretty nasty and hard to find bugs.

01-23-2005, 04:55 PM
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.

Omaha
01-29-2005, 11:12 PM
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!