Question about RGB with OpenGL

Started by
3 comments, last by ajm113 15 years, 11 months ago
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
Check out my open source code projects/libraries! My Homepage You may learn something.
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?
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);
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]
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
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.
Check out my open source code projects/libraries! My Homepage You may learn something.

This topic is closed to new replies.

Advertisement