我正在尝试在 OpenGL 中创建 5x5 棋盘。我已经能够设计 5x6 和 8x8,但代码不适用于 5x5。有人可以查看代码并指出我的错误在哪里,因为宽度不会更改为 5?
这是我似乎有问题的代码部分:
void drawScene()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(-2.5*1.5, 0.0, 2.5*1.5);
for(double j=0.0;j>(-5*1.5);j-=1.5)
{
k++;
for(i=0.0;i<(2.5*3.0);i+=3.0)
{
if(k%2!=0)
{
glPushMatrix();
glTranslatef(i,0.0,j);
glCallList(_displayListId_blackArea);
glPopMatrix();
}
else
{
glPushMatrix();
glTranslatef(i+1.5,0.0,j);
glCallList(_displayListId_blackArea);
glPopMatrix();
}
}
}
for(double j=0.0;j>(-5*1.5);j-=1.5)
{
k++;
for(i=0.0;i<(2.5*3.0);i+=3.0)
{
if(k%2!=0)
{
glPushMatrix();
glTranslatef(i,0.0,j);
glCallList(_displayListId_whiteArea);
glPopMatrix();
}
else
{
glPushMatrix();
glTranslatef(i+1.5,0.0,j);
glCallList(_displayListId_whiteArea);
glPopMatrix();
}
}
}
}