我正在尝试运行一个示例 GLUT 程序,但它只创建一个白色窗口,然后冻结应用程序。我发现它在调用 glutMainLoop 时冻结(如果我在循环中调用 glutCheckLoop 也是如此)。我可能遗漏了什么?
这是我找到的示例代码:
#include <stdlib.h>
#ifdef __APPLE__
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif
// Question 1: In a GLUT program, how is control passed
// back to the programmer? How is this set up during
// initialization?
int win_width = 512;
int win_height = 512;
void display( void )
{
glClear( GL_COLOR_BUFFER_BIT );
glutSwapBuffers();
}
void reshape( int w, int h )
{
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
// Question 3: What do the calls to glOrtho()
// and glViewport() accomplish?
glOrtho( 0., 1., 0., 1., -1., 1. );
glViewport( 0, 0, w, h );
win_width = w;
win_height = h;
glutPostRedisplay();
}
void keyboard( unsigned char key, int x, int y ) {
switch(key) {
case 27: // Escape key
exit(0);
break;
}
}
int main (int argc, char *argv[]) {
glutInit( &argc, argv );
// Question 2: What does the parameter to glutInitDisplayMode()
// specify?
glutInitDisplayMode( GLUT_RGBA | GLUT_DOUBLE );
glutInitWindowSize( win_width, win_height );
glutCreateWindow( "Intro Graphics Assignment 1" );
glutDisplayFunc( display );
glutReshapeFunc( reshape );
glutKeyboardFunc( keyboard );
glutMainLoop();
return 0;
}