Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Color

This topic is 6000 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

Is there a way I can get OpenGL to use what most graphics programs use for color, i.e. instead of saying full red = 1.0,have full red = 256. If this post if confusing, let me know and I''ll try and clarify things. P.S. This is what I use for color now: glColor3f(0.0f,0.0f,0.0f); "You can observe a lot just by watching."- Yogi Berra

Share this post


Link to post
Share on other sites
Advertisement
How about making your own function:

  
void my_glColor3f(float r, float g, float b)
{
glColor3f((r/256),(g/256),(b/256));
}


Hope this helps...

---------------

I finally got it all together...
...and then forgot where I put it.

Share this post


Link to post
Share on other sites
In fact, i think that bitshifting right by 8 would be faster. I''m not sure about this, and the compiler may do it for you, but if you want to impress someone, do this:

  
void my_glColor3f(float r, float g, float b)
{
glColor3f((r>>8),(g>>8),(b>>8));
}


P.S. I may have this wrong...

---------------

I finally got it all together...
...and then forgot where I put it.

Share this post


Link to post
Share on other sites
Certainly. Use glColor3b or glColor4b. But do not do this. All 3D API''s convert integral color components, coordinates, and angles to floating-point internally, so there''s theoretically a performance hit to using integral values. Beyond that, eventually we''ll have more than 8 bits per channel, so 0 to 255 will no longer be enough. The 0.0 to 1.0 range is not only neutral to the actual color depth, but also happens to be in the API''s (and hardware also, most likely) native format. Furthermore, not "everyone" uses 0 to 255--in fact, I''d say that most people use floating-point. I don''t see how anything could be more intuitive than values that are effectively percentages; 50% of 0.0 to 1.0 = 0.5, as opposed to 50% = 128 of 0 to 255.

Use floating-point. Just get used to it and I promise that, eventually, you''ll never look back again. Soon everything will be floating point...

Share this post


Link to post
Share on other sites
Dividing by 256 would work, but NOT bitshifting. This is because you want to do floating-point division, not integer division. And when you divide, divide by 256.0 instead of 256 so that it will give you the fractional part. Otherwise you''ll get either 0 or 1.

Share this post


Link to post
Share on other sites
And to squeeze out every bit of nano seconds from your cpu...

Precompute the values in a table so instead of dividing everytime you want to set a calor which can at times be per vertex, you refernce to the index....

Unless dividing is very fast???

Share this post


Link to post
Share on other sites

Do not divide by 256. You will get a slight performance hit out of it.

multiply by 0.00390625f or do what Admiral Binary stated and place all the values in a lookup table first

float c_lookup[256];
for(unsigned char j=0;j<256;j++)
c_lookup[j]=i*0.00390625f;

then when you use the colours, lets say you have a colour which is

unsigned char red=250;
unsigned char green=8;
unsigned char blue=97;

you would just use

glColour3f(c_lookup[red],c_lookup[green],c_lookup[blue]);





Beer - the love catalyst
good ol' homepage"

Edited by - Dredge-Master on December 13, 2001 11:52:58 PM
Just get comfortable with floating-point. Even multiplication and array access will introduce performance degradation. Just use floating-point; using integers to describe colors is archaic.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!