【发布时间】:2012-10-17 08:11:45
【问题描述】:
void init(void)
{
glEnable(GL_DEPTH_TEST);
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
}
void display(void)
{
glClearColor(1.0, 1.0, 1.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glScalef(1.0,1.0,1.0);
glColor3f(0.0,0.0,0.0);
glBegin(GL_POLYGON);
glVertex2f(-0.5, -0.5);
glVertex2f(-0.5, 0.5);
glVertex2f(0.5, 0.5);
glVertex2f(0.5, -0.5);
glEnd();
glutSwapBuffers();
}
void reshape(int w, int h)
{
int height = h;
int width = w;
glViewport(0, 0, (GLsizei)w, (GLsizei)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60, (GLfloat)w / (GLfloat)h, 1.0, 100.0);
glMatrixMode(GL_MODELVIEW);
}
int main(int argc, char* argv[])
{
Complex c(0,0);
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
glutInitWindowSize(512, 512);
glutInitWindowPosition(100, 100);
winID = glutCreateWindow("Fractal");
init();
glutDisplayFunc(display);
glutIdleFunc(display);
glutReshapeFunc(reshape);
// Compute the update rate here...
glutMainLoop();
return 0;
}
如果我将代码放在 display() 中,我会得到一个正方形,除了 if 条件中的 glutSwapBuffers() 检查代码是否第一次进入显示。如果我删除 if,我会得到一个白色窗口
【问题讨论】:
-
问题措辞不当。你有什么问题?
-
// Compute the update rate here…不,它没有。在运行程序的过程中,该特定代码行恰好到达一次。如果那里有一个非终止循环,您将无法到达 GLUT 主循环,从而阻止事件被处理。此外,如果您想要持续更新,您应该将glutPostRedisplay注册为空闲函数,而不是display。
标签: opengl