Question about RGB with OpenGL
Ok, sorry about this dumb question, but by chance is their a site or quick and painless function I could use that would return RGBA (I think) values that where converted from RGB values so I could use them for glColor3f and etc.
I know this site isn't much on spoon feeding, but I did some searching and could not find a good piece of info for C++ and RGB converting.
I remember seeing and working with a function that did this, but forgot where and how too do it.
Project Info:
VS2005 STD
C++/Win32/OpenGL
Say again? RGBA from RGB you think? I caught something about glColor3f, so ill take a stab and say you want to go from byte (0 ->255) range to float?
byte r g b a
float toFloat = 1.0 / 255.0
float r = byte r * toFloat
float g = byte g * toFloat
float b = byte b * toFloat
float a = byte a * toFloat
is that what you wanted?
byte r g b a
float toFloat = 1.0 / 255.0
float r = byte r * toFloat
float g = byte g * toFloat
float b = byte b * toFloat
float a = byte a * toFloat
is that what you wanted?
There's no need to convert a RGBA color to a RGB color for use with glColor3f. Firstly, there's a glColor4f, which will take the alpha channel, naturally. And secondly, you simply don't give glColor3f the alpha value if you don't want OpenGL to get it. Eg;
Color c;
glColor3f(c.r, c.g, c.r);
...or...
glColor4f(c.r, c.g, c.r, c.a);
Color c;
glColor3f(c.r, c.g, c.r);
...or...
glColor4f(c.r, c.g, c.r, c.a);
If your original data is 8 bit RGBA, you can use
glColor4ubv((GLubyte *)&color);
where color is unsigned int
There is plenty of other functions like glColor3f, glColor3fv, glColor4f, glColor4fv, ... if you want to try those.
[Edited by - V-man on May 8, 2008 7:17:41 AM]
glColor4ubv((GLubyte *)&color);
where color is unsigned int
There is plenty of other functions like glColor3f, glColor3fv, glColor4f, glColor4fv, ... if you want to try those.
[Edited by - V-man on May 8, 2008 7:17:41 AM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement