Jump to content
  • Advertisement
Sign in to follow this  
ajm113

OpenGL Question about RGB with OpenGL

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

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

Share this post


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

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites
Well I don't think it's RGBA I am working with, sorry I guest just RGB with out the 1.0, but use something like 225, 225, 225 instead so I know what I am putting in because of the color examples online.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!