Noob to opengl colors
i am learning opengl and i was wondering how you know what color you will get
when you call the gl color.
ex
glColor3f(?, ?, ?);
if the ? are 2.0, 4.0, and 1.0 respectively how do i know what colors
i will get?
If I'm not much mistaken, the parameters are red, green and blue, respectively, with values ranging from 0.0 to 1.0.
For example, red would be glColor3f(1.0, 0.0, 0.0);, and cyan glColor3f(0.0, 1.0, 1.0);.
(Blue-book reference.)
[edit] I think that the values that you specified will give you white, since each parameter is greater than or equal to 1.0.
Oh, and if you want an idea of what colour you'll get, try opening up a drawing program, opening its colour selection dialogue (presuming that that dialogue allows for custom colours, and not just a pre-defined set), and setting the colour values according to your desired values, and converting to the program's range.
For example, if you want to find out what (1.0, 0.5, 0.5) should produce, and your drawing program takes red, green and blue values ranging from 0 to 255, set the drawing program's colour to 255, 128, 128 - i.e., 1.0*255, 0.5*255, 0.5*255.
For example, red would be glColor3f(1.0, 0.0, 0.0);, and cyan glColor3f(0.0, 1.0, 1.0);.
(Blue-book reference.)
[edit] I think that the values that you specified will give you white, since each parameter is greater than or equal to 1.0.
Oh, and if you want an idea of what colour you'll get, try opening up a drawing program, opening its colour selection dialogue (presuming that that dialogue allows for custom colours, and not just a pre-defined set), and setting the colour values according to your desired values, and converting to the program's range.
For example, if you want to find out what (1.0, 0.5, 0.5) should produce, and your drawing program takes red, green and blue values ranging from 0 to 255, set the drawing program's colour to 255, 128, 128 - i.e., 1.0*255, 0.5*255, 0.5*255.
For byte colors (aka 0-255), you can also use glColor3b which might be cleaner if your values are in the 0-255 range and will directly match up to the values you may see in a common paint editor.
But just to verify what the others have said, glColor3f takes values in the 0-1 range.
But just to verify what the others have said, glColor3f takes values in the 0-1 range.
Quote:Original post by Khaos Dragon
For byte colors (aka 0-255), you can also use glColor3b which might be cleaner if your values are in the 0-255 range and will directly match up to the values you may see in a common paint editor.
But just to verify what the others have said, glColor3f takes values in the 0-1 range.
I don't know what glColor3b does.
It is better to use glColor3ub or glColor4ub.
One trick is to do this :
uint colorvalue=0xFF55CCBBB;
glColor4ubv((ubyte)&colorvalue);
Quote:Original post by V-manQuote:Original post by Khaos Dragon
For byte colors (aka 0-255), you can also use glColor3b which might be cleaner if your values are in the 0-255 range and will directly match up to the values you may see in a common paint editor.
But just to verify what the others have said, glColor3f takes values in the 0-1 range.
I don't know what glColor3b does.
It is better to use glColor3ub or glColor4ub.
One trick is to do this :
uint colorvalue=0xFF55CCBBB;
glColor4ubv((ubyte)&colorvalue);
That is a cool trick, but I would guess that glColor3ub is probably better form.
glColor3f or glColor4f is the natural color format or OpenGL so all the others first have to convert the bytes/integers to floats first and thus are a bit slower.
Note that you are free to provide any valid number of the given type to the glColor function. However, before the color is drawn to the color buffer, it is clamped to [0;1], so values bigger than 1.0 (float) or 255 (integer) will result in 1.0 or 255 when the color is written. You might however use a color value that is outside that range for color operations like multiplication or addition.
Note that you are free to provide any valid number of the given type to the glColor function. However, before the color is drawn to the color buffer, it is clamped to [0;1], so values bigger than 1.0 (float) or 255 (integer) will result in 1.0 or 255 when the color is written. You might however use a color value that is outside that range for color operations like multiplication or addition.
Quote:Original post by Lord_Evil
glColor3f or glColor4f is the natural color format or OpenGL so all the others first have to convert the bytes/integers to floats first and thus are a bit slower.
Note that you are free to provide any valid number of the given type to the glColor function. However, before the color is drawn to the color buffer, it is clamped to [0;1], so values bigger than 1.0 (float) or 255 (integer) will result in 1.0 or 255 when the color is written. You might however use a color value that is outside that range for color operations like multiplication or addition.
For me, glColorPointer(4, GL_UNSIGNED_BYTE, ..., ....)
has always been fast with VBOs.
If you try glColorPointer(3, GL_UNSIGNED_BYTE, ..., ....), the driver starts to stall.
I don't know about GL_FLOAT.
Well, I'd say that with glColorPointer3 the driver has to fill in the alpha component for every vertex and thus cannot just read the array.
0.0 - 1.0 are used because they are color depth independent. 1.0 will always be the whitest white, but 255,255,255 won't.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement