i have the following Problem. Through the function below i can create squares. Now i would like to give each square a different color. Is this possible? If not would it be possible to color each row in a different way?
Would be very glad if anyone could help me.
Here is my source code:
void QuadratColor(float length,int quant)
Assuming you are not using lighting, OpenGL uses the current colour when drawing. This is set using the glColor* set of commands (e.g. glColor3f(1.0, 0.0, 0.0); sets red). If you set the colour before executing the display list, it will be used by the drawing commands inside the display list.
Thx for the answer. But unfortunately that is not my problem. If i do it the way you describe it, thann all my square would be red.
But I would like to know if i can do it in a way that the first square is e.g red the second blue the third cyan and so on.
Or is it possible to allocate a random color?
in the loop
Mazy: pushing the current matrix will not save the color information. you need this:
glColor3f(<your color> );
there are many other attributes you can pass, including all of them (GL_CURRENT_BIT i think)
Bart: you can set the color to whatever you want. for random colors, make a MACRO that selects a number at random from 0-255, then pass 3 of those MACROS to glColor3ub(); good luck, and don’t have a cow, man!
Sorry, but could you please explain your code for me a little bit more?
In which loop shall i put the Lines? In the first or the second.
And do i understand it right that through the glColor i can choose the different colors i want to use and through glDrawList they are somwhow randomized?
Would be very nice of you if you can explain it to me.