OpenGL GL_QUAD_STRIP正在使用glColor3f()淡出(OpenGL GL_QUAD_STRIP is fading with glColor3f())

我用glColor3f()和GL_QUAD_STRIP绘制了彼此相邻的2个正方形,但看起来它们正在淡化2个正方形之间的颜色,有什么方法可以防止这种情况吗? 或者GL_QUAD_STRIP根本就不适合这种事情? 更合适的将是GL_QUADS,但这太容易了。

glBegin(GL_QUAD_STRIP); glColor3f(1.0f, 1.0f, 1.0f); glVertex3f(0.0f, 0.0f, 0.0f); glVertex3f(0.0f, 1.0f, 0.0f); glVertex3f(1.0f, 0.0f, 0.0f); glVertex3f(1.0f, 1.0f, 0.0f); glColor3f(0.0f, 0.0f, 0.0f); glVertex3f(2.0f, 0.0f, 0.0f); glVertex3f(2.0f, 1.0f, 0.0f); glColor3f(1.0f, 1.0f, 1.0f); glEnd();

I'm drawing 2 squares next to each other with glColor3f() and GL_QUAD_STRIP, but it seems that they are fading the colors between the 2 squares, is there any way to prevent this? Or is GL_QUAD_STRIP simply not meant for this kind of thing? More appropriate would be GL_QUADS, but that makes it too easy.

glBegin(GL_QUAD_STRIP); glColor3f(1.0f, 1.0f, 1.0f); glVertex3f(0.0f, 0.0f, 0.0f); glVertex3f(0.0f, 1.0f, 0.0f); glVertex3f(1.0f, 0.0f, 0.0f); glVertex3f(1.0f, 1.0f, 0.0f); glColor3f(0.0f, 0.0f, 0.0f); glVertex3f(2.0f, 0.0f, 0.0f); glVertex3f(2.0f, 1.0f, 0.0f); glColor3f(1.0f, 1.0f, 1.0f); glEnd();

最满意答案

通常,颜色附着到每个顶点,而不是每个四边形。 因此,由于2条四边形条带之间共享2个顶点,因此您可以使用两种颜色(以及您观察的“渐变”,这称为插值)。

现在,在您的特定情况下,存在一个有助于的OpenGL模式:您可以告诉OpenGL根本不插入颜色,并且只获取完整图元的每个图元(此处为四边形)的最后一个顶点的颜色。

这是通过以下状态完成的 :

glShadeModel(GL_FLAT);

In general, the colors are attached to each vertex, not each quad. So since 2 vertices are shared between the 2 quads of your strip, you get the color used for both (and the "fading" you're observing. It's called interpolation).

Now, in your particular case, there exists however an OpenGL mode that helps: You can tell OpenGL to not interpolate the colors at all, and only get the color of the last vertex of each primitive (here quads) for the full primitive.

This is done with the following state:

glShadeModel(GL_FLAT);

更多推荐