我有以下绘制球体的 drawScene 函数。X,Y 的坐标一直在更新。据我从 printf 中可以看出,这些值肯定会发生变化。
问题是球体不会根据坐标改变位置,而是总是在同一个地方绘制......
void drawScene(void){
//Clear information from last draw
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW); //Switch to the drawing perspective
glLoadIdentity(); //Reset the drawing perspective
glColor3d(1,0,0);
//glPushMatrix();///
glTranslated(X,Y,-7);//xyz//(X%5)-2.5,Y%5//(((X%6)-3),0,-7)
printf("\n\n\nCOORDS(X)%d (Y):%d\n\n\n\n",X,Y);
glutSolidSphere(0.3, 25, 20);//3,20,20
//glPopMatrix();///
glutSwapBuffers(); //Send the 3D scene to the screen
}
PS。我不确定这是否正确,但每次我想要更新我的 openGL 窗口时,我都会调用 drawScene() 或者它只绘制一次。