How to make colour to a quad other than RGB.

Started by
14 comments, last by V-man 16 years ago
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.
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);
Advertisement
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.
Quote:Original post by Decrius
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


Right, because 127 isn't the center of the range (0,255). 127.5/255 = 0.5
Orin Tresnjak | Graphics ProgrammerBethesda Game StudiosStandard Disclaimer: My posts represent my opinions and not those of Bethesda/Zenimax, etc.
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
Power User / Programmer / Game Player ( Not computer nerd :)
Or use glColor3ub
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?
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);

This topic is closed to new replies.

Advertisement