Color

Started by
13 comments, last by clrscr 22 years, 4 months ago
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
-----------------------------When men speak of the future, the Gods laugh.An apology for the devil: it must be remembered that we have heard one side of the case. God has written all the books.Samuel Butler (1835 - 1902)
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.
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.
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...
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.
--Ben CarterRomans 8:38-39
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???
quote:P.S. I may have this wrong...


...what more can I say?

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

I finally got it all together...
...and then forgot where I put it.
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 firstfloat 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 isunsigned char red=250;unsigned char green=8;unsigned char blue=97;you would just useglColour3f(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
Beer - the love catalystgood ol' homepage
Scuse me the look up table was my idea!!! Trying to short change me over heres
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.

This topic is closed to new replies.

Advertisement