How to make colour to a quad other than RGB.

Started by
14 comments, last by V-man 15 years, 12 months ago
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 .....
Advertisement
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.
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.
You must mix the color channels. E.g.

red = 100
green = 100
blue = 100

is a dark gray.

Best regards,
Porthos
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().
[size="2"]SignatureShuffle: [size="2"]Random signature images on fora
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.



Quote:Original post by BionicBytes
... just divide the each RGB component by 255 ...


256 ;)

[size="2"]SignatureShuffle: [size="2"]Random signature images on fora
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

Quote:Original post by BionicBytes
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


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

[size="2"]SignatureShuffle: [size="2"]Random signature images on fora
Quote:Original post by BionicBytes
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


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.

This topic is closed to new replies.

Advertisement