OpenGL窗口立即关闭,错误-1073740777(0xc0000417)

时间:2016-07-07 14:39:54

标签: c++ visual-studio opengl

我正在使用Visual Studio 2013和OpenGL来创建模拟。 理想情况下,我正在创建的窗口应保持打开状态,以便我可以使用键进行更改,并且可以在同一窗口中查看不同的结果。 但是窗口在启动后立即关闭,错误代码为

  

program.exe'已退出,代码为-1073740777(0xc0000417)

我做了一些调试并尝试对各行进行评论,并看到如果我将'glutSwapBuffers()'作为注释,则窗口保持打开但是为空。

有人可以对此有所了解吗?

void keyboard (unsigned char key, int x, int y)
{
 switch (key)
 {
    case 'r': case 'R':
    if (filling==0)
    {
        glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); 
        filling=1;
    }
    else
    {
        glPolygonMode (GL_FRONT_AND_BACK, GL_POINT); 
        filling=0;
    }
    break;
    case 27:
    exit(0);
    break;
 }
}

void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
glMatrixMode(GL_MODELVIEW); 
glLoadIdentity(); 
glRotatef(-90,0.0,1.0,0.0); 
glRotatef(-90,1.0,0.0,0.0); 

rotation_x = rotation_x + (rotation_x_increment - rotation_x)/50;
rotation_y = rotation_y + (rotation_y_increment - rotation_y)/50;
rotation_z = rotation_z + rotation_z_increment;

if (rotation_x > 359) rotation_x = 0;
if (rotation_y > 359) rotation_y = 0;
if (rotation_z > 359) rotation_z = 0;

if(rotation_x_increment > 359) rotation_x_increment = 0;
if(rotation_y_increment > 359) rotation_y_increment = 0;
if(rotation_z_increment > 359) rotation_z_increment = 0;

glRotatef(rotation_x,1.0,0.0,0.0); 
glRotatef(rotation_y,0.0,1.0,0.0);
glRotatef(rotation_z,0.0,0.0,1.0);

glTranslatef(x_translate,0.0,0.0);
glTranslatef(0.0,y_translate,0.0);
glTranslatef(0,0,z_translate); 

glFlush(); // This force the execution of OpenGL commands
glutSwapBuffers(); 
glFinish();
}

int main(int argc, char **argv)
{
IntroDisplay();
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(screen_width,screen_height);
glutInitWindowPosition(0,0);
glutCreateWindow("Ultrasonic Testing");
glutDisplayFunc(display);
glutIdleFunc(display);
glutReshapeFunc (resize);
glutKeyboardFunc (keyboard);
glutSpecialFunc (keyboard_s);
glutMouseFunc(mouse);
glutMotionFunc(mouseMove);
init();
glutMainLoop();
return 0;
}

2 个答案:

答案 0 :(得分:0)

你有没有尝试编译和运行一个绝对最小的裸骨程序,除了用GLUT创建一个窗口,注册一个只清除和交换缓冲区的显示功能之外什么都不做。即此

#include <GL/glut.h>
static void display(void)
{
    glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
    glutSwapBuffers();
}
int main(int argc, char *argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
    glutCreateWindow("test");
    glutDisplayFunc(display);
    glutIdleFunc(glutPostRedisplay);
    glutMainLoop();
    return 0;
}

我对您遇到麻烦的原因的猜测是,您使用的某些库是使用与您正在使用的编译器不同的编译器构建的,并且预期运行时间的差异会导致您的某些操作。如果上面给出的最小程序崩溃,那么这是最可能的原因。

请注意,在您的代码中,对glFinishglFlush的调用是多余的,因为缓冲交换会隐含刷新和完成。另外,将显示功能注册为GLUT空闲处理程序通常不是一个好主意;如果您需要连续显示更新,请注册glutPostRedisplay。

答案 1 :(得分:0)

这个问题与我的司机有关。重新安装后,一切正常。

我认为这是因为交换功能还取决于系统而不仅仅是库。我在某处读到了。