因此,我代码的一个子集(在翻转循环中)是:
for(int x=0;x<data.length;x++)
for(int y=0;y<data[0].length;y++) {
float r = colorData[x][y][0], g = colorData[x][y][1], b = colorData[x][y][2];
glGetError();
glColor3f(r,g,b);
int xCoord = x*100;
int yCoord = y*100;
int height = (int) Math.round(data[y][x]*25);
glBegin(GL_QUADS);
//Top
glVertex3f(xCoord,yCoord,height);
glVertex3f(xCoord+100,yCoord,height);
glVertex3f(xCoord+100,yCoord+100,height);
glVertex3f(xCoord,yCoord+100,height);
//*/
//Sides
glColor3f(r/2,g/2,b/2);
glVertex3f(xCoord,yCoord,height);
glVertex3f(xCoord,yCoord,0);
glVertex3f(xCoord+100,yCoord,0);
glVertex3f(xCoord+100,yCoord,height);
glVertex3f(xCoord,yCoord+100,height);
glVertex3f(xCoord+100,yCoord+100,height);
glVertex3f(xCoord+100,yCoord+100,0);
glVertex3f(xCoord,yCoord+100,0);
glVertex3f(xCoord,yCoord+100,height);
glVertex3f(xCoord,yCoord+100,0);
glVertex3f(xCoord,yCoord,0);
glVertex3f(xCoord,yCoord,height);
glVertex3f(xCoord+100,yCoord+100,height);
glVertex3f(xCoord+100,yCoord,height);
glVertex3f(xCoord+100,yCoord,0);
glVertex3f(xCoord+100,yCoord+100,0);
//Bottom
glColor3f(r/4,g/4,b/4);
glVertex3f(xCoord,yCoord,0);
glVertex3f(xCoord,yCoord+100,0);
glVertex3f(xCoord+100,yCoord+100,0);
glVertex3f(xCoord+100,yCoord,0);
glEnd();
int err = glGetError();
if(err != GL_NO_ERROR)
System.out.println("An error has occured: #"+err);
glColor3f(1,0,0);
glBegin(GL_LINES);
//Top
glVertex3f(xCoord,yCoord,height);
glVertex3f(xCoord+100,yCoord,height);
glVertex3f(xCoord+100,yCoord+100,height);
glVertex3f(xCoord,yCoord+100,height);
glEnd();
}
代码工作正确, 绘制了两维方格的盒子, 盒子的侧面比顶部暗一点。 (穷人的灯光)
好奇的是,我接到了致glColor3f的第一通电话,希望盒子顶部成为无色的,而两侧保持原样;然而,整个盒子的网格都变白了。为什么会这样呢?这是这个代码中的东西吗?还是我变环中的其他部分导致了这个?
(如果有区别,我正在使用 OpenGL1.1 的 LWJGL s Java 执行)