我想在屏幕上看到球体的运动。 但是,如果您运行代码,则将无法更新屏幕。 如何更改代码以显示我创建的短语位置的变化?
void display() {
glLoadIdentity();
gluLookAt(0, 0, 10, 0, 0, 0, 0, 1, 0);
GLfloat diffuse1[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat ambient1[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat specular1[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat position1[] = { 0, 0, 0, 1.0 };
GLfloat diffuse2[] = { 0.5, 0.5, 0.5, 1 };
GLfloat ambient2[] = { 0.1, 0.1, 0.1, 1 };
GLfloat specular2[] = { 0.5, 0.5, 0.5, 1 };
GLfloat emission2[] = { 0, 0, 0, 1 };
GLfloat shine = 300;
glLightfv(GL_LIGHT0, GL_POSITION, position);
glLightfv(GL_LIGHT0, GL_AMBIENT, ambient1);
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse1);
glLightfv(GL_LIGHT0, GL_SPECULAR, specular1);
glPushMatrix();
glMaterialfv(GL_FRONT, GL_AMBIENT, ambient2);
glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse2);
glMaterialfv(GL_FRONT, GL_SPECULAR, specular2);
glMaterialfv(GL_FRONT, GL_EMISSION, emission2);
glMaterialf(GL_FRONT, GL_SHININESS, shine);
glRotatef(mer_revolution, 0, 0, 1);
glTranslatef(0, 0.8, 0);
glRotatef(mer_rotate, 0, 0, 1);
glutSolidSphere(1, 300, 300);
glPopMatrix();
glFlush();
}
void main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(800,600);
glutCreateWindow("");
glClearColor(0, 0, 0, 0);
glColor3f(1.0, 1.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glMatrixMode(GL_MODELVIEW);
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutIdleFunc(move);
glutMainLoop();
}
答案 0 :(得分:2)
移动'gL_COLOR_BUFFER_BIT |显示屏顶部的GL_DEPTH_BUFFER_BIT”。 执行功能时必须初始化屏幕。只有这样,屏幕才能继续更改。