PDA

View Full Version : colors in opengl



Rain
02-21-2003, 08:39 AM
where can i find a list of the corresponding numbers for colors for glColor3f(1.0, 1.0, 1.0) besides red, green, blue, black, white? I tried looking in windows paint for the rgb color numbers and for dark green, for example, the color is 0, 90, 0, but this does not display dark green in opengl. please help. thanks.

shinpaughp
02-21-2003, 09:07 AM
glColor comes in many flavors... the 3f at the end means that it takes 3 parameted (R (red component), G (green component), and B (blue component)) and that it takes floating point numbers. With 4ub at end, the function expects 1 additional component which is the alpha and would expect unsigned bytes. Valid values for floating point range from 0.0 to 1.0 - you can think of this as a percentage - 0.0 = 0%, 1.0 = 100%, 0.5 = 50%, etc. Basically, if you are using unsigned bytes, the colors are made of 1 byte each values ranging from 0 to 255. So for the example you gave you could either use glColor3ub(0, 90, 0) or glColor3f(0.0, 0.35294117647058823529411764705882, 0.0) which are equivalent. It is really a matter of preference as to how you wish to enter the information, and why not avoid the extra calculations if you already know the color byte format. In the end OpenGL stores all color information in floating point format.

Obli
02-21-2003, 11:35 AM
I usually open The gimp (or any other image manipulation program) and search for a color I like.

Those programs usually give the RGB values in the range 1-255.
Just take this value, divide by 255 and you've got the normalized 0.0-1.0 value.

Bye

nexusone
02-21-2003, 11:44 AM
well with glColorf the values are in float with range 1.0-0.0

try glColor3f(0.0, 0.8, 0.0) or

This should match up with your paint program.

glColor3ub( 0, 90, 0) ub = unsigned byte = 0 to 255



Originally posted by Rain:
where can i find a list of the corresponding numbers for colors for glColor3f(1.0, 1.0, 1.0) besides red, green, blue, black, white? I tried looking in windows paint for the rgb color numbers and for dark green, for example, the color is 0, 90, 0, but this does not display dark green in opengl. please help. thanks.



[This message has been edited by nexusone (edited 02-24-2003).]

Mazy
02-22-2003, 04:00 AM
glColor3ub is unsigned bytes(0-255)

Bob
02-22-2003, 05:07 AM
glColor3i( 0, 90, 0) i = int = 0 to 255

No, i = int = 0 to 2^31-1 (assuming 32-bit integers).

So glColor3i(0, 90, 0) is approximately equal to glColor3f(0, 0.000000042, 0).

blood.angel
02-23-2003, 09:56 PM
So specifying colors as floats saves processing time if they were defined as ints or ubytes?
Wow.