在 opengl 中使用 glBegin() 和 glEnd() 时,您可以设置和更改每个 glVertex3f() 之间的颜色。使用顶点数组和 glDrawArrays() 时如何重新创建此行为。这是常规的opengl。
for(angle = 0.0f; angle < (2.0f*GL_PI); angle += (GL_PI/8.0f))
{
// Calculate x and y position of the next vertex
x = 50.0f*sin(angle);
y = 50.0f*cos(angle);
// Alternate color between red and green
if((iPivot %2) == 0)
glColor3f(0.0f, 1.0f, 0.0f);
else
glColor3f(1.0f, 0.0f, 0.0f);
// Increment pivot to change color next time
iPivot++;
// Specify the next vertex for the triangle fan
glVertex2f(x, y);
}