Jump to content
  • Advertisement
Sign in to follow this  
voldemort62442

OpenGL Noob to opengl colors

This topic is 3852 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i am learning opengl and i was wondering how you know what color you will get when you call the gl color. ex glColor3f(?, ?, ?); if the ? are 2.0, 4.0, and 1.0 respectively how do i know what colors i will get?

Share this post


Link to post
Share on other sites
Advertisement
If I'm not much mistaken, the parameters are red, green and blue, respectively, with values ranging from 0.0 to 1.0.

For example, red would be glColor3f(1.0, 0.0, 0.0);, and cyan glColor3f(0.0, 1.0, 1.0);.

(Blue-book reference.)

[edit] I think that the values that you specified will give you white, since each parameter is greater than or equal to 1.0.

Oh, and if you want an idea of what colour you'll get, try opening up a drawing program, opening its colour selection dialogue (presuming that that dialogue allows for custom colours, and not just a pre-defined set), and setting the colour values according to your desired values, and converting to the program's range.

For example, if you want to find out what (1.0, 0.5, 0.5) should produce, and your drawing program takes red, green and blue values ranging from 0 to 255, set the drawing program's colour to 255, 128, 128 - i.e., 1.0*255, 0.5*255, 0.5*255.

Share this post


Link to post
Share on other sites
For byte colors (aka 0-255), you can also use glColor3b which might be cleaner if your values are in the 0-255 range and will directly match up to the values you may see in a common paint editor.

But just to verify what the others have said, glColor3f takes values in the 0-1 range.

Share this post


Link to post
Share on other sites
Quote:
Original post by Khaos Dragon
For byte colors (aka 0-255), you can also use glColor3b which might be cleaner if your values are in the 0-255 range and will directly match up to the values you may see in a common paint editor.

But just to verify what the others have said, glColor3f takes values in the 0-1 range.


I don't know what glColor3b does.
It is better to use glColor3ub or glColor4ub.
One trick is to do this :

uint colorvalue=0xFF55CCBBB;
glColor4ubv((ubyte)&colorvalue);

Share this post


Link to post
Share on other sites
Quote:
Original post by V-man
Quote:
Original post by Khaos Dragon
For byte colors (aka 0-255), you can also use glColor3b which might be cleaner if your values are in the 0-255 range and will directly match up to the values you may see in a common paint editor.

But just to verify what the others have said, glColor3f takes values in the 0-1 range.


I don't know what glColor3b does.
It is better to use glColor3ub or glColor4ub.
One trick is to do this :

uint colorvalue=0xFF55CCBBB;
glColor4ubv((ubyte)&colorvalue);


That is a cool trick, but I would guess that glColor3ub is probably better form.



Share this post


Link to post
Share on other sites
glColor3f or glColor4f is the natural color format or OpenGL so all the others first have to convert the bytes/integers to floats first and thus are a bit slower.

Note that you are free to provide any valid number of the given type to the glColor function. However, before the color is drawn to the color buffer, it is clamped to [0;1], so values bigger than 1.0 (float) or 255 (integer) will result in 1.0 or 255 when the color is written. You might however use a color value that is outside that range for color operations like multiplication or addition.

Share this post


Link to post
Share on other sites
Quote:
Original post by Lord_Evil
glColor3f or glColor4f is the natural color format or OpenGL so all the others first have to convert the bytes/integers to floats first and thus are a bit slower.

Note that you are free to provide any valid number of the given type to the glColor function. However, before the color is drawn to the color buffer, it is clamped to [0;1], so values bigger than 1.0 (float) or 255 (integer) will result in 1.0 or 255 when the color is written. You might however use a color value that is outside that range for color operations like multiplication or addition.


For me, glColorPointer(4, GL_UNSIGNED_BYTE, ..., ....)
has always been fast with VBOs.
If you try glColorPointer(3, GL_UNSIGNED_BYTE, ..., ....), the driver starts to stall.
I don't know about GL_FLOAT.

Share this post


Link to post
Share on other sites
Well, I'd say that with glColorPointer3 the driver has to fill in the alpha component for every vertex and thus cannot just read the array.

Share this post


Link to post
Share on other sites
0.0 - 1.0 are used because they are color depth independent. 1.0 will always be the whitest white, but 255,255,255 won't.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!