How to creat Gradients in 2D primitives in GLUT

can anyone tell me how to create Gradients in openGL primitives in GLUT?

Just a sample:

Enable Blend
Define Blend funcion
Begin draw primive
Set color with alpha
Draw bottom vertexs
Set new alpha
Draw remind vertexs
End draw

glEnable (GL_BLEND);

glBegin (GL_QUADS);
glColor4f (0.0, 1.0, 0.0, 0.0);
glVertex3f (0.0, 0.0, 0.0);
glVertex3f (0.5, 0.0, 0.0);
glColor4f (0.0, 1.0, 0.0, 1.0);
glVertex3f (0.5, 0.5, 0.0);
glVertex3f (0.0, 0.5, 0.0);
glEnd ();

Originally posted by onlyhuman23:
can anyone tell me how to create Gradients in openGL primitives in GLUT?

If you are talking about color-gradients (like a fade from dark blue to white, or from red to yellow), the quickest way is to enable GL_SMOOTH shading (glShadeModel( GL_SMOOTH) ) and draw the corners of your primitives in the right color (one side col1, opposite side col2).

A more advanced way to do this is to define a 1-dimensional texture that contains the gradient you want to display and use that to texture the primitives that need the gradient. This allows you to let the gradient fade across different colors (like a rainbow).
This latter method works best when combined with texture coordinate generation, but supplying your own texture coordinates can produce quite good results too depending on the geometry you use and the required direction of the gradiens (i.e. if they are aligned with the primitives or not).

(as an aside: GLUT doesn’t help you creating gradients, once you have a working window to draw onto, it’s just OpenGL)