【发布时间】:2011-03-09 18:48:07
【问题描述】:
我正在渲染这样的对象:
for (int i = 0; i < COLOR_ARRAY_SIZE; i += 4) {
colors[i] = 1.0f;
colors[i + 1] = 0.0f;
colors[i + 2] = 0.0f;
colors[i + 3] = 1.0f;
}
// Clear color and depth buffer
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Set GL11 flags:
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glEnable(GL_DEPTH_TEST);
// make sure nothing messes with the colour
glDisable(GL_BLEND);
glDisable(GL_DITHER);
glDisable(GL_FOG);
glDisable(GL_LIGHTING);
glDisable(GL_TEXTURE_2D);
glShadeModel(GL_FLAT);
// Load projection matrix:
glMatrixMode(GL_PROJECTION);
glLoadMatrixf(projectionMatrix);
// Load model view matrix and scale appropriately
int kObjectScale = 300f;
glMatrixMode(GL_MODELVIEW);
glLoadMatrixf(modelViewMatrix);
glTranslatef(0.5f, 0.5f, 0.5f);
glScalef(kObjectScale, kObjectScale, kObjectScale);
// Draw object
glVertexPointer(3, GL_FLOAT, 0, (const GLvoid*) &vertexPositions[0]);
glNormalPointer(GL_FLOAT, 0, (const GLvoid*) &vertexNormals[0]);
glColorPointer(4, GL_FLOAT, 0, (const GLvoid*) &colors[0]);
glDrawElements(GL_TRIANGLES, 11733, GL_UNSIGNED_SHORT,
(const GLvoid*) &indices[0]);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
我希望这会将我的对象全部呈现为红色,但它是不同颜色的彩虹。有谁知道为什么?我会假设我的“颜色”数组缓冲区有问题,但我一辈子都看不到它是什么。实际的顶点似乎渲染得很好。
【问题讨论】: