2012-08-29 34 views
0

我在linux mint上使用Qt Creator,我嘗試運行一個opengl程序。 建築物沒有提供任何錯誤,但是當我嘗試在Qt Creator中運行程序時,會出現一個終端窗口,而且沒有其他事情發生。當我直接在終端上運行的程序得到以下輸出:OpenGL程序無法在Qt Creator中啓動

OpenGL version supported by this platform (3.3.0 NVIDIA 295.40): 
OpenGL 3.3.0 NVIDIA 295.40, GLSL 3.30 NVIDIA via Cg compiler 
Ready for OpenGL 2.0 
Segmentation fault (core dumped) 

我的代碼:

#include <stdio.h> 
#include <GL/glew.h> 
#include <GL/gl.h> 
#include <GL/glu.h> 
#include <GL/glut.h> 
#include <GL/glext.h> 

int main(int argc, char **argv) { 

    glutInit(&argc, argv); 
    glutInitWindowSize(600, 600); 
    glutInitWindowPosition(100, 100); 
    glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH); 
    glutCreateWindow("Aquarium"); 
    glutDisplayFunc(onDisplay); 
    glutMouseFunc(onMouse); 
    glutIdleFunc(onIdle); 
    glutKeyboardFunc(onKeyboard); 
    glutReshapeFunc(onReshape); 

    printf("OpenGL version supported by this platform (%s): \n", glGetString(GL_VERSION)); 

    printf("OpenGL %s, GLSL %s\n",glGetString(GL_VERSION),glGetString(GL_SHADING_LANGUAGE_VERSION)); 

    glewInit(); 

    if (glewIsSupported("GL_VERSION_2_0")) 
     printf("Ready for OpenGL 2.0\n"); 
    else { 
     printf("OpenGL 2.0 not supported\n"); 
     exit(1); 
    } 

    onInitialization(); 

    glutMainLoop(); 

    return 0; 
} 

我已經定義了事件處理程序,和我有onInitialization()方法太。 如果我嘗試在onInitialization()方法的開始處打印某些內容,則除了我之前編寫的行之外,該程序不會寫入任何其他內容。所以它不會進入 onInitialization()我認爲。我甚至無法在Qt Creator中調試此程序。什麼會導致這種情況?什麼原因導致我無法在Qt Creator中啓動程序?我有一個.pro文件:

QT  -= gui core 

TARGET = main 
CONFIG += console 

TEMPLATE = app 

LIBS += /usr/lib/libglut.so /usr/lib/compiz/libopengl.so /usr/lib/i386-linux-gnu/libGLU.so /usr/lib/i386-linux-gnu/libGLEW.so 

QMAKE_CXXFLAGS += -W -Wall -Wextra -pedantic 

SOURCES += main.cpp 

用同樣的設置我已經能夠在Windows上運行的程序(當然LIBS是不同的存在)。

的onInitialization():

void onInitialization() { 

    printf("onInitialization"); 

    soft.controlpoints.push_back(Point(5., 5., 5.)); 
    soft.speeds.push_back(Point(0., 0., 0.)); 
    soft.controlpoints.push_back(Point(5, -5., 5.)); 
    soft.speeds.push_back(Point(0., 0., 0.)); 
    soft.controlpoints.push_back(Point(5., -5., -5.)); 
    soft.speeds.push_back(Point(0., 0., 0.)); 

    soft2.controlpoints.push_back(Point(5., 5., 5.)); 
    soft2.speeds.push_back(Point(0., 0., 0.)); 
    soft2.controlpoints.push_back(Point(5, -5., 5.)); 
    soft2.speeds.push_back(Point(0., 0., 0.)); 
    soft2.controlpoints.push_back(Point(5., -5., -5.)); 
    soft2.speeds.push_back(Point(0., 0., 0.)); 
    soft2.controlpoints.push_back(Point(-5., 5., -5.)); 
    soft2.speeds.push_back(Point(0., 0., 0.)); 

    soft.set_r(); 
    soft2.set_r(); 

    aquarium.objects.push_back(&water); 
    aquarium.objects.push_back(&fish); 
    aquarium.objects.push_back(&field); 
    aquarium.objects.push_back(&soft2); 

    aquarium.createMaterials(); 

    aquarium.createVoxelArray(); 

    glEnable(GL_DEPTH_TEST); 
    lastMovingTime = 0.; 

    setShadowMapShaders(); 
    setAquariumShaders(); 

}

它不打印連 「onInitialization」 字符串。該方法中的對象是全局變量,並且實現了在此調用的所有方法。什麼會導致它不打印「onInitialization」字符串? soft.controlpoints,soft.speeds和aquarium.object是公共領域。即使我評論其他所有內容,字符串也不會出現,但窗口已創建。而且它還沒有從Qt Creator內部運行。

+0

你爲什麼不檢查['glewInit()'](http://glew.sourceforge.net/basic.html)的返回碼? – genpfault

+0

它返回GLEW_OK。 – lyra42

+0

顯然問題出在'onInitialization'函數的某個地方。請發佈那個代碼,以便我們可以幫助你。 – datenwolf

回答

0

事實證明,問題出在文件讀取器方法(即讀入GLSL着色器代碼),這是因爲Qt Creator的工作目錄沒有設置在包含着色器源文件的目錄中。