2017-08-09 181 views
-2

我一直在玩OpenGL和Ubuntu,似乎我遇到了錯誤。OpenGL「分段錯誤」錯誤

我試圖按照其他線程具有完全相同的問題。

簡單地說,我也沒有工作......

這是我的錯誤:

Segmentation fault (core dumped) 

我編譯使用這種 「build.sh」 腳本

g++ -o exec main.cpp -I/usr/include/libdrm -lglfw -I/usr/include/libdrm -lGL -I/usr/include/libdrm -lGLEW -lGLU -lGL 

而且程序這裏是我的「main.cpp」

#include <GL/glew.h> 
#include <GLFW/glfw3.h> 


int main(){ 

    if(!glfwInit()){ 
     //error 
    } 

    glewExperimental = GL_TRUE; 

    glewInit(); 

    GLFWwindow* window = glfwCreateWindow(640, 480, "Title", NULL, NULL); 

    if(!window){ 
     //error 
    } 


    glfwMakeContextCurrent(window); 


    glClearColor(0.2f, 0.3f, 0.3f, 1.0f); 


    float vertices[] = { 
     -0.5f, -0.5f, 0.0f, 
     0.5f, -0.5f, 0.0f, 
     0.0f, 0.5f, 0.0f 
    }; 

    unsigned int VBO; 

    glGenBuffers(1, &VBO); 

    while(!glfwWindowShouldClose(window)){ 


     glfwPollEvents(); 

     glClear(GL_COLOR_BUFFER_BIT); 

     glfwSwapBuffers(window); 




    } 

    glfwDestroyWindow(window); 

    glfwTerminate(); 

    return 0; 
} 

編輯: 問題已解決。 對於任何人跟我一樣,你需要調用makeContextCurrent後glewInit()()

+1

運行它後看哪條線路導致問題。 – Basya

+0

只是一個簡單的問題 - 你是在嵌入式還是其他異常的環境下(比如無符號整數的大小可能小於32位)。 (現在不太可能,但你永遠不知道....) – Basya

+0

我正在運行64位Ubuntu。問題行是glGenBuffers(1,&VBO) – 64humans

回答

0

這是很簡單的,我只是需要把

glewExperimental = GL-TRUE; 
glewInit(); 

在調試器中glfwMakeContextCurrent()