• Create Account

## Color

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

14 replies to this topic

### #1clrscr  Members

158
Like
Likes
Like

Posted 13 December 2001 - 09:12 AM

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

100
Like
Likes
Like

Posted 13 December 2001 - 09:17 AM

  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.

100
Like
Likes
Like

Posted 13 December 2001 - 09:19 AM

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.

### #4merlin9x9  Members

174
Like
Likes
Like

Posted 13 December 2001 - 09:24 AM

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

### #5RabidChild  Members

122
Like
Likes
Like

Posted 13 December 2001 - 09:34 AM

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.

### #6ANSI2000  Members

122
Like
Likes
Like

Posted 13 December 2001 - 09:41 AM

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???

100
Like
Likes
Like

Posted 13 December 2001 - 09:43 AM

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.

### #8Dredge-Master  Members

175
Like
Likes
Like

Posted 13 December 2001 - 04:48 PM

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

### #9ANSI2000  Members

122
Like
Likes
Like

Posted 13 December 2001 - 07:08 PM

Scuse me the look up table was my idea!!! Trying to short change me over heres

### #10merlin9x9  Members

174
Like
Likes
Like

Posted 14 December 2001 - 09:07 AM

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.

### #11siaspete  Members

208
Like
Likes
Like

Posted 14 December 2001 - 09:24 AM

Hi,

Modern OpenGL drivers are optimised for Q3, so storing the colour information in the same format as the game is almost guaranteed to be fastest.

4 bytes packed into an int, not floats. Also D3D takes colour in this form, so I think it''s the way to go.

### #12merlin9x9  Members

174
Like
Likes
Like

Posted 15 December 2001 - 11:07 AM

That''s a shortsighted way of thinking. Beyond that, not all drivers are optimized for Q3. In fact—arguably—no drivers are except for ATI''s. We also mustn''t forget that Windows is not the only OpenGL platform.

### #13Inmate2993  Members

222
Like
Likes
Like

Posted 15 December 2001 - 12:11 PM

I''d say go with the real numbers and then just have some constant that represents 1/256 (.00390625). While the video cards have 8bit color components, the API that rests on top of them work in a different number format, and those API are usually highly optomized by highly paid professionals, which means you probably couldn''t out do their code.

:: Inmate2993
:: William C. Bubel

### #14Dredge-Master  Members

175
Like
Likes
Like

Posted 16 December 2001 - 01:47 AM

quote:
Original post by ANSI2000
Scuse me the look up table was my idea!!! Trying to short change me over heres

Oops, sorry bout that Ansi2000, thought it was Admiral Binary that posted it. My mistake.

Beer - the love catalyst

### #15Dredge-Master  Members

175
Like
Likes
Like

Posted 16 December 2001 - 01:50 AM

Oh yeah, I am not sure if anyone else has mentioned this above (can''t be bothered checking) but you can use (albeit it is slower) glColor3b() instead (or something similar to it if I got the name wrong).

There are variants of the functions that take different types (float, int, double, char) and stuff, so just use the char version.

Beer - the love catalyst

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.