PDA

View Full Version : glColor3 - Clamped to 0.0 to 1.0 ?



Andrew Jameson
01-29-2008, 09:34 AM
Hi,
It's been my understanding that glColor3 is clamped to the range 0.0 to 1.0. I've been trying to get a smoke effect to look right and out of desparation upped the color to glColor3f(1.5,1.5,1.5,Alpha) ... and voila it looks great !

I'm now confused over my assumption about the clamping range and will my parameters be accepted on all cards ?

From the help about glColor ...

"Signed integer color components, when specified, are linearly mapped to floating-point values such that the most positive representable value maps to 1.0, and the most negative representable value maps to - 1.0. Floating-point values are mapped directly.

Neither floating-point nor signed integer values are clamped to the range [0,1] before updating the current color. However, color components are clamped to this range before they are interpolated or written into a color buffer."

The second paragraph seems to contradict the first ...

Anyone care to enlighten me ? (and more importantly - can I use values > 1.0 ?)

Thanks

Andrew

Dark Photon
01-29-2008, 10:22 AM
Hi,
It's been my understanding that glColor3 is clamped to the range 0.0 to 1.0...Anyone care to enlighten me ? (and more importantly - can I use values > 1.0 ?)
Yes. You are talking about disabling vertex attribute normalization that occurs for some vertex attributes formats by default. You can control that by populating the vertex attribute using glVertexAttribPointer instead. It has a normalize Y/N argument. Or use float or signed integer formats as those aren't clamped.

Also, to disable the color clamping that occurs in the pipe by default, disable the clamping or use a TEXCOORD vertex attribute instead. For the former, see the ARB_color_buffer_float (http://www.opengl.org/registry/specs/ARB/color_buffer_float.txt) extension. For instance:


glClampColorARB( GL_CLAMP_VERTEX_COLOR_ARB , GL_FALSE )
glClampColorARB( GL_CLAMP_FRAGMENT_COLOR_ARB, GL_FALSE )
glClampColorARB( GL_CLAMP_READ_COLOR_ARB , GL_FALSE )
For Mesa, use its special ClampColor method, which is different because of a silly patent issue (http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Board=3&Number=231810).

Andrew Jameson
01-31-2008, 04:10 AM
Thanks for your very comprehensive and understandable response.

Regards,

Andrew