停止使用
GL_POLYGON
.
这个
GL\U多边形
原语类型将转换为一系列三角形,但这种三角剖分的方式将完全取决于实现。在您的例子中,实现可能是获取前3个顶点,并将其生成三角形。由于前3个顶点是共线的,因此形成一个没有面积的三角形,因此不会为它们渲染任何内容。
您需要一个非常特定的三角剖分,所以您可以自己进行三角剖分并使用
GL_TRIANGLES
。例如:
float positions[] =
{
-200, 100, // top-left
-200, 0, // middle-left
-200, -100, // bottom-left
200, -100, // bottom-right
200, 0, // middle-right
200, 100, // top-right
};
//In the same order as `positions`.
enum pos_indices { top_left, middle_left, bottom_left, bottom_right, middle_right, top_right };
void position(pos_indices index)
{
int ix = index * 2;
glVertex2f(positions[ix], positions[ix + 1]);
}
float colors[] =
{
1, 0, 0, // red
0, 1, 0, // green
0, 0, 1, // blue
};
//In the same order as `colors`
enum color_indices { red, green, blue };
void color(color_indices index)
{
int ix = index * 3;
glColor3f(colors[ix], colors[ix + 1], colors[ix + 2]);
}
void drawTest()
{
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glShadeModel(GL_SMOOTH);
glBegin(GL_TRIANGLES);
{
color(red);
position(top_left);
color(green);
position(middle_left);
color(red);
position(top_right);
color(green);
position(middle_left);
color(green);
position(middle_right);
color(red);
position(top_right);
color(green);
position(middle_left);
color(blue);
position(bottom_left);
color(green);
position(middle_right);
color(blue);
position(bottom_left);
color(blue);
position(bottom_right);
color(green);
position(middle_right);
}
glEnd();
}