Hi, I want to design a function so if the user press "c" at any time during my program, this function will display random color on the object from green, yellow, blue and red. How do I do it? thanks in advance.
Hi, I want to design a function so if the user press "c" at any time during my program, this function will display random color on the object from green, yellow, blue and red. How do I do it? thanks in advance.
'The bigger they are, the harder they fall' ~Yang
Okay, so you want to change the red green and blue color components. You've got to generate a floating point between 0 and 1 if you're using glColor3f, which I have to assume that you are because you did not tell me otherwise.
if(GetKeyState('C') & 0x80)
{
red = (float)rand() / (float)RAND_MAX;
green = (float)rand() / (float)RAND_MAX;
blue = (float)rand() / (float)RAND_MAX;
}
rand() produces a maximum value of rand_max, which is why rand()/ rand_max must produce a float between 0 and 1
make sure that you call:
srand(GetTickCount());
at the start of the program. this 'initializes' the random number generator. include windows.h to get it to work.