我已经尝试了无数次来尝试让它发挥作用。我已经移动了很多东西,但仍然没有任何效果。当我按下 M 键时,我的灯会变成随机颜色。但是,它们仅变为白色。
这就是我所拥有的...
浮动颜色数组[100][3];// 为随机颜色创建一个数组
按键功能:
case 'm' | 'M':
updateLights(2);
break;
defined_to_openGL 函数:
for (int i = 0; i < 3; i++)
{
glPushMatrix();
glColor3f(colorArray[i][0],colorArray[i][1],colorArray[i][2]);
glTranslatef(-50*i/2,-20,0.5); // Begin the first circle at -50, -20. Then multiply by i to create a space between them.
drawLights(2.0f);
glPopMatrix();
if(i <= 3)
{
glPushMatrix();
glColor3f(colorArray[i][0],colorArray[i][1],colorArray[i][2]);
glTranslatef(-38,-20,0.5);
drawLights(2.0f);
glPopMatrix();
glPushMatrix();
glColor3f(colorArray[i][0],colorArray[i][1],colorArray[i][2]);
glTranslatef(-12,-20,0.5);
drawLights(2.0f);
glPopMatrix();
}
}
更新灯功能:
{
cout << "update lights" << endl;
for(int i = 0; i < 3; i++)
{
colorArray[i][0] = rand() % 255;
colorArray[i][1] = rand() % 255;
colorArray[i][2] = rand() % 255;
glutPostRedisplay();
}
}