为什么显示功能被调用两次?

时间:2014-08-23 11:35:43

标签: c opengl graphics

在下面的OpenGL代码中,用于初始化和主函数,为什么显示函数被调用两次?我看不到除glutDisplayFunc(display);

之外的其他电话
void init(void)
{
   glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Set background color to black and opaque
   glClearDepth(1.0f);                   // Set background depth to farthest
   glEnable(GL_DEPTH_TEST);   // Enable depth testing for z-culling
   glEnable(GL_POINT_SMOOTH);
   glDepthFunc(GL_LEQUAL);    // Set the type of depth-test
   glShadeModel(GL_SMOOTH);   // Enable smooth shading
   gluLookAt(0.0, 0.0, -5.0,  /* eye is at (0,0,5) */
             0.0, 0.0, 0.0,      /* center is at (0,0,0) */
             0.0, 1.0, 0.0);      /* up is in positive Y direction */

   glOrtho(-5,5,-5,5,12,15); 
  //glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);  // Nice perspective corrections

}

int
main(int argc, char **argv)
{
  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
  glutCreateWindow("red 3D lighted cube");
  glutInitWindowSize(1280,800 );   // Set the window's initial width & height
  //glutInitWindowPosition(50, 50); // Position the window's initial top-left corner    
  //glutReshapeWindow(800,800);
  init();
  compute();
  glutDisplayFunc(display);

  glutMainLoop();
  return 0;             /* ANSI C requires main to return int. */
}

1 个答案:

答案 0 :(得分:6)

只要GLUT决定要求应用程序(那是你)重绘窗口内容,就会调用display()回调。

当窗口打开时,可能会发生一些事件,导致需要确保重绘窗口。

你不应该“关心”;只需确保重新绘制display()函数中的内容,不要在意它被调用的次数。

相关问题