Archived

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

clrscr

Color

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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
"Please refrain from bothering Booster."

Share this post


Link to post
Share on other sites
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