What I want to do is to draw a square where each vertex is supposed to have a different color.
This should lead into a nice gradient within the square.
Here’s the code I’m using:
glBegin(GL_QUADS);
glColor3f(0.0f, 0.0f, 1.0f);
glVertex2f(((float)(winWidth-redLineWidth))/2.f,((float)(winHeight-redLineWidth))/2.f);
glColor3f(0.0f, 0.0f, 0.0f);
glVertex2f(((float)(winWidth+redLineWidth))/2.f,((float)(winHeight-redLineWidth))/2.f);
glColor3f(0.0f, 1.0f, 0.0f);
glVertex2f(((float)(winWidth+redLineWidth))/2.f,((float)(winHeight+redLineWidth))/2.f);
glColor3f(1.0f, 0.0f, 0.0f);
glVertex2f(((float)(winWidth-redLineWidth))/2.f,((float)(winHeight+redLineWidth))/2.f);
glEnd();
Please ignore the variables used.
I get a rectangle painted, but it has a solid color.
Where’s the error here?
I’m using GLUT on Mac OS X.
It seems unlikely that you’ve changed this, but you might try to add a
glShadeModel(GL_SMOOTH)call before your drawing code. The default behavior should do as you expected though, so the problem is likely elsewhere.