2016-07-07 403 views
0

我正在使用Visual Studio 2013和OpenGL創建一個模擬。 理想情況下,我創建的窗口應保持打開狀態,以便可以使用鍵進行更改,並且可以在同一窗口中查看不同的結果。 但窗口是錯誤代碼啓動後立即關閉OpenGL窗口立即關閉,並顯示錯誤-1073740777(0xc0000417)

的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; 
} 
+0

STATUS_INVALID_CRUNTIME_PARAMETER - 可能是混合的crts或類似的東西,重建所有來源 – paulm

+0

@paulm嘗試重建。嘗試清潔和重建。仍然沒有變化。 它可能是與Windows或glut32.dll相關的東西?因爲我一段時間沒有更改代碼,並且突然開始這樣做。 –

+0

包括過剩? – paulm

回答

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; 
} 

我在你的故障原因的猜測是,您使用的是一些庫是在不同的編譯器比您正在使用,並在運行時預期的差異導致一些hickups爲你修造了。如果上面給出的最小程序崩潰,那麼這是最可能的原因。

請注意,在您的代碼中,對glFinishglFlush的調用是多餘的,因爲沖洗和完成是由緩衝區交換隱含的。另外,將顯示功能註冊爲GLUT閒置處理程序通常不是一個好主意;如果您需要連續顯示更新,請註冊glutPostRedisplay。

+0

我試過最簡單的程序,它也崩潰了。你建議我如何解決運行時錯誤? –

+0

@RahulK:既然你提到glutSwapBuffers被調用時出現問題,你的GLUT的特定版本似乎是罪魁禍首。你最好採取的行動是爲FreeGLUT提供源代碼(http://prdownloads.sourceforge.net/freeglut/freeglut-3.0.0.tar.gz?download),並用你自己的編譯器自己構建它。實際上,將FreeGLUT放入您的項目並將其作爲解決方案添加到您的VisualStudio項目中會很有意義,因此它將與您的主程序一起構建。 – datenwolf

+0

我弄明白了。我重新安裝了整個Visual Studio和所有更新。仍然不確定究竟是什麼問題。非常感謝您的幫助。 :) –