# How to make colour to a quad other than RGB.

## Recommended Posts

Dathu    122
Hi all, I have render one quad by using glBegin()and glEnd(),In that I have taken four vertexes.Before glBegin()I wrote the function glColor3d(),to make the quad colour.Here my question is,I want to make that quad colour other than Red,Green,Blue. can anyone help .....

##### Share on other sites
BionicBytes    154
What do you mean by 'other than RGB'? OpenGL works using the RGB color space.
If you are talking about Hue-Sat and Luminance then you just need to write your own conversion matrix to convert that format into RGB before using the glColorX command.
In short - OGL only works in RGB (and newer extensions allow sRGB) anything else requires your own code to conversion code.

##### Share on other sites
Dathu    122
I am using mfc appwizard dialog in that I have created the opengl window.In that opengl window I render one quad and to fill colour for that quad I used glcolor3d() function.Now question is I want to fill that quad with other than Red,Green,Blue.For this If I made any changes (i.e.values)in glcolor3d function the quad is not changing other than Red,Gree,Blue,Black,White.But I want to fill other than these colours. HOW?

Thanks.

##### Share on other sites
Porthos    210
You must mix the color channels. E.g.

red = 100
green = 100
blue = 100

is a dark gray.

Best regards,
Porthos

##### Share on other sites
Decrius    100
red = 1.0
green = 0.0
blue = 1.0

Makes purple. It's fairly easy, in Paint you can get the colour values (in range from 0 - 255). So what you have to do, is pick the number and divide it by 256. Then fill the red, green and blue values into glColor3f().

##### Share on other sites
BionicBytes    154
For openGL the RGB values are float values between 0.0 and 1.0. These values are clamped. Typical paint programs display RGB values in the range of 0...255. So conversion is easy - just divide the each RGB component by 255 and use that result in the glColor3f () command.

##### Share on other sites
Decrius    100
Quote:
 Original post by BionicBytes... just divide the each RGB component by 255 ...

256 ;)

##### Share on other sites
BionicBytes    154
I *could* be wrong but divide by 255. Take the RED component for example. The max value this could have is 255. The Min value is 0. Yep - the range is 256 but
take pure RED - a value of 255. We want this to map to 1.0 - so divide by 255
Pure black in the RED channel is 0 - and when divided by 255 is still 0, so works for that too. If you divide by 256 then pure red is NOT mapping to 1.0

##### Share on other sites
Decrius    100
Quote:
 Original post by BionicBytesI *could* be wrong but divide by 255. Take the RED component for example. The max value this could have is 255. The Min value is 0. Yep - the range is 256 buttake pure RED - a value of 255. We want this to map to 1.0 - so divide by 255Pure black in the RED channel is 0 - and when divided by 255 is still 0, so works for that too. If you divide by 256 then pure red is NOT mapping to 1.0

Hmm yes, but it must be divided by 256 somehow, else it will never be right, will it?

Take 127, considered to be grey. 127 / 255 != 0.5

##### Share on other sites
mystb    186
Quote:
 Original post by BionicBytesI *could* be wrong but divide by 255. Take the RED component for example. The max value this could have is 255. The Min value is 0. Yep - the range is 256 buttake pure RED - a value of 255. We want this to map to 1.0 - so divide by 255Pure black in the RED channel is 0 - and when divided by 255 is still 0, so works for that too. If you divide by 256 then pure red is NOT mapping to 1.0

try to thing on base 10.. you have 0 to 9... and divide by 10.
this is just a sort of "base 256", so divide by 256, and you'll be fine, trust me :)

and to answer your division question... you divide by 256 and the remaining is the number for each color.

##### Share on other sites
V-man    813
Values go from 0 to 255.
So what will happen when you divide by 256?

255.0/256.0 = 0.99609375
which is NOT WHITE.

And if you want to convert 0.0 to 1.0
to the 0 to 255, mult by 255.

##### Share on other sites
aevanthony    100
There is a *range of 256 *values.

The highest *value is 255 because we count 0.

You divide by the highest *value (255) of the *range (256 values) to normalize it.

1 = 0/255
2 = 1/255
3 = 2/255
...
256 = 255/255

If you can't wrap your mind around this now, then have something to drink, bust out a pen and paper, start reading some discrete mathematics books. You'll eventually get it.

##### Share on other sites
lancekt    348
Quote:
 Original post by DecriusHmm yes, but it must be divided by 256 somehow, else it will never be right, will it?Take 127, considered to be grey. 127 / 255 != 0.5

Right, because 127 isn't the center of the range (0,255). 127.5/255 = 0.5

##### Share on other sites
jerm007    198
I think what the op is asking is how to color each vertex individually. You stated that you wrote glColor3d *before* glBegin(). If you call glBegin and then call glColor3d for each vertex, each vertex can have a different color. Example:

glBegin(GL_QUADS)glColor3f(1, 0, 0);glVertex3f(...);glColor3f(0, 1, 0);glVertex3f(...);glColor3f(0, 0, 1);glVertex3f(...);glColor3f(1, 1, 1);glVertex3f(...);glEnd();

This will give you a quad with red, green, blue and white corners, blending together in the middle. HTH

Jeremiah

##### Share on other sites
Split Thumbs    112
Or use glColor3ub

##### Share on other sites
V-man    813
Nah, use glColor4ub or better yet glColor4ubv. The hardware works with 32 bit at a time.

Do this :
uint color=0xFFFFFFFF;glColor4ubv((GLubyte *)&color);

Why on earth is the OP using glColor3d?

## Create an account or sign in to comment

You need to be a member in order to leave a comment

## Create an account

Sign up for a new account in our community. It's easy!

Register a new account