我试图在OpenGL中绘制这个颜色贴图
使用QUADS时,结果看起来很好:
int colorArr[] = { 255, 224, 192, 160, 128, 96, 64, 32 };
gluOrtho2D(-2, 2, -2, 2);
glPolygonMode(GL_FRONT, GL_FILL);
glDisable(GL_COLOR_LOGIC_OP);
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_QUADS);
for (int i = 0; i < 8; i++) {
glColor3ub(colorArr[7 - i], 0, 0);
glVertex2f(-4, i - 4);
glVertex2f(4, i - 4);
glVertex2f(4, i - 4 + 1);
glVertex2f(-4, i - 4 + 1);
}
glEnd();
glEnable(GL_COLOR_LOGIC_OP);
glLogicOp(GL_OR);
glBegin(GL_QUADS);
for (int i = 0; i < 8; i++) {
glColor3ub(0, colorArr[i], 0);
glVertex2f(i - 4, 4);
glVertex2f(i - 4, -4);
glVertex2f(i - 4 + 1, -4);
glVertex2f(i - 4 + 1, 4);
}
glEnd();
glFlush();
但如果我使用QUAD_STRIPS绘制多边形,颜色之间的颜色会变得平滑:
int colorArr[] = { 255, 224, 192, 160, 128, 96, 64, 32 };
gluOrtho2D(-2, 2, -2, 2);
glPolygonMode(GL_FRONT, GL_FILL);
glDisable(GL_COLOR_LOGIC_OP);
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_QUAD_STRIP);
for (int i = 0; i < 8; i++) {
glColor3ub(colorArr[7 - i], 0, 0);
glVertex2f(-4, i - 4);
glVertex2f(4, i - 4);
}
glVertex2f(-4, 4);
glVertex2f(4, 4);
glEnd();
glEnable(GL_COLOR_LOGIC_OP);
glLogicOp(GL_OR);
glBegin(GL_QUAD_STRIP);
for (int i = 0; i < 8; i++) {
glColor3ub(0, colorArr[i], 0);
glVertex2f(i - 4, 4);
glVertex2f(i - 4, -4);
}
glVertex2f(4, 4);
glVertex2f(4, -4);
glEnd();
glFlush();
你知道为什么会这样吗?
答案 0 :(得分:0)
您正在绘制的Quad条带与此相当:
glBegin(GL_QUADS);
for (int i = 0; i < 7; i++) {
glColor3ub(colorArr[7 - i], 0, 0);
glVertex2f(-4, i - 4);
glVertex2f(4, i - 4);
glColor3ub(colorArr[7 - i+1], 0, 0);
glVertex2f(4, i - 4 + 1);
glVertex2f(-4, i - 4 + 1);
}
您每2个顶点都会更改颜色,颜色会作为属性插入下一个/上一个点。