Noob to opengl colors

Started by
7 comments, last by Daaark 16 years ago
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?
Advertisement
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.

MWAHAHAHAHAHAHA!!!

My Twitter Account: @EbornIan

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.
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);
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);
Quote:Original post by V-man
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);


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.

If I was helpful, feel free to rate me up ;)If I wasn't and you feel to rate me down, please let me know why!
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.
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'd say that with glColorPointer3 the driver has to fill in the alpha component for every vertex and thus cannot just read the array.
If I was helpful, feel free to rate me up ;)If I wasn't and you feel to rate me down, please let me know why!
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