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 6 of 6

Thread: glColor problem

  1. #1
    Intern Contributor
    Join Date
    Mar 2002
    Location
    CA,USA
    Posts
    57

    glColor problem

    HI,
    I am relatively new to OpenGL...

    I am facing one problem

    when I use
    glColor3f(1.0f,0.0f,0.0f);

    The object looks 3D

    But when i use color command like this
    glColor3f(250.0f,0.0f,0.0f);

    It does not look 3D at all...

    can any body explain me the reason..

    Thanks in advance
    aus

  2. #2
    Junior Member Newbie
    Join Date
    Aug 2002
    Posts
    24

    Re: glColor problem

    The colors in the RGBA mode are specified in the range of 0 to 1 for each component, so...there's no sense to use 250, i guess that the 250 should be clamped to 1.0 but it seems that opengl is messing up with such a higher value.

    Bye

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

    Re: glColor problem

    You must remember that the letter at the end of glColor3'x' indecates value ranges.
    Puting a higher value in glcolor3f which expects a float not an interger, so you get weird results.

    glColor3i rgb values from 0 to 255.
    glColor3f rgb values from 0.0 to 1.0

    glColor3f(1.0, 0.0, 0.0) is the same as
    glColor3i(255, 0, 0)

    128i = 0.5f

    Got it?




    Originally posted by aus79er:
    HI,
    I am relatively new to OpenGL...

    I am facing one problem

    when I use
    glColor3f(1.0f,0.0f,0.0f);

    The object looks 3D

    But when i use color command like this
    glColor3f(250.0f,0.0f,0.0f);

    It does not look 3D at all...

    can any body explain me the reason..

    Thanks in advance
    aus


    [This message has been edited by nexusone (edited 09-27-2002).]

  4. #4
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    3,115

    Re: glColor problem

    glColor3i rgb values from 0 to 255.
    glColor3f rgb values from 0.0 to 1.0

    glColor3f(1.0, 0.0, 0.0) is the same as
    glColor3i(255, 0, 0)
    No, they are not the same.

    Integer types are mapped so that integer value 0 is mapped to 0.0, and largest representable value is mapped to 1.0. Since a GLint is requires to have at least 31 significant bits (excluding sign bit), the color range of glColori is at least [0, 2147483647], where 2147483647 is mapped to 1.0.

    These glColor-calls will all result in the same colors, assuming the standard 8 bit char, 16 bit short and 32 bit int.
    Code :
    glColor3f(1, 0.5, 0);
    glColor3b(127, 63, 0)
    glColor3ub(255, 127, 0);
    glColor3s(32767, 16383, 0);
    glColor3us(65535, 32767, 0);
    glColor3i(2147483647, 1073741823, 0);
    glColor3ui(4294967295, 2147483647, 0);

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

    Re: glColor problem

    Yes you are correct on the interger values, I was thinking of byte values when I posted it.


    Originally posted by Bob:
    Code :
    glColor3f(1, 0.5, 0);
    glColor3b(127, 63, 0)
    glColor3ub(255, 127, 0);
    glColor3s(32767, 16383, 0);
    glColor3us(65535, 32767, 0);
    glColor3i(2147483647, 1073741823, 0);
    glColor3ui(4294967295, 2147483647, 0);

  6. #6
    Intern Contributor
    Join Date
    Mar 2002
    Location
    CA,USA
    Posts
    57

    Re: glColor problem

    Thanks for your explaination....

    aus

Posting Permissions

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