ошибка сегментации opengl при инициализации

Это довольно неприятный вопрос, но я получаю ошибку сегментации каждый раз, когда программа пытается запустить «init()», и я понятия не имею, почему. Я использую следующие библиотеки: glew, glu, glfw3 и загрузчик шейдеров отсюда http://www.opengl-redbook.com/.

#include <GL/glew.h>
#include <GL/glu.h>
#include <GLFW/glfw3.h>
#include <GL/gl.h>
#include "LoadShaders.h"
#include <iostream>
//g++ -c main.cpp -l glfw -l GLEW -l GL -l GLU -c LoadShaders.cpp 
//g++ -o run main.o LoadShaders.o -l GLEW -l glfw -l GL -l GLU

GLuint VAOs[1];
GLuint Buffers[1];
enum Attrib_IDs {vPosition = 0};
void init (void){

    glGenVertexArrays(1, VAOs);
    glBindVertexArray(VAOs[0]);

    GLfloat vertices[6][2] ={
        {-0.90, -0.90},
        {0.85, -0.90},
        {-0.90, 0.85},
        {0.90, -0.85},
        {0.90, 0.90},
        {-0.85, 0.90}
    };

    glGenBuffers(1, Buffers);
    glBindBuffer(GL_ARRAY_BUFFER, Buffers[0]);
    glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);

    ShaderInfo shaders[] = {
        {GL_VERTEX_SHADER, "game.vert"},
        {GL_FRAGMENT_SHADER, "game.frag"},
        {GL_NONE, NULL}
    };

    GLuint program = LoadShaders(shaders);
    glUseProgram(program);

    glVertexAttribPointer(vPosition, 2, GL_FLOAT, GL_FALSE, 0, 0);
    glEnableVertexAttribArray(vPosition);
}

int main(){
    GLFWwindow* window;

    /*initialize the glfw library*/
    if (!glfwInit())
    {
        return -1;
    }

    window = glfwCreateWindow(640, 480, "Hello world!", NULL, NULL);
    if (!window)
    {
        glfwTerminate();
        return -1;
    }

    /* Make the window's context current */
    glfwMakeContextCurrent(window);
    init();
    /* Loop until the user closes the window */
    while (!glfwWindowShouldClose(window))
    {

        glClear(GL_COLOR_BUFFER_BIT);

        glBindVertexArray(VAOs[0]);
        glDrawArrays(GL_TRIANGLES, 0, 6);

        glFlush();
        /* Swap front and back buffers */
        glfwSwapBuffers(window);
        /* Poll for and process events */
        glfwPollEvents();
    }

    glfwTerminate();
    return 0;

}

person Adam Van Oijen    schedule 16.07.2015    source источник
comment
Какую отладку вы сделали? Где в init() ошибка? Пожалуйста, прочтите справочный центр для получения подробной информации о том, что вам нужно включить в свой вопрос.   -  person Jim Garrison    schedule 16.07.2015
comment
@JimGarrison Я не знаю, где в init() ошибки, вот в чем проблема. Единственная ошибка, которую я получаю, это «сбой сегментации» при запуске. Знаете ли вы какие-либо инструменты отладки, которые я бы использовал?   -  person Adam Van Oijen    schedule 16.07.2015


Ответы (1)


оказывается, я только забыл инициализировать glew, используя glewInit(). После этого все работает хорошо

person Adam Van Oijen    schedule 16.07.2015