Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 7 of 7

Thread: colors in opengl

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2004
    Posts
    3

    colors in opengl

    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.

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Jan 2003
    Location
    Virginia
    Posts
    586

    Re: colors in opengl

    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.

  3. #3
    Advanced Member Frequent Contributor
    Join Date
    Aug 2001
    Location
    Italy
    Posts
    626

    Re: colors in opengl

    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

  4. #4
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Location
    Gastonia, NC, USA
    Posts
    2,070

    Re: colors in opengl

    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).]

  5. #5
    Advanced Member Frequent Contributor
    Join Date
    Oct 2001
    Posts
    596

    Re: colors in opengl

    glColor3ub is unsigned bytes(0-255)

  6. #6
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    2,982

    Re: colors in opengl

    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).

  7. #7
    Intern Contributor
    Join Date
    Nov 2001
    Location
    Ireland
    Posts
    93

    Re: colors in opengl

    So specifying colors as floats saves processing time if they were defined as ints or ubytes?
    Wow.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •